From 57c251ea8bf253e93541b310351ada7e2cf18206 Mon Sep 17 00:00:00 2001 From: Natasha Draper Date: Mon, 20 Nov 2023 15:42:02 +0200 Subject: [PATCH 1/3] fix: magnet & freezing upgrade particles now respect player handedness --- .../client/particles/laserparticle/LaserParticle.java | 8 +++++++- .../mininggadgets/common/items/MiningGadget.java | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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..dded1a42 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,8 @@ 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 +145,11 @@ public void tick() { forward = forward.scale(0.85f); down = down.scale(-0.35); + // Check which hand is player's main hand. + boolean isRightHanded = Minecraft.getInstance().options.mainHand().get() == HumanoidArm.RIGHT; + //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 = isRightHanded ? 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..407dd4ca 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,11 @@ private void spawnFreezeParticle(Player player, BlockPos sourcePos, Level world, down = down.scale(-0.35); backward = backward.scale(0.05); + // Check which hand is player's main hand. + boolean isRightHanded = Minecraft.getInstance().options.mainHand().get() == HumanoidArm.RIGHT; + //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 = isRightHanded ? playerPos.add(right) : playerPos.subtract(right); laserPos = laserPos.add(forward); laserPos = laserPos.add(down); lookingAt = lookingAt.add(backward); From 5c20ea57e100e030246b05606329b2e058a07b45 Mon Sep 17 00:00:00 2001 From: Natasha Draper Date: Mon, 20 Nov 2023 16:44:23 +0200 Subject: [PATCH 2/3] fix: apply correct settings for servers & also consider main vs off hand --- .../client/particles/laserparticle/LaserParticle.java | 8 +++++--- .../mininggadgets/common/items/MiningGadget.java | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) 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 dded1a42..feae77ef 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 @@ -145,11 +145,13 @@ public void tick() { forward = forward.scale(0.85f); down = down.scale(-0.35); - // Check which hand is player's main hand. - boolean isRightHanded = Minecraft.getInstance().options.mainHand().get() == HumanoidArm.RIGHT; + // 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 = isRightHanded ? playerPos.add(right) : playerPos.subtract(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 407dd4ca..9489fe1a 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java @@ -320,11 +320,14 @@ private void spawnFreezeParticle(Player player, BlockPos sourcePos, Level world, down = down.scale(-0.35); backward = backward.scale(0.05); - // Check which hand is player's main hand. - boolean isRightHanded = Minecraft.getInstance().options.mainHand().get() == HumanoidArm.RIGHT; + // 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 = isRightHanded ? playerPos.add(right) : playerPos.subtract(right); + Vec3 laserPos = isGadgetInRightHand ? playerPos.add(right) : playerPos.subtract(right); laserPos = laserPos.add(forward); laserPos = laserPos.add(down); lookingAt = lookingAt.add(backward); From 5f027c8265363345ecf362e6bfcdde74790688c1 Mon Sep 17 00:00:00 2001 From: Natasha Draper Date: Thu, 23 Nov 2023 11:15:50 +0200 Subject: [PATCH 3/3] fix: unnecessary whitespace --- .../client/particles/laserparticle/LaserParticle.java | 1 - 1 file changed, 1 deletion(-) 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 feae77ef..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 @@ -134,7 +134,6 @@ public void tick() { 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;