diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/HeldItemRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/HeldItemRendererMixin.java index 094cf3033d..185c6cff59 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/HeldItemRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/HeldItemRendererMixin.java @@ -5,7 +5,7 @@ package meteordevelopment.meteorclient.mixin; -import com.google.common.base.MoreObjects; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.render.ArmRenderEvent; @@ -18,6 +18,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.registry.tag.ItemTags; import net.minecraft.util.Arm; import net.minecraft.util.Hand; import org.spongepowered.asm.mixin.Mixin; @@ -25,9 +26,10 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Objects; + import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(HeldItemRenderer.class) @@ -47,16 +49,19 @@ public abstract class HeldItemRendererMixin { @Shadow protected abstract boolean shouldSkipHandAnimationOnSwap(ItemStack from, ItemStack to); - @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) + @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")) private float modifySwing(float swingProgress) { HandView module = Modules.get().get(HandView.class); - Hand hand = MoreObjects.firstNonNull(mc.player.preferredHand, Hand.MAIN_HAND); + Hand hand = Objects.requireNonNullElse(mc.player.preferredHand, Hand.MAIN_HAND); if (module.isActive()) { - if (hand == Hand.OFF_HAND && !mc.player.getOffHandStack().isEmpty()) { + if (module.swordSlash() && hand == Hand.MAIN_HAND && mainHand.isIn(ItemTags.SWORDS)) { + return 0f; + } + if (hand == Hand.OFF_HAND && !offHand.isEmpty()) { return swingProgress + module.offSwing.get().floatValue(); } - if (hand == Hand.MAIN_HAND && !mc.player.getMainHandStack().isEmpty()) { + if (hand == Hand.MAIN_HAND && !mainHand.isEmpty()) { return swingProgress + module.mainSwing.get().floatValue(); } } @@ -71,8 +76,11 @@ private boolean modifySkipSwapAnimation(boolean original) { @ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 2), index = 0) private float modifyEquipProgressMainhand(float value) { + HandView handView = Modules.get().get(HandView.class); + if (handView.swordSlash() && mc.player.getMainHandStack().isIn(ItemTags.SWORDS)) return value; + float f = mc.player.getHandEquippingProgress(1f); - float modified = Modules.get().get(HandView.class).oldAnimations() ? 1 : f * f * f; + float modified = handView.oldAnimations() ? 1 : f * f * f; return (shouldSkipHandAnimationOnSwap(mainHand, mc.player.getMainHandStack()) ? modified : 0) - equipProgressMainHand; } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java index 892a8f9924..2e30685d6f 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java @@ -67,7 +67,7 @@ private void onEquipStack(EquipmentSlot slot, ItemStack oldStack, ItemStack newS } } - @ModifyArg(method = "swingHand(Lnet/minecraft/util/Hand;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;swingHand(Lnet/minecraft/util/Hand;Z)V")) + @ModifyVariable(method = "swingHand(Lnet/minecraft/util/Hand;Z)V", at = @At("HEAD"), argsOnly = true) private Hand setHand(Hand hand) { if ((Object) this != mc.player) return hand; @@ -76,6 +76,7 @@ private Hand setHand(Hand hand) { if (handView.swingMode.get() == HandView.SwingMode.None) return hand; return handView.swingMode.get() == HandView.SwingMode.Offhand ? Hand.OFF_HAND : Hand.MAIN_HAND; } + return hand; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/HandView.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/HandView.java index 214054d993..13cabdeba4 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/HandView.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/HandView.java @@ -53,6 +53,13 @@ public class HandView extends Module { .build() ); + public final Setting swordSlash = sgGeneral.add(new BoolSetting.Builder() + .name("sword-slash") + .description("Replaces the sword swing animation with the offhand idle animation.") + .defaultValue(false) + .build() + ); + public final Setting swingMode = sgGeneral.add(new EnumSetting.Builder() .name("swing-mode") .description("Modifies your client & server hand swinging.") @@ -231,6 +238,10 @@ public boolean disableFoodAnimation() { return isActive() && disableFoodAnimation.get(); } + public boolean swordSlash() { + return isActive() && swordSlash.get(); + } + public enum SwingMode { Offhand, Mainhand,