Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: magnet & freezing upgrade particles now respect player handedness #238

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Can this only have 1 enter, not 2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, missed that from moving some lines around, thanks for the find

Vec3 right = new Vec3(-look.z, 0, look.x).normalize();
Vec3 forward = look;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down