Skip to content

Commit

Permalink
some more progress!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Jul 22, 2024
1 parent f6094e7 commit 0e5a330
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 176 deletions.
82 changes: 58 additions & 24 deletions src/main/java/com/mixces/legacyanimations/LegacyAnimations.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.mixces.legacyanimations.hook.TransformHook;
import com.mojang.brigadier.arguments.FloatArgumentType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.server.command.CommandManager;
import net.minecraft.text.Text;

Expand All @@ -15,15 +17,15 @@ public class LegacyAnimations implements ModInitializer
public void onInitialize()
{
LegacyAnimationsSettings.CONFIG.load();
// ClientTickEvents.END_WORLD_TICK.register(world ->
// {
// if (MinecraftClient.getInstance().player == null)
// {
// return;
// }
//
// MinecraftClient.getInstance().player.calculateDimensions();
// });
ClientTickEvents.END_WORLD_TICK.register(world ->
{
if (MinecraftClient.getInstance().player == null)
{
return;
}

MinecraftClient.getInstance().player.calculateDimensions();
});

CommandRegistrationCallback.EVENT.register(
(dispatcher, registryAccess, environment) ->
Expand Down Expand Up @@ -56,21 +58,53 @@ public void onInitialize()
context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2 + " z: " + value3), false);
return 1;
})
// .then(CommandManager.argument("roll", FloatArgumentType.floatArg())
// .executes(context -> {
// final float value = FloatArgumentType.getFloat(context, "x");
// final float value2 = FloatArgumentType.getFloat(context, "y");
// final float value3 = FloatArgumentType.getFloat(context, "z");
// final float value4 = FloatArgumentType.getFloat(context, "roll");
// TransformHook.translationX = value;
// TransformHook.translationY = value2;
// TransformHook.translationZ = value3;
// TransformHook.rotationY = value4;
// context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2 + " z: " + value3 + " roll: " + value4), false);
// return 1;
// })
// )
))));
.then(CommandManager.argument("yaw", FloatArgumentType.floatArg())
.executes(context -> {
final float value = FloatArgumentType.getFloat(context, "x");
final float value2 = FloatArgumentType.getFloat(context, "y");
final float value3 = FloatArgumentType.getFloat(context, "z");
final float value4 = FloatArgumentType.getFloat(context, "yaw");
TransformHook.translationX = value;
TransformHook.translationY = value2;
TransformHook.translationZ = value3;
TransformHook.rotationX = value4;
context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2 + " z: " + value3 + " yaw: " + value4), false);
return 1;
})
.then(CommandManager.argument("pitch", FloatArgumentType.floatArg())
.executes(context -> {
final float value = FloatArgumentType.getFloat(context, "x");
final float value2 = FloatArgumentType.getFloat(context, "y");
final float value3 = FloatArgumentType.getFloat(context, "z");
final float value4 = FloatArgumentType.getFloat(context, "roll");
final float value5 = FloatArgumentType.getFloat(context, "pitch");
TransformHook.translationX = value;
TransformHook.translationY = value2;
TransformHook.translationZ = value3;
TransformHook.rotationX = value4;
TransformHook.rotationY = value5;
context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2 + " z: " + value3 + " yaw: " + value4 + " pitch: " + value5), false);
return 1;
})
.then(CommandManager.argument("roll", FloatArgumentType.floatArg())
.executes(context -> {
final float value = FloatArgumentType.getFloat(context, "x");
final float value2 = FloatArgumentType.getFloat(context, "y");
final float value3 = FloatArgumentType.getFloat(context, "z");
final float value4 = FloatArgumentType.getFloat(context, "yaw");
final float value5 = FloatArgumentType.getFloat(context, "pitch");
final float value6 = FloatArgumentType.getFloat(context, "roll");
TransformHook.translationX = value;
TransformHook.translationY = value2;
TransformHook.translationZ = value3;
TransformHook.rotationX = value4;
TransformHook.rotationY = value5;
TransformHook.rotationZ = value6;
context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2 + " z: " + value3 + " yaw: " + value4 + " pitch: " + value5 + " roll: " + value6), false);
return 1;
})

)))))));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
public abstract class BipedEntityModelMixin<T extends LivingEntity>
{

//todo: thorough investigation needed

@Shadow public BipedEntityModel.ArmPose leftArmPose;
@Shadow public BipedEntityModel.ArmPose rightArmPose;
@Shadow @Final public ModelPart rightArm;
Expand All @@ -37,24 +35,26 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
)
private void legacyAnimations$fixIncorrectArmPlacement(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage)
if (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage)
{
return;
}

