From d9111e99e842dfdee0ae55dad9c6099f823d044d Mon Sep 17 00:00:00 2001 From: ManInMyVan <113963219+ManInMyVan@users.noreply.github.com> Date: Wed, 22 Jan 2025 19:29:01 -0700 Subject: [PATCH] feat(Animations): better EquipOffset --- .../minecraft/item/MixinHeldItemRenderer.java | 34 +++++++++++++++++-- .../module/modules/render/ModuleAnimations.kt | 14 ++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/item/MixinHeldItemRenderer.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/item/MixinHeldItemRenderer.java index 955235ab17a..b0b3a950b5e 100644 --- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/item/MixinHeldItemRenderer.java +++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/item/MixinHeldItemRenderer.java @@ -44,6 +44,7 @@ import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(HeldItemRenderer.class) public abstract class MixinHeldItemRenderer { @@ -55,6 +56,10 @@ public abstract class MixinHeldItemRenderer { @Shadow private ItemStack offHand; + @Shadow + @Final + private static float EQUIP_OFFSET_TRANSLATE_Y; + @Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;push()V", shift = At.Shift.AFTER)) private void hookRenderFirstPersonItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { if (ModuleAnimations.INSTANCE.getRunning()) { @@ -162,8 +167,8 @@ private int hookItemUseItem(AbstractClientPlayerEntity instance) { target = "Lnet/minecraft/client/render/item/HeldItemRenderer;applyEquipOffset(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/Arm;F)V", ordinal = 3 ), index = 2) - private float applyEquipOffset(float equipProgress) { - if (ModuleAnimations.INSTANCE.getRunning() && !ModuleAnimations.INSTANCE.getEquipOffset()) { + private float injectIgnoreBlocking(float equipProgress) { + if (ModuleAnimations.EquipOffset.INSTANCE.getRunning() && ModuleAnimations.EquipOffset.INSTANCE.getIgnoreBlocking()) { return 0.0F; } @@ -229,4 +234,29 @@ private float injectSilentHotbarNoCooldown(float original) { return original; } + @Inject(method = "resetEquipProgress", at = @At("HEAD"), cancellable = true) + private void injectIgnorePlace(Hand hand, CallbackInfo ci) { + if (ModuleAnimations.INSTANCE.getRunning() && ModuleAnimations.EquipOffset.INSTANCE.getIgnorePlace()) { + ci.cancel(); + } + } + + @Inject(method = "shouldSkipHandAnimationOnSwap", at = @At("RETURN"), cancellable = true) + private void injectIgnoreAmount(ItemStack from, ItemStack to, CallbackInfoReturnable cir) { + if (ModuleAnimations.INSTANCE.getRunning() && !cir.getReturnValueZ()) { + cir.setReturnValue(!ModuleAnimations.EquipOffset.INSTANCE.getRunning() + || (from.getCount() == to.getCount() || ModuleAnimations.EquipOffset.INSTANCE.getIgnoreAmount()) + && ItemStack.areItemsAndComponentsEqual(from, to) + ); + } + } + + @ModifyArg(method = "applyEquipOffset", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;translate(FFF)V"), index = 1) + private float injectDisableEquipOffset(float y) { + if (ModuleAnimations.INSTANCE.getRunning() && !ModuleAnimations.EquipOffset.INSTANCE.getRunning()) { + return EQUIP_OFFSET_TRANSLATE_Y; + } + + return y; + } } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleAnimations.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleAnimations.kt index 600e6534b1f..a1f85993fc0 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleAnimations.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleAnimations.kt @@ -45,6 +45,7 @@ object ModuleAnimations : ClientModule("Animations", Category.RENDER) { init { tree(MainHand) tree(OffHand) + tree(EquipOffset) } object MainHand : ToggleableConfigurable(this, "MainHand", false) { @@ -72,19 +73,18 @@ object ModuleAnimations : ClientModule("Animations", Category.RENDER) { * of a sword. * This choice is only used when the [ModuleSwordBlock] module is enabled. */ - var blockAnimationChoice = choices( + val blockAnimationChoice = choices( "BlockingAnimation", OneSevenAnimation, arrayOf( OneSevenAnimation, PushdownAnimation ) ) - /** - * If true, the original Minecraft equip offset will be applied. - * This causes the blocking to look weirdly fast and cause the sword to almost disappear from - * the screen. - */ - var equipOffset by boolean("EquipOffset", false) + object EquipOffset : ToggleableConfigurable(this, "EquipOffset", true) { + val ignoreBlocking by boolean("IgnoreBlocking", true) + val ignorePlace by boolean("IgnorePlace", true) + val ignoreAmount by boolean("IgnoreAmount", false) + } /** * if true, the walk animation will also be applied in the air.