diff --git a/src/main/java/com/direwolf20/mininggadgets/client/particles/laserparticle/LaserParticle.java b/src/main/java/com/direwolf20/mininggadgets/client/particles/laserparticle/LaserParticle.java index 0d634587..de285d0d 100644 --- a/src/main/java/com/direwolf20/mininggadgets/client/particles/laserparticle/LaserParticle.java +++ b/src/main/java/com/direwolf20/mininggadgets/client/particles/laserparticle/LaserParticle.java @@ -12,6 +12,7 @@ import net.minecraft.client.particle.ParticleProvider; import net.minecraft.core.BlockPos; import net.minecraft.util.Mth; +import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; @@ -132,6 +133,7 @@ public void tick() { Vec3 playerPos = player.position().add(0, player.getEyeHeight(), 0); Vec3 blockPos = new Vec3(sourceX, sourceY, sourceZ); Vec3 look = player.getLookAngle(); // or getLook(partialTicks) + //The next 3 variables are directions on the screen relative to the players look direction. So right = to the right of the player, regardless of facing direction. Vec3 right = new Vec3(-look.z, 0, look.x).normalize(); Vec3 forward = look; @@ -142,8 +144,13 @@ public void tick() { forward = forward.scale(0.85f); down = down.scale(-0.35); + // Check which hand the gadget is in. + boolean isRightHanded = player.getMainArm() == HumanoidArm.RIGHT; + boolean isGadgetInMainHand = player.getMainHandItem().getItem() instanceof MiningGadget; + boolean isGadgetInRightHand = (isRightHanded && isGadgetInMainHand) || (!isRightHanded && !isGadgetInMainHand); + //Take the player's eye position, and shift it to where the end of the laser is (Roughly) - Vec3 laserPos = playerPos.add(right); + Vec3 laserPos = isGadgetInRightHand ? playerPos.add(right) : playerPos.subtract(right); laserPos = laserPos.add(forward); laserPos = laserPos.add(down); diff --git a/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java b/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java index 823c4da9..9489fe1a 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java @@ -35,6 +35,7 @@ import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; @@ -319,8 +320,14 @@ private void spawnFreezeParticle(Player player, BlockPos sourcePos, Level world, down = down.scale(-0.35); backward = backward.scale(0.05); + // Check which hand the gadget is in. + boolean isRightHanded = player.getMainArm() == HumanoidArm.RIGHT; + ItemStack heldItem = player.getMainHandItem(); + boolean isGadgetInMainHand = heldItem.getItem() instanceof MiningGadget; + boolean isGadgetInRightHand = (isRightHanded && isGadgetInMainHand) || (!isRightHanded && !isGadgetInMainHand); + //Take the player's eye position, and shift it to where the end of the laser is (Roughly) - Vec3 laserPos = playerPos.add(right); + Vec3 laserPos = isGadgetInRightHand ? playerPos.add(right) : playerPos.subtract(right); laserPos = laserPos.add(forward); laserPos = laserPos.add(down); lookingAt = lookingAt.add(backward);