rightArm.roll = 0.0F;
leftArm.roll = 0.0F;
if (rightArmPose == BipedEntityModel.ArmPose.BOW_AND_ARROW)
{
rightArm.yaw = -0.1F + head.yaw;
leftArm.yaw = 0.1F + head.yaw + 0.4F;
rightArm.pitch = (float) (-Math.PI / 2) + head.pitch;
leftArm.pitch = (float) (-Math.PI / 2) + head.pitch;
}
if (leftArmPose == BipedEntityModel.ArmPose.BOW_AND_ARROW)
{
rightArm.roll = 0.0F;
leftArm.roll = 0.0F;
if (rightArmPose == BipedEntityModel.ArmPose.BOW_AND_ARROW)
{
rightArm.yaw = -0.1F + head.yaw;
leftArm.yaw = 0.1F + head.yaw + 0.4F;
rightArm.pitch = (float) (-Math.PI / 2) + head.pitch;
leftArm.pitch = (float) (-Math.PI / 2) + head.pitch;
}
if (leftArmPose == BipedEntityModel.ArmPose.BOW_AND_ARROW)
{
rightArm.yaw = -0.1F + head.yaw - 0.4F;
leftArm.yaw = 0.1F + head.yaw;
rightArm.pitch = (float) (-Math.PI / 2) + head.pitch;
leftArm.pitch = (float) (-Math.PI / 2) + head.pitch;
}
rightArm.yaw = -0.1F + head.yaw - 0.4F;
leftArm.yaw = 0.1F + head.yaw;
rightArm.pitch = (float) (-Math.PI / 2) + head.pitch;
leftArm.pitch = (float) (-Math.PI / 2) + head.pitch;
}
}

Expand Down Expand Up @@ -82,10 +82,12 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
)
private void legacyAnimations$oldSneakValue1(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
if (!LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
{
rightLeg.pivotY = 9.0f;
return;
}

rightLeg.pivotY = 9.0f;
}

@Inject(
Expand All @@ -112,10 +114,12 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
)
private void legacyAnimations$oldSneakValue2(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
if (!LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
{
leftLeg.pivotY = 9.0f;
return;
}

leftLeg.pivotY = 9.0f;
}

@Inject(
Expand All @@ -129,10 +133,12 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
)
private void legacyAnimations$oldSneakValue3(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
if (!LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
{
rightLeg.pivotZ = 0.1f;
return;
}

rightLeg.pivotZ = 0.1f;
}

@Inject(
Expand All @@ -146,10 +152,12 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
)
private void legacyAnimations$oldSneakValue4(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
if (!LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
{
leftLeg.pivotZ = 0.1f;
return;
}

leftLeg.pivotZ = 0.1f;
}

@Inject(
Expand All @@ -163,10 +171,12 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
)
private void legacyAnimations$oldSneakValue5(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
if (!LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
{
head.pivotY = 1.0f;
return;
}

head.pivotY = 1.0f;
}

@WrapWithCondition(
Expand Down Expand Up @@ -231,37 +241,13 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity>
)
public void legacyAnimations$oldBlockingArm(ModelPart arm, boolean rightArm, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock)
if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock)
{
arm.pitch = arm.pitch * 0.5F - (float) (Math.PI / 3);
arm.yaw = 0.0F;
return;
}
}

@ModifyArg(
method = "positionLeftArm",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;positionBlockingArm(Lnet/minecraft/client/model/ModelPart;Z)V"
),
index = 0
)
private ModelPart legacyAnimations$switchBlockingArm1(ModelPart arm)
{
return LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock ? rightArm : arm;
}

@ModifyArg(
method = "positionRightArm",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;positionBlockingArm(Lnet/minecraft/client/model/ModelPart;Z)V"
),
index = 0
)
private ModelPart legacyAnimations$switchBlockingArm2(ModelPart arm)
{
return LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock ? leftArm : arm;
arm.pitch = arm.pitch * 0.5F - (float) (Math.PI / 3);
arm.yaw = 0.0F;
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.mixces.legacyanimations.mixin;

import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.hook.TransformHook;
import com.mixces.legacyanimations.util.ItemUtils;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.HeldItemFeatureRenderer;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Arm;
import net.minecraft.util.math.RotationAxis;
Expand All @@ -18,29 +20,36 @@
@Mixin(HeldItemFeatureRenderer.class)
public class HeldItemFeatureRendererMixin {

// @Inject(
// method = "renderItem",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"
// )
// )
// private void legacyAnimations$swordBlockTransform(LivingEntity entity, ItemStack stack, ModelTransformationMode transformationMode, Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci)
// {
// if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock)
// {
// return;
// }
//
// if (!ItemUtils.INSTANCE.isSwordInMainHand(stack) || !ItemUtils.INSTANCE.isShieldInOffHand(stack))
// {
// return;
// }
//
// matrices.translate(0.05f, 0.0f, -0.1f);
// matrices.multiply(RotationAxis.POSITIVE_Y.rotation(-50.0F));
// matrices.multiply(RotationAxis.POSITIVE_X.rotation(-10.0F));
// matrices.multiply(RotationAxis.POSITIVE_Z.rotation(-60.0F));
// }
@Inject(
method = "renderItem",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"
)
)
private void legacyAnimations$swordBlockTransform(LivingEntity entity, ItemStack stack, ModelTransformationMode transformationMode, Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci)
{
if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock)
{
return;
}

if (!entity.isBlocking())
{
return;
}

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));

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

}
Loading

0 comments on commit 0e5a330

Please sign in to comment.