Skip to content

Commit f6ea9bf

Browse files
authored
Add "Sword Slash" swing animation to HandView (#6291)
1 parent 1c7927f commit f6ea9bf

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package meteordevelopment.meteorclient.mixin;
77

8-
import com.google.common.base.MoreObjects;
8+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
99
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
1010
import meteordevelopment.meteorclient.MeteorClient;
1111
import meteordevelopment.meteorclient.events.render.ArmRenderEvent;
@@ -18,16 +18,18 @@
1818
import net.minecraft.client.util.math.MatrixStack;
1919
import net.minecraft.entity.player.PlayerEntity;
2020
import net.minecraft.item.ItemStack;
21+
import net.minecraft.registry.tag.ItemTags;
2122
import net.minecraft.util.Arm;
2223
import net.minecraft.util.Hand;
2324
import org.spongepowered.asm.mixin.Mixin;
2425
import org.spongepowered.asm.mixin.Shadow;
2526
import org.spongepowered.asm.mixin.injection.At;
2627
import org.spongepowered.asm.mixin.injection.Inject;
2728
import org.spongepowered.asm.mixin.injection.ModifyArg;
28-
import org.spongepowered.asm.mixin.injection.ModifyVariable;
2929
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3030

31+
import java.util.Objects;
32+
3133
import static meteordevelopment.meteorclient.MeteorClient.mc;
3234

3335
@Mixin(HeldItemRenderer.class)
@@ -47,16 +49,19 @@ public abstract class HeldItemRendererMixin {
4749
@Shadow
4850
protected abstract boolean shouldSkipHandAnimationOnSwap(ItemStack from, ItemStack to);
4951

50-
@ModifyVariable(method = "renderItem(FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/command/OrderedRenderCommandQueue;Lnet/minecraft/client/network/ClientPlayerEntity;I)V", at = @At(value = "STORE", ordinal = 0), index = 6)
52+
@ModifyExpressionValue(method = "renderItem(FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/command/OrderedRenderCommandQueue;Lnet/minecraft/client/network/ClientPlayerEntity;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getHandSwingProgress(F)F"))
5153
private float modifySwing(float swingProgress) {
5254
HandView module = Modules.get().get(HandView.class);
53-
Hand hand = MoreObjects.firstNonNull(mc.player.preferredHand, Hand.MAIN_HAND);
55+
Hand hand = Objects.requireNonNullElse(mc.player.preferredHand, Hand.MAIN_HAND);
5456

5557
if (module.isActive()) {
56-
if (hand == Hand.OFF_HAND && !mc.player.getOffHandStack().isEmpty()) {
58+
if (module.swordSlash() && hand == Hand.MAIN_HAND && mainHand.isIn(ItemTags.SWORDS)) {
59+
return 0f;
60+
}
61+
if (hand == Hand.OFF_HAND && !offHand.isEmpty()) {
5762
return swingProgress + module.offSwing.get().floatValue();
5863
}
59-
if (hand == Hand.MAIN_HAND && !mc.player.getMainHandStack().isEmpty()) {
64+
if (hand == Hand.MAIN_HAND && !mainHand.isEmpty()) {
6065
return swingProgress + module.mainSwing.get().floatValue();
6166
}
6267
}
@@ -71,8 +76,11 @@ private boolean modifySkipSwapAnimation(boolean original) {
7176

7277
@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 2), index = 0)
7378
private float modifyEquipProgressMainhand(float value) {
79+
HandView handView = Modules.get().get(HandView.class);
80+
if (handView.swordSlash() && mc.player.getMainHandStack().isIn(ItemTags.SWORDS)) return value;
81+
7482
float f = mc.player.getHandEquippingProgress(1f);
75-
float modified = Modules.get().get(HandView.class).oldAnimations() ? 1 : f * f * f;
83+
float modified = handView.oldAnimations() ? 1 : f * f * f;
7684

7785
return (shouldSkipHandAnimationOnSwap(mainHand, mc.player.getMainHandStack()) ? modified : 0) - equipProgressMainHand;
7886
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void onEquipStack(EquipmentSlot slot, ItemStack oldStack, ItemStack newS
6767
}
6868
}
6969

70-
@ModifyArg(method = "swingHand(Lnet/minecraft/util/Hand;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;swingHand(Lnet/minecraft/util/Hand;Z)V"))
70+
@ModifyVariable(method = "swingHand(Lnet/minecraft/util/Hand;Z)V", at = @At("HEAD"), argsOnly = true)
7171
private Hand setHand(Hand hand) {
7272
if ((Object) this != mc.player) return hand;
7373

@@ -76,6 +76,7 @@ private Hand setHand(Hand hand) {
7676
if (handView.swingMode.get() == HandView.SwingMode.None) return hand;
7777
return handView.swingMode.get() == HandView.SwingMode.Offhand ? Hand.OFF_HAND : Hand.MAIN_HAND;
7878
}
79+
7980
return hand;
8081
}
8182

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ public class HandView extends Module {
5353
.build()
5454
);
5555

56+
public final Setting<Boolean> swordSlash = sgGeneral.add(new BoolSetting.Builder()
57+
.name("sword-slash")
58+
.description("Replaces the sword swing animation with the offhand idle animation.")
59+
.defaultValue(false)
60+
.build()
61+
);
62+
5663
public final Setting<SwingMode> swingMode = sgGeneral.add(new EnumSetting.Builder<SwingMode>()
5764
.name("swing-mode")
5865
.description("Modifies your client & server hand swinging.")
@@ -231,6 +238,10 @@ public boolean disableFoodAnimation() {
231238
return isActive() && disableFoodAnimation.get();
232239
}
233240

241+
public boolean swordSlash() {
242+
return isActive() && swordSlash.get();
243+
}
244+
234245
public enum SwingMode {
235246
Offhand,
236247
Mainhand,

0 commit comments

Comments
 (0)