|
| 1 | +package com.kipti.bnb.content.girder_strut; |
| 2 | + |
| 3 | +import com.kipti.bnb.registry.BnbDataComponents; |
| 4 | +import net.minecraft.client.Minecraft; |
| 5 | +import net.minecraft.client.multiplayer.ClientLevel; |
| 6 | +import net.minecraft.client.player.LocalPlayer; |
| 7 | +import net.minecraft.core.BlockPos; |
| 8 | +import net.minecraft.core.particles.DustParticleOptions; |
| 9 | +import net.minecraft.world.item.ItemStack; |
| 10 | +import net.minecraft.world.phys.Vec3; |
| 11 | +import org.joml.Vector3f; |
| 12 | + |
| 13 | +public class GirderStrutPlacementEffects { |
| 14 | + |
| 15 | + public static void tick(LocalPlayer player) { |
| 16 | + if (Minecraft.getInstance().isPaused()) return; |
| 17 | + |
| 18 | + //Get held item |
| 19 | + ItemStack heldItem = player.getMainHandItem().getItem() instanceof GirderStrutBlockItem girderStrutMainHand ? player.getMainHandItem() : |
| 20 | + player.getOffhandItem().getItem() instanceof GirderStrutBlockItem girderStrutOffHand ? player.getOffhandItem() : null; |
| 21 | + if (heldItem != null) { |
| 22 | + display(player, heldItem); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + private static void display(LocalPlayer player, ItemStack heldItem) { |
| 27 | + ClientLevel level = Minecraft.getInstance().level; |
| 28 | + boolean valid = true; |
| 29 | + BlockPos fromPos = heldItem.get(BnbDataComponents.GIRDER_STRUT_FROM); |
| 30 | + |
| 31 | + if (fromPos == null) { |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + BlockPos targetPos = BlockPos.containing(Minecraft.getInstance().hitResult.getLocation()); |
| 36 | + |
| 37 | + Vec3 renderFrom = Vec3.atCenterOf(fromPos); |
| 38 | + Vec3 renderTo = Vec3.atCenterOf(targetPos); |
| 39 | + |
| 40 | + Vec3 dir = renderTo.subtract(renderFrom).normalize(); |
| 41 | + |
| 42 | + for (double t = 0; t <= renderFrom.length(); t += 0.1) { |
| 43 | + Vec3 lerped = renderFrom.add(dir.scale(t)); |
| 44 | + |
| 45 | + level.addParticle( |
| 46 | + new DustParticleOptions(new Vector3f(valid ? .3f : .9f, valid ? .9f : .3f, .5f), 1), true, |
| 47 | + lerped.x + .5f, lerped.y + .5f, lerped.z + .5f, 0, 0, 0); |
| 48 | + } |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments