Skip to content

Commit

Permalink
left handed swing bug fix!! + third person item positions coming soon
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Jul 24, 2024
1 parent 394c5a8 commit d8e69d2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.mixces.legacyanimations.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Arm;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -23,6 +30,33 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
@Shadow @Final public ModelPart head;
@Shadow @Final public ModelPart rightLeg;
@Shadow @Final public ModelPart leftLeg;
@Shadow protected abstract ModelPart getArm(Arm arm);

@Shadow @Final public ModelPart body;

@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;animateArms(Lnet/minecraft/entity/LivingEntity;F)V"
)
)
public void legacyAnimations$adjustArmYaw(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci)
{
if (!LegacyAnimationsSettings.getInstance().oldSwordBlock)
{
return;
}

final ClientPlayerEntity player = MinecraftClient.getInstance().player;

if (player == null)
{
return;
}

getArm(player.getMainArm()).yaw = 0.0F;
}

@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
Expand Down Expand Up @@ -242,6 +276,47 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
return !LegacyAnimationsSettings.getInstance().oldSneaking;
}

@WrapOperation(
method = "animateArms",
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/model/ModelPart;yaw:F",
ordinal = 9
)
)
public float legacyAnimations$removeConflictingFields3(ModelPart instance, Operation<Float> original)
{
return 0.0F;
}

@Inject(
method = "animateArms",
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;handSwingProgress:F",
ordinal = 2
)
)
public void legacyAnimations$mirrorSwing(T entity, float animationProgress, CallbackInfo ci, @Local Arm arm, @Local ModelPart modelPart)
{
modelPart.pitch += (arm == Arm.LEFT ? -1 : 1) * body.yaw;
}

@ModifyExpressionValue(
method = "animateArms",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/util/math/MathHelper;sin(F)F",
ordinal = 5
)
)
public float legacyAnimations$mirrorSwing2(float original, @Local Arm arm)
{
return (arm == Arm.LEFT ? -1 : 1) * original;
}

@Inject(
method = "positionBlockingArm",
at = @At(
Expand All @@ -255,8 +330,8 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
return;
}

arm.pitch *= 0.5F - (float) (Math.PI / 10) * 3;
arm.yaw = 0.0F;
arm.pitch = arm.pitch * 0.5F - (float) (Math.PI / 10) * 3;
arm.yaw = (rightArm ? -1.0f : 1.0f) * (float) (-Math.PI / 6);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ public class HeldItemFeatureRendererMixin {
return;
}

if (!ItemUtils.INSTANCE.isShieldInOffHand(entity.getOffHandStack()) || !ItemUtils.INSTANCE.isSwordInMainHand(entity.getMainHandStack()))
if (ItemUtils.INSTANCE.isShieldInOffHand(entity.getOffHandStack()) && ItemUtils.INSTANCE.isSwordInMainHand(entity.getMainHandStack()))
{
return;
matrices.translate(TransformHook.translationX, TransformHook.translationY, TransformHook.translationZ);
matrices.multiply(RotationAxis.POSITIVE_X.rotation(TransformHook.rotationX));
matrices.multiply(RotationAxis.POSITIVE_Y.rotation(TransformHook.rotationY));
matrices.multiply(RotationAxis.POSITIVE_Z.rotation(TransformHook.rotationZ));
}

// matrices.translate(TransformHook.translationX, TransformHook.translationY, TransformHook.translationZ);
// matrices.multiply(RotationAxis.POSITIVE_X.rotation(TransformHook.rotationX));
// matrices.multiply(RotationAxis.POSITIVE_Y.rotation(TransformHook.rotationY));
// matrices.multiply(RotationAxis.POSITIVE_Z.rotation(TransformHook.rotationZ));

matrices.translate(-0.2F, 0.0F, 0.1F);
matrices.multiply(RotationAxis.POSITIVE_X.rotation(21.0F));
matrices.multiply(RotationAxis.POSITIVE_Y.rotation(90.0F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotation(-90.0F));


// x: -0.2 y: 0.0 z: 0.1 yaw: 21.0 pitch: 90.0 roll: -90.0
}
Expand Down

0 comments on commit d8e69d2

Please sign in to comment.