From 77ac79aa54351c6f76244db103024f7481878bd2 Mon Sep 17 00:00:00 2001 From: Mixces Date: Wed, 17 Jul 2024 23:21:18 -0500 Subject: [PATCH] minor re-write of code! --- .../legacyanimations/LegacyAnimations.java | 16 ++- .../mixin/ArmorFeatureRendererMixin.java | 6 +- .../mixin/BuiltinModelItemRendererMixin.java | 33 +++-- .../ClientPlayerInteractionManagerMixin.java | 4 +- .../legacyanimations/mixin/EntityMixin.java | 2 +- .../FishingBobberEntityRendererMixin.java | 2 +- .../mixin/GameRendererMixin.java | 15 ++- .../mixin/HeldItemRendererMixin.java | 1 + .../mixin/InGameHudMixin.java | 36 +++--- .../mixin/ItemEntityRendererMixin.java | 48 +++++-- .../mixin/ItemRendererMixin.java | 49 ++++--- .../mixin/LivingEntityMixin.java | 30 +++-- .../mixin/LivingEntityRendererMixin.java | 39 ++++-- .../mixin/MinecraftClientMixin.java | 88 ++++++++++--- .../mixin/PlayerEntityMixin.java | 122 +++++++++--------- .../mixin/PlayerEntityRendererMixin.java | 1 + .../CameraInterface.java} | 4 +- .../EntityInterface.java} | 4 +- .../LivingEntityInterface.java} | 4 +- .../legacyanimations/util/HandUtils.java | 1 + .../legacyanimations/util/ItemUtils.java | 7 + .../util/TransformationModeUtils.java | 2 +- src/main/resources/fabric.mod.json | 2 + .../resources/legacyanimations.mixins.json | 12 +- 24 files changed, 321 insertions(+), 207 deletions(-) rename src/main/java/com/mixces/legacyanimations/mixin/{AccessorCamera.java => interfaces/CameraInterface.java} (73%) rename src/main/java/com/mixces/legacyanimations/mixin/{InvokerEntity.java => interfaces/EntityInterface.java} (75%) rename src/main/java/com/mixces/legacyanimations/mixin/{LivingEntityInvoker.java => interfaces/LivingEntityInterface.java} (73%) diff --git a/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java b/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java index 7df23d0..b884196 100644 --- a/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java +++ b/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java @@ -12,13 +12,15 @@ public class LegacyAnimations implements ModInitializer public void onInitialize() { LegacyAnimationsSettings.CONFIG.load(); - ClientTickEvents.END_WORLD_TICK.register(world -> - { - if (MinecraftClient.getInstance().player != null) - { - MinecraftClient.getInstance().player.calculateDimensions(); - } - }); +// ClientTickEvents.END_WORLD_TICK.register(world -> +// { +// if (MinecraftClient.getInstance().player == null) +// { +// return; +// } +// +// MinecraftClient.getInstance().player.calculateDimensions(); +// }); } } \ No newline at end of file diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ArmorFeatureRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ArmorFeatureRendererMixin.java index 5875119..eadb901 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/ArmorFeatureRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/ArmorFeatureRendererMixin.java @@ -34,7 +34,7 @@ public abstract class ArmorFeatureRendererMixin original, @Local(ordinal = 0, argsOnly = true) VertexConsumerProvider vertexConsumers) + private VertexConsumer legacyAnimations$useEntityLayerRendererTrim(Sprite instance, VertexConsumer consumer, Operation original, @Local(ordinal = 0, argsOnly = true) VertexConsumerProvider vertexConsumers) { if (!LegacyAnimationsSettings.CONFIG.instance().armorTint) { diff --git a/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java index d72ddab..ae42631 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java @@ -17,22 +17,21 @@ public abstract class BuiltinModelItemRendererMixin { //todo: re-write shields - - @ModifyExpressionValue( - method = "render", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z", - ordinal = 0 - ) - ) - private boolean legacyAnimations$disableShieldRendering(boolean original, ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) - { - if (LegacyAnimationsSettings.CONFIG.instance().hideShields && TransformationModeUtils.isValidPerspective(mode)) - { - return original; - } - return !ItemUtils.INSTANCE.isValidItem(stack, stack.getUseAction()); - } +// @ModifyExpressionValue( +// method = "render", +// at = @At( +// value = "INVOKE", +// target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z", +// ordinal = 0 +// ) +// ) +// private boolean legacyAnimations$disableShieldRendering(boolean original, ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) +// { +// if (LegacyAnimationsSettings.CONFIG.instance().hideShields && TransformationModeUtils.isValidPerspective(mode)) +// { +// return original; +// } +// return !ItemUtils.INSTANCE.isValidItem(stack, stack.getUseAction()); +// } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ClientPlayerInteractionManagerMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ClientPlayerInteractionManagerMixin.java index ba25a0f..5552295 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/ClientPlayerInteractionManagerMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/ClientPlayerInteractionManagerMixin.java @@ -18,10 +18,10 @@ public abstract class ClientPlayerInteractionManagerMixin { - @Shadow @Final private MinecraftClient client; @Shadow public abstract boolean isBreakingBlock(); @Shadow public abstract void cancelBlockBreaking(); @Shadow private float currentBreakingProgress; + @Shadow @Final private MinecraftClient client; @ModifyExpressionValue( method = "updateBlockBreakingProgress", @@ -54,7 +54,7 @@ public abstract class ClientPlayerInteractionManagerMixin return; } - final ClientPlayerEntity player = MinecraftClient.getInstance().player; + final ClientPlayerEntity player = client.player; if (player == null) { diff --git a/src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java index 8dcb132..c261a00 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java @@ -11,7 +11,7 @@ public abstract class EntityMixin { - //todo: revert swimming mechanic + //todo: revert swimming mechanic (double jump to leave) @ModifyReturnValue( method = "getPose", diff --git a/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java index d0681a2..3d2da56 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java @@ -63,7 +63,7 @@ protected FishingBobberEntityRendererMixin(EntityRendererFactory.Context ctx) // ) // ) // public float useInterpolatedEyeHeight(PlayerEntity instance) { -// return MathHelper.lerp(dispatcher.camera.getLastTickDelta(), ((AccessorCamera) dispatcher.camera).getLastCameraY(), ((AccessorCamera) dispatcher.camera).getCameraY()); +// return MathHelper.lerp(dispatcher.camera.getLastTickDelta(), ((CameraInterface) dispatcher.camera).getLastCameraY(), ((CameraInterface) dispatcher.camera).getCameraY()); // } @ModifyExpressionValue( diff --git a/src/main/java/com/mixces/legacyanimations/mixin/GameRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/GameRendererMixin.java index 2b9a3bd..d971756 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/GameRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/GameRendererMixin.java @@ -28,15 +28,16 @@ public class GameRendererMixin ) private void legacyAnimations$addOldPitchRotation(MatrixStack matrices, float tickDelta, CallbackInfo ci, @Local(ordinal = 0) PlayerEntity playerEntity) { - if (LegacyAnimationsSettings.CONFIG.instance().oldViewBob) + if (!LegacyAnimationsSettings.CONFIG.instance().oldViewBob) { - float h = MathHelper.lerp( - tickDelta, - ((PlayerPitchInterface) playerEntity).legacyAnimations$getPrevPlayerPitch(), - ((PlayerPitchInterface) playerEntity).legacyAnimations$getPlayerPitch() - ); - matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(h)); + return; } + + final float prevPlayerPitch = ((PlayerPitchInterface) playerEntity).legacyAnimations$getPrevPlayerPitch(); + final float playerPitch = ((PlayerPitchInterface) playerEntity).legacyAnimations$getPlayerPitch(); + final float h = MathHelper.lerp(tickDelta, prevPlayerPitch, playerPitch); + + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(h)); } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java index e892e71..7fc5a67 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java @@ -29,6 +29,7 @@ public abstract class HeldItemRendererMixin { + //todo: re-write the whole thing :) @Shadow protected abstract void applySwingOffset(MatrixStack matrices, Arm arm, float swingProgress); @Shadow private float equipProgressOffHand; @Shadow private ItemStack mainHand; diff --git a/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java index f06420f..ba3fdd2 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java @@ -15,25 +15,27 @@ import net.minecraft.util.UseAction; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; @Mixin(InGameHud.class) public abstract class InGameHudMixin { - @WrapOperation(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z")) - private boolean cancelOffhandHotbar(ItemStack itemStack, Operation original) - { - ClientPlayerEntity player = MinecraftClient.getInstance().player; - if (player != null) { - ItemStack mainStack = player.getMainHandStack(); - UseAction action = mainStack.getUseAction(); - if (LegacyAnimationsSettings.CONFIG.instance().hideShieldHotbar && ItemUtils.INSTANCE.isValidItem(mainStack, action)) - { - return original.call(itemStack) || itemStack.isOf(Items.SHIELD); - } - } - return original.call(itemStack); - } + //todo: shield shit +// @WrapOperation(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z")) +// private boolean cancelOffhandHotbar(ItemStack itemStack, Operation original) +// { +// ClientPlayerEntity player = MinecraftClient.getInstance().player; +// if (player != null) { +// ItemStack mainStack = player.getMainHandStack(); +// UseAction action = mainStack.getUseAction(); +// if (LegacyAnimationsSettings.CONFIG.instance().hideShieldHotbar && ItemUtils.INSTANCE.isValidItem(mainStack, action)) +// { +// return original.call(itemStack) || itemStack.isOf(Items.SHIELD); +// } +// } +// return original.call(itemStack); +// } @WrapWithCondition( method = "renderHealthBar", @@ -57,7 +59,11 @@ private boolean cancelOffhandHotbar(ItemStack itemStack, Operation orig ) private boolean legacyAnimations$removePerspectiveCheck(boolean original) { - return LegacyAnimationsSettings.CONFIG.instance().perspectiveCrosshair || original; + if (!LegacyAnimationsSettings.CONFIG.instance().perspectiveCrosshair) + { + return original; + } + return true; } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java index db23e86..d5d4d9f 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java @@ -34,9 +34,17 @@ protected ItemEntityRendererMixin(EntityRendererFactory.Context ctx) target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V" ) ) - private Quaternionf facePlayer(Quaternionf quaternion, @Local(ordinal = 0) boolean bl) + private Quaternionf legacyAnimations$facePlayer(Quaternionf quaternion, @Local(ordinal = 0) boolean bl) { - return LegacyAnimationsSettings.CONFIG.instance().fastItems && !bl ? dispatcher.getRotation() : quaternion; + if (!LegacyAnimationsSettings.CONFIG.instance().fastItems) { + return quaternion; + } + + if (bl) + { + return quaternion; + } + return dispatcher.getRotation(); } @Inject( @@ -47,23 +55,35 @@ private Quaternionf facePlayer(Quaternionf quaternion, @Local(ordinal = 0) boole shift = At.Shift.AFTER ) ) - private void rotateItemAccordingly(ItemEntity itemEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci, @Local(ordinal = 0) boolean bl) + private void legacyAnimations$rotateItemAccordingly(ItemEntity itemEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci, @Local(ordinal = 0) boolean bl) { - if (LegacyAnimationsSettings.CONFIG.instance().fastItems && MinecraftClient.getInstance().player != null && !bl) + if (!LegacyAnimationsSettings.CONFIG.instance().fastItems) { - if (dispatcher.gameOptions.getPerspective().isFrontView()) + return; + } + + if (MinecraftClient.getInstance().player == null) + { + return; + } + + if (bl) + { + return; + } + + if (dispatcher.gameOptions.getPerspective().isFrontView()) + { + if (HandUtils.INSTANCE.isLeftHand(MinecraftClient.getInstance().player, dispatcher)) { - if (HandUtils.INSTANCE.isLeftHand(MinecraftClient.getInstance().player, dispatcher)) - { - matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); - } + matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); } - else + } + else + { + if (HandUtils.INSTANCE.isRightHand(MinecraftClient.getInstance().player, dispatcher)) { - if (HandUtils.INSTANCE.isRightHand(MinecraftClient.getInstance().player, dispatcher)) - { - matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); - } + matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); } } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java index e41ab18..201c210 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java @@ -3,6 +3,7 @@ import com.llamalad7.mixinextras.sugar.Local; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; import com.mixces.legacyanimations.util.HandUtils; +import com.mixces.legacyanimations.util.ItemUtils; import com.mixces.legacyanimations.util.TransformationModeUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; @@ -31,23 +32,6 @@ public class ItemRendererMixin @Shadow @Final private MinecraftClient client; - @ModifyArg(method = "renderBakedItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;renderBakedItemQuads(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Ljava/util/List;Lnet/minecraft/item/ItemStack;II)V", ordinal = 1), index = 2) - private List legacyAnimations$changeToSprite(List quads, @Local(ordinal = 0, argsOnly = true) BakedModel model) - { - if (LegacyAnimationsSettings.CONFIG.instance().fastItems && client.player != null && TransformationModeUtils.shouldBeSprite() && !model.hasDepth()) - { - boolean isLeftHand = HandUtils.INSTANCE.isLeftHand(client.player, client.getEntityRenderDispatcher()); - boolean isFrontView = client.getEntityRenderDispatcher().gameOptions.getPerspective().isFrontView(); - Direction perspectiveFace = legacyAnimations$determineDirection(isFrontView, isLeftHand); - if (TransformationModeUtils.getTransformationMode() == ModelTransformationMode.GROUND) - { - return legacyAnimations$filterQuadsByDirection(quads, perspectiveFace); - } - return legacyAnimations$filterQuadsByDirection(quads, Direction.SOUTH); - } - return quads; - } - @Inject( method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At( @@ -56,10 +40,37 @@ public class ItemRendererMixin ) private void legacyAnimations$getTransformationMode(ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { - if (LegacyAnimationsSettings.CONFIG.instance().fastItems) + TransformationModeUtils.setTransformationMode(renderMode); + ItemUtils.setModel(model); + } + + //todo: unfuck left handed sprites and re-write code + @ModifyArg(method = "renderBakedItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;renderBakedItemQuads(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Ljava/util/List;Lnet/minecraft/item/ItemStack;II)V", ordinal = 1), index = 2) + private List legacyAnimations$changeToSprite(List quads, @Local(ordinal = 0, argsOnly = true) BakedModel model) + { + if (!LegacyAnimationsSettings.CONFIG.instance().fastItems) { + return quads; + } + + if (client.player == null) + { + return quads; + } + + if (!TransformationModeUtils.shouldBeSprite() || model.hasDepth()) + { + return quads; + } + + final boolean isLeftHand = HandUtils.INSTANCE.isLeftHand(client.player, client.getEntityRenderDispatcher()); + final boolean isFrontView = client.getEntityRenderDispatcher().gameOptions.getPerspective().isFrontView(); + final Direction perspectiveFace = legacyAnimations$determineDirection(isFrontView, isLeftHand); + + if (TransformationModeUtils.getTransformationMode() == ModelTransformationMode.GROUND) { - TransformationModeUtils.setTransformationMode(renderMode); + return legacyAnimations$filterQuadsByDirection(quads, perspectiveFace); } + return legacyAnimations$filterQuadsByDirection(quads, Direction.SOUTH); } @Unique diff --git a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java index 2e9e554..3a9d2c9 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java @@ -21,15 +21,16 @@ public abstract class LivingEntityMixin implements PlayerPitchInterface @Unique public float legacyAnimations$prevCameraPitch; @Unique public float legacyAnimations$cameraPitch; - @ModifyConstant(method = "isBlocking", constant = @Constant(intValue = 5)) - private int legacyAnimations$fixSync(int constant) - { - if (ServerUtils.INSTANCE.isOnHypixel()) - { - return 0; - } - return constant; - } + //todo: hypixel rahh +// @ModifyConstant(method = "isBlocking", constant = @Constant(intValue = 5)) +// private int legacyAnimations$fixSync(int constant) +// { +// if (ServerUtils.INSTANCE.isOnHypixel()) +// { +// return 0; +// } +// return constant; +// } @ModifyConstant( method = "tick", @@ -51,8 +52,10 @@ public abstract class LivingEntityMixin implements PlayerPitchInterface private float legacyAnimations$revertBackwardsWalk(float constant) { if (LegacyAnimationsSettings.CONFIG.instance().oldWalking) - return 0.0F; - return constant; + { + return constant; + } + return 0.0F; } @Inject( @@ -66,10 +69,11 @@ public abstract class LivingEntityMixin implements PlayerPitchInterface ) private void legacyAnimations$setPrevCameraPitch(CallbackInfo ci) { - if (LegacyAnimationsSettings.CONFIG.instance().oldViewBob) + if (!LegacyAnimationsSettings.CONFIG.instance().oldViewBob) { - legacyAnimations$prevCameraPitch = legacyAnimations$cameraPitch; + return; } + legacyAnimations$prevCameraPitch = legacyAnimations$cameraPitch; } @Override diff --git a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityRendererMixin.java index 8cf96c8..675f6a8 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityRendererMixin.java @@ -2,10 +2,10 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.mixin.interfaces.CameraInterface; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.*; import net.minecraft.client.render.entity.LivingEntityRenderer; -import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(LivingEntityRenderer.class) -public abstract class LivingEntityRendererMixin> +public abstract class LivingEntityRendererMixin { @ModifyExpressionValue( @@ -28,9 +28,14 @@ public abstract class LivingEntityRendererMixin original) { - if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && instance.isUsingItem()) + if (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage) + { + original.call(instance, hand); + + } + + if (instance.isUsingItem()) { legacyAnimations$fakeSwingHand(instance, hand); } else { - instance.swingHand(hand); + original.call(instance, hand); } } @Inject( - method = "doAttack", + method = "handleInputEvents", at = @At( - value = "HEAD" + value = "INVOKE", + target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z", + ordinal = 0 ) ) - private void legacyAnimations$removeMissPenalty(CallbackInfoReturnable cir) + private void mixcesAnimations$addLeftClickCheck(CallbackInfo ci) { - if (ServerUtils.INSTANCE.isOnHypixel()) +// if (!ServerUtils.INSTANCE.isOnHypixel()) +// { +// return; +// } + + if (currentScreen != null || !options.attackKey.isPressed() || !mouse.isCursorLocked()) { attackCooldown = 0; } } + //todo: find better way to do this? + @ModifyArg( + method = "handleInputEvents", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/MinecraftClient;handleBlockBreaking(Z)V" + ) + ) + private boolean legacyAnimations$removeCondition(boolean original) + { + if (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage) + { + return original; + } + return currentScreen == null && options.attackKey.isPressed() && mouse.isCursorLocked(); + } + @Unique private static void legacyAnimations$fakeSwingHand(ClientPlayerEntity player, Hand hand) { - if (!player.handSwinging || player.handSwingTicks >= ((LivingEntityInvoker) player).invokeGetHandSwingDuration() / 2 || player.handSwingTicks < 0) + final int handSwingDuration = ((LivingEntityInterface) player).invokeGetHandSwingDuration(); + + if (player.handSwinging && player.handSwingTicks < handSwingDuration / 2 && player.handSwingTicks >= 0) { - player.handSwingTicks = -1; - player.handSwinging = true; - player.preferredHand = hand; + return; } + + player.handSwingTicks = -1; + player.handSwinging = true; + player.preferredHand = hand; } } \ No newline at end of file diff --git a/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityMixin.java index b6ea976..d0e2133 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityMixin.java @@ -2,9 +2,9 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.mixin.interfaces.EntityInterface; +import com.mixces.legacyanimations.mixin.interfaces.LivingEntityInterface; import com.mixces.legacyanimations.util.ServerUtils; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityPose; import net.minecraft.entity.EquipmentSlot; @@ -12,10 +12,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.SwordItem; -import net.minecraft.util.Arm; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -25,52 +23,28 @@ public abstract class PlayerEntityMixin extends LivingEntityMixin { - @Shadow protected abstract boolean canChangeIntoPose(EntityPose pose); - - @Inject(method = "resetLastAttackedTicks", at = @At("HEAD"), cancellable = true) - private void legacyAnimations$removeAttackDelay(CallbackInfo ci) - { - if (ServerUtils.INSTANCE.isOnHypixel()) - { - ci.cancel(); - } - } - -// @ModifyReturnValue( -// method = "getActiveEyeHeight", -// at = @At( -// value = "RETURN", -// ordinal = 1 -// ) -// ) -// private float modifyEyeHeight(float constant) { -// if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) { -// if (!canChangeIntoPose(EntityPose.STANDING)) { -// return constant; -// } else { -// return constant + 0.27F; -// } + //todo: hypixel +// @Inject(method = "resetLastAttackedTicks", at = @At("HEAD"), cancellable = true) +// private void legacyAnimations$removeAttackDelay(CallbackInfo ci) +// { +// if (ServerUtils.INSTANCE.isOnHypixel()) +// { +// ci.cancel(); // } -// return constant; // } -// @Inject(method = "getBaseDimensions", at = @At("HEAD"), cancellable = true) -// private void modifyDimensions(EntityPose pose, CallbackInfoReturnable cir) { -// if (pose == EntityPose.CROUCHING) { -// cir.setReturnValue(EntityDimensions.changing(0.6F, 1.62F).withEyeHeight(1.54F)); + //todo: hypixel +// @Inject(method = "getMainArm", at = @At("HEAD"), cancellable = true) +// public void legacyAnimations$correctHandSide(CallbackInfoReturnable cir) +// { +// final PlayerEntity entity = (PlayerEntity) (Object) this; +// +// if (entity instanceof ClientPlayerEntity && ServerUtils.INSTANCE.isOnHypixel()) +// { +// cir.setReturnValue(MinecraftClient.getInstance().options.getMainArm().getValue()); // } // } - @Inject(method = "getMainArm", at = @At("HEAD"), cancellable = true) - public void legacyAnimations$correctHandSide(CallbackInfoReturnable cir) - { - PlayerEntity entity = (PlayerEntity) (Object) this; - if (entity instanceof ClientPlayerEntity && ServerUtils.INSTANCE.isOnHypixel()) - { - cir.setReturnValue(MinecraftClient.getInstance().options.getMainArm().getValue()); - } - } - @Inject( method = "tickMovement", at = @At( @@ -82,32 +56,56 @@ public abstract class PlayerEntityMixin extends LivingEntityMixin ) private void legacyAnimations$getPitchFromVelocity(CallbackInfo ci) { - if (LegacyAnimationsSettings.CONFIG.instance().oldViewBob) + if (!LegacyAnimationsSettings.CONFIG.instance().oldViewBob) + { + return; + } + + final PlayerEntity entity = (PlayerEntity) (Object) this; + final double velocityY = ((EntityInterface) entity).invokeGetVelocity().y; + float f1 = (float) (Math.atan(-velocityY * 0.2F) * 15.0F); + + if (((EntityInterface) entity).invokeIsOnGround() || ((LivingEntityInterface) entity).invokeGetHealth() <= 0.0F) { - PlayerEntity entity = (PlayerEntity) (Object) this; - double velocityY = ((InvokerEntity) entity).invokeGetVelocity().y; - float f1 = (float) (Math.atan(-velocityY * 0.2F) * 15.0F); - if (((InvokerEntity) entity).invokeIsOnGround() || ((LivingEntityInvoker) entity).invokeGetHealth() <= 0.0F) - { - f1 = 0.0F; - } - legacyAnimations$cameraPitch += (f1 - legacyAnimations$cameraPitch) * 0.8F; + f1 = 0.0F; } + legacyAnimations$cameraPitch += (f1 - legacyAnimations$cameraPitch) * 0.8F; } - @Inject( - method = "getEquippedStack", +// @Inject( +// method = "getEquippedStack", +// at = @At( +// value = "RETURN", +// ordinal = 1 +// ), +// cancellable = true) +// private void legacyAnimations$hypixelShieldBug(EquipmentSlot slot, CallbackInfoReturnable cir) +// { +// if (ServerUtils.INSTANCE.isOnHypixel() && getMainHandStack().getItem() instanceof SwordItem && !isUsingItem()) +// { +// cir.setReturnValue(new ItemStack(Items.SHIELD)); +// } +// } + + @ModifyReturnValue( + method = "getBaseDimensions", at = @At( - value = "RETURN", - ordinal = 1 - ), - cancellable = true) - private void legacyAnimations$hypixelShieldBug(EquipmentSlot slot, CallbackInfoReturnable cir) + value = "RETURN" + ) + ) + private EntityDimensions legacyAnimations$modifyStandingEyeHeight(EntityDimensions original, EntityPose pose) { - if (ServerUtils.INSTANCE.isOnHypixel() && getMainHandStack().getItem() instanceof SwordItem && !isUsingItem()) + if (!LegacyAnimationsSettings.CONFIG.instance().oldSneaking) { - cir.setReturnValue(new ItemStack(Items.SHIELD)); + return original; + } + + //todo: eyeheight under slabs + + if (pose != EntityPose.CROUCHING) { + return original; } + return original.withEyeHeight(original.eyeHeight() + 0.27F); } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityRendererMixin.java index 04fd671..bb53c16 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityRendererMixin.java @@ -15,6 +15,7 @@ public class PlayerEntityRendererMixin { + //todo: shield shit // @Inject(method = "getArmPose", at = @At(value = "HEAD"), cancellable = true) // private static void getArmPose_blockArm(AbstractClientPlayerEntity player, Hand hand, CallbackInfoReturnable cir) { // if (LegacyAnimationsSettings.CONFIG.instance().hideShields && player.getStackInHand(hand).getItem() instanceof ShieldItem) { diff --git a/src/main/java/com/mixces/legacyanimations/mixin/AccessorCamera.java b/src/main/java/com/mixces/legacyanimations/mixin/interfaces/CameraInterface.java similarity index 73% rename from src/main/java/com/mixces/legacyanimations/mixin/AccessorCamera.java rename to src/main/java/com/mixces/legacyanimations/mixin/interfaces/CameraInterface.java index 53eb581..6289ad8 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/AccessorCamera.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/interfaces/CameraInterface.java @@ -1,11 +1,11 @@ -package com.mixces.legacyanimations.mixin; +package com.mixces.legacyanimations.mixin.interfaces; import net.minecraft.client.render.Camera; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(Camera.class) -public interface AccessorCamera +public interface CameraInterface { @Accessor float getCameraY(); diff --git a/src/main/java/com/mixces/legacyanimations/mixin/InvokerEntity.java b/src/main/java/com/mixces/legacyanimations/mixin/interfaces/EntityInterface.java similarity index 75% rename from src/main/java/com/mixces/legacyanimations/mixin/InvokerEntity.java rename to src/main/java/com/mixces/legacyanimations/mixin/interfaces/EntityInterface.java index dd9b275..3ad2c4b 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/InvokerEntity.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/interfaces/EntityInterface.java @@ -1,4 +1,4 @@ -package com.mixces.legacyanimations.mixin; +package com.mixces.legacyanimations.mixin.interfaces; import net.minecraft.entity.Entity; import net.minecraft.util.math.Vec3d; @@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(Entity.class) -public interface InvokerEntity +public interface EntityInterface { @Invoker Vec3d invokeGetVelocity(); diff --git a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityInvoker.java b/src/main/java/com/mixces/legacyanimations/mixin/interfaces/LivingEntityInterface.java similarity index 73% rename from src/main/java/com/mixces/legacyanimations/mixin/LivingEntityInvoker.java rename to src/main/java/com/mixces/legacyanimations/mixin/interfaces/LivingEntityInterface.java index 848cd8e..8e04eb8 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityInvoker.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/interfaces/LivingEntityInterface.java @@ -1,11 +1,11 @@ -package com.mixces.legacyanimations.mixin; +package com.mixces.legacyanimations.mixin.interfaces; import net.minecraft.entity.LivingEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(LivingEntity.class) -public interface LivingEntityInvoker +public interface LivingEntityInterface { @Invoker int invokeGetHandSwingDuration(); diff --git a/src/main/java/com/mixces/legacyanimations/util/HandUtils.java b/src/main/java/com/mixces/legacyanimations/util/HandUtils.java index a4e9700..72bd027 100644 --- a/src/main/java/com/mixces/legacyanimations/util/HandUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/HandUtils.java @@ -9,6 +9,7 @@ public class HandUtils { + //todo: simplify public static HandUtils INSTANCE = new HandUtils(); public int handMultiplier(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) diff --git a/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java b/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java index cbd79f8..93b4313 100644 --- a/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java @@ -1,7 +1,10 @@ package com.mixces.legacyanimations.util; +import lombok.Getter; +import lombok.Setter; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.render.model.BakedModel; import net.minecraft.component.DataComponentTypes; import net.minecraft.item.FishingRodItem; import net.minecraft.item.ItemStack; @@ -13,6 +16,10 @@ public class ItemUtils public static ItemUtils INSTANCE = new ItemUtils(); + @Getter + @Setter + private static BakedModel model; + public boolean isValidItem(ItemStack heldStack, UseAction action) { if (ItemUtils.INSTANCE.isValidHeldItem(heldStack) || diff --git a/src/main/java/com/mixces/legacyanimations/util/TransformationModeUtils.java b/src/main/java/com/mixces/legacyanimations/util/TransformationModeUtils.java index 3fe3f9e..960298d 100644 --- a/src/main/java/com/mixces/legacyanimations/util/TransformationModeUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/TransformationModeUtils.java @@ -12,7 +12,7 @@ public class TransformationModeUtils @Setter @Getter - public static ModelTransformationMode transformationMode; + private static ModelTransformationMode transformationMode; private static final EnumSet cameraTypes = EnumSet.of( diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d856062..94175d6 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -9,7 +9,9 @@ "Mixces", "Wyvest", "Microcontrollers", + "Adrenix (NostalgicTweaks)", "ImToggle", + "redth", "Cecer (CecerMCProjects)" ], "contact": diff --git a/src/main/resources/legacyanimations.mixins.json b/src/main/resources/legacyanimations.mixins.json index 3cc0e51..a5f3151 100644 --- a/src/main/resources/legacyanimations.mixins.json +++ b/src/main/resources/legacyanimations.mixins.json @@ -2,9 +2,7 @@ "required": true, "package": "com.mixces.legacyanimations.mixin", "compatibilityLevel": "JAVA_21", - "client": - [ - "AccessorCamera", + "client": [ "ArmorFeatureRendererMixin", "BipedEntityModelMixin", "BuiltinModelItemRendererMixin", @@ -17,15 +15,17 @@ "GameRendererMixin", "HeldItemRendererMixin", "InGameHudMixin", - "InvokerEntity", "ItemEntityRendererMixin", "ItemRendererMixin", - "LivingEntityInvoker", "LivingEntityMixin", "LivingEntityRendererMixin", "MinecraftClientMixin", "PlayerEntityMixin", - "PlayerEntityRendererMixin" + "PlayerEntityRendererMixin", + "VertexConsumerMixin", + "interfaces.CameraInterface", + "interfaces.EntityInterface", + "interfaces.LivingEntityInterface" ], "injectors": { "defaultRequire": 1