Skip to content

Commit 3421d02

Browse files
committed
working old swing animation and swap animation settings
1 parent 98daf85 commit 3421d02

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

common/src/main/java/com/lambda/mixin/render/HeldItemRendererMixin.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
package com.lambda.mixin.render;
22

33
import com.lambda.module.modules.render.ViewModel;
4+
import net.minecraft.client.MinecraftClient;
45
import net.minecraft.client.network.AbstractClientPlayerEntity;
56
import net.minecraft.client.render.VertexConsumerProvider;
67
import net.minecraft.client.render.item.HeldItemRenderer;
78
import net.minecraft.client.util.math.MatrixStack;
89
import net.minecraft.item.ItemStack;
910
import net.minecraft.util.Hand;
11+
import org.spongepowered.asm.mixin.Final;
1012
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Shadow;
1114
import org.spongepowered.asm.mixin.injection.At;
1215
import org.spongepowered.asm.mixin.injection.Inject;
16+
import org.spongepowered.asm.mixin.injection.ModifyArg;
1317
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1418

1519
@Mixin(HeldItemRenderer.class)
1620
public class HeldItemRendererMixin {
21+
@Final @Shadow private MinecraftClient client;
22+
@Shadow private ItemStack mainHand;
23+
@Shadow private ItemStack offHand;
24+
@Shadow private float equipProgressMainHand;
25+
@Shadow private float equipProgressOffHand;
26+
1727
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderArmHoldingItem(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IFFLnet/minecraft/util/Arm;)V"))
1828
private void onRenderArmHoldingItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack itemStack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
1929
if (!ViewModel.INSTANCE.isEnabled()) return;
@@ -27,4 +37,33 @@ private void onRenderFirstPersonItem(AbstractClientPlayerEntity player, float ti
2737

2838
ViewModel.INSTANCE.transform(itemStack, hand, matrices);
2939
}
40+
41+
@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 2), index = 0)
42+
private float modifyEquipProgressMainHand(float value) {
43+
if (client.player == null || ViewModel.INSTANCE.isDisabled()) return value;
44+
45+
ViewModel config = ViewModel.INSTANCE;
46+
ItemStack currentStack = client.player.getMainHandStack();
47+
if (!config.getSwapAnimation()) {
48+
mainHand = currentStack;
49+
}
50+
51+
float progress = config.getOldAnimations() || !config.getSwapAnimation() ? 1 : (float) Math.pow(client.player.getAttackCooldownProgress(1), 3);
52+
53+
return (ItemStack.areEqual(mainHand, currentStack) ? progress : 0) - equipProgressMainHand;
54+
}
55+
56+
@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 3), index = 0)
57+
private float modifyEquipProgressOffhand(float value) {
58+
if (client.player == null || ViewModel.INSTANCE.isDisabled()) return value;
59+
60+
ViewModel config = ViewModel.INSTANCE;
61+
62+
ItemStack currentStack = client.player.getOffHandStack();
63+
if (!config.getSwapAnimation()) {
64+
offHand = currentStack;
65+
}
66+
67+
return (ItemStack.areEqual(offHand, currentStack) || !config.getSwapAnimation() ? 1 : 0) - equipProgressOffHand;
68+
}
3069
}

common/src/main/kotlin/com/lambda/module/modules/render/ViewModel.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ object ViewModel : Module(
2424
private val ignoreHand by setting("Ignore Hand", false, "Prevents adjusting the players hand", visibility = { page == Page.General })
2525
private val swingMode by setting("Swing Mode", SwingMode.Standard, "Changes which hands swing", visibility = { page == Page.General })
2626
val swingSpeed by setting("Swing Speed", 6, 0..20, 1, "Adjusts how fast the player swings", visibility = { page == Page.General })
27-
val swingProgress by setting("Swing Progress", 0.0f, 0.0f..1.0f, 0.025f, "Renders as if the player was this progress through the swing animation", visibility = { page == Page.General })
28-
val oldSwingAnimation by setting("Old Swing Animation", false, "Adjusts the swing animation to what it looked like in 1.8", visibility = { page == Page.General })
29-
val swapAnimation by setting("Swap Animation", true, "If disabled, it removes the drop down animation when swapping item", visibility = { page == Page.General })
27+
val mainSwingProgress by setting("Main Swing Progress", 0.0f, 0.0f..1.0f, 0.025f, "Renders as if the players main hand was this progress through the swing animation", visibility = { page == Page.General })
28+
val offhandSwingProgress by setting("Offhand Swing Progress", 0.0f, 0.0f..1.0f, 0.025f, "Renders as if the players offhand was this progress through the swing animation", visibility = { page == Page.General })
29+
val oldAnimations by setting("Old Animations", false, "Adjusts the animations to look like they did in 1.8", visibility = { page == Page.General })
30+
val swapAnimation by setting("Swap Animation", true, "If disabled, it removes the drop down animation when swapping item", visibility = { page == Page.General && oldAnimations })
3031
val shadow by setting("Shadows", true, "If disabled, it removes shadows on the model", visibility = { page == Page.General })
3132

3233
private val linkedScale by setting("Linked Scale", true, "Links both hands scale settings", visibility = { page == Page.Scale })
3334
private val leftXScale by setting("Left X Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale }).apply { onValueChange { _, to -> if (linkedScale) rightXScale = to } }
3435
private val leftYScale by setting("Left Y Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale }).apply { onValueChange { _, to -> if (linkedScale) rightYScale = to } }
3536
private val leftZScale by setting("Left Z Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale }).apply { onValueChange { _, to -> if (linkedScale) rightZScale = to } }
36-
private var rightXScale by setting("Right X Scale", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
37-
private var rightYScale by setting("Right Y Scale", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
38-
private var rightZScale by setting("Right Z Scale", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
37+
private var rightXScale by setting("Right X Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
38+
private var rightYScale by setting("Right Y Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
39+
private var rightZScale by setting("Right Z Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
3940

4041
private val linkedPosition by setting("Linked Position", true, "Links both hands position settings", visibility = { page == Page.Position })
4142
private val leftXPosition by setting("Left X Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Position }).apply { onValueChange { _, to -> if (linkedPosition) rightXPosition = to } }

0 commit comments

Comments
 (0)