Skip to content

Commit 48ebeeb

Browse files
committed
Clean up the HandView 'skip swap animation' setting
1 parent 5f89e8d commit 48ebeeb

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/main/java/meteordevelopment/meteorclient/mixin/HeldItemRendererMixin.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package meteordevelopment.meteorclient.mixin;
77

88
import com.google.common.base.MoreObjects;
9+
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
910
import meteordevelopment.meteorclient.MeteorClient;
1011
import meteordevelopment.meteorclient.events.render.ArmRenderEvent;
1112
import meteordevelopment.meteorclient.events.render.HeldItemRendererEvent;
@@ -21,8 +22,10 @@
2122
import net.minecraft.util.Hand;
2223
import org.spongepowered.asm.mixin.Mixin;
2324
import org.spongepowered.asm.mixin.Shadow;
24-
import org.spongepowered.asm.mixin.Unique;
25-
import org.spongepowered.asm.mixin.injection.*;
25+
import org.spongepowered.asm.mixin.injection.At;
26+
import org.spongepowered.asm.mixin.injection.Inject;
27+
import org.spongepowered.asm.mixin.injection.ModifyArg;
28+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
2629
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2730

2831
import static meteordevelopment.meteorclient.MeteorClient.mc;
@@ -41,6 +44,9 @@ public abstract class HeldItemRendererMixin {
4144
@Shadow
4245
private ItemStack offHand;
4346

47+
@Shadow
48+
protected abstract boolean shouldSkipHandAnimationOnSwap(ItemStack from, ItemStack to);
49+
4450
@ModifyVariable(method = "renderItem(FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/network/ClientPlayerEntity;I)V", at = @At(value = "STORE", ordinal = 0), index = 6)
4551
private float modifySwing(float swingProgress) {
4652
HandView module = Modules.get().get(HandView.class);
@@ -58,22 +64,22 @@ private float modifySwing(float swingProgress) {
5864
return swingProgress;
5965
}
6066

61-
@Redirect(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;shouldSkipHandAnimationOnSwap(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"))
62-
private boolean redirectSwapping(HeldItemRenderer instance, ItemStack from, ItemStack to) {
63-
return skipSwapAnimation(from, to);
67+
@ModifyReturnValue(method = "shouldSkipHandAnimationOnSwap", at = @At("RETURN"))
68+
private boolean modifySkipSwapAnimation(boolean original) {
69+
return original || Modules.get().get(HandView.class).skipSwapping();
6470
}
6571

6672
@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 2), index = 0)
6773
private float modifyEquipProgressMainhand(float value) {
6874
float f = mc.player.getAttackCooldownProgress(1f);
6975
float modified = Modules.get().get(HandView.class).oldAnimations() ? 1 : f * f * f;
7076

71-
return (skipSwapAnimation(mainHand, mc.player.getMainHandStack()) ? modified : 0) - equipProgressMainHand;
77+
return (shouldSkipHandAnimationOnSwap(mainHand, mc.player.getMainHandStack()) ? modified : 0) - equipProgressMainHand;
7278
}
7379

7480
@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 3), index = 0)
7581
private float modifyEquipProgressOffhand(float value) {
76-
return (skipSwapAnimation(offHand, mc.player.getOffHandStack()) ? 1 : 0) - equipProgressOffHand;
82+
return (shouldSkipHandAnimationOnSwap(offHand, mc.player.getOffHandStack()) ? 1 : 0) - equipProgressOffHand;
7783
}
7884

7985
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemDisplayContext;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", shift = At.Shift.BEFORE))
@@ -90,9 +96,4 @@ private void onRenderArm(AbstractClientPlayerEntity player, float tickDelta, flo
9096
private void cancelTransformations(MatrixStack matrices, float tickDelta, Arm arm, ItemStack stack, PlayerEntity player, CallbackInfo ci) {
9197
if (Modules.get().get(HandView.class).disableFoodAnimation()) ci.cancel();
9298
}
93-
94-
@Unique
95-
private boolean skipSwapAnimation(ItemStack stack1, ItemStack stack2) {
96-
return !Modules.get().get(HandView.class).showSwapping() || ItemStack.areEqual(stack1, stack2);
97-
}
9899
}

src/main/java/meteordevelopment/meteorclient/systems/modules/render/HandView.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public class HandView extends Module {
3939
.build()
4040
);
4141

42-
public final Setting<Boolean> showSwapping = sgGeneral.add(new BoolSetting.Builder()
43-
.name("show-swapping")
44-
.description("Whether or not to show the item swapping animation")
45-
.defaultValue(true)
42+
public final Setting<Boolean> skipSwapping = sgGeneral.add(new BoolSetting.Builder()
43+
.name("skip-swapping-animation")
44+
.description("Whether or not to skip the item swapping animation")
45+
.defaultValue(false)
4646
.build()
4747
);
4848

@@ -223,8 +223,8 @@ public boolean oldAnimations() {
223223
return isActive() && oldAnimations.get();
224224
}
225225

226-
public boolean showSwapping() {
227-
return isActive() && showSwapping.get();
226+
public boolean skipSwapping() {
227+
return isActive() && skipSwapping.get();
228228
}
229229

230230
public boolean disableFoodAnimation() {

0 commit comments

Comments
 (0)