Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,16 +18,18 @@
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;
import org.spongepowered.asm.mixin.Shadow;
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)
Expand All @@ -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();
}
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public class HandView extends Module {
.build()
);

public final Setting<Boolean> 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> swingMode = sgGeneral.add(new EnumSetting.Builder<SwingMode>()
.name("swing-mode")
.description("Modifies your client & server hand swinging.")
Expand Down Expand Up @@ -231,6 +238,10 @@ public boolean disableFoodAnimation() {
return isActive() && disableFoodAnimation.get();
}

public boolean swordSlash() {
return isActive() && swordSlash.get();
}

public enum SwingMode {
Offhand,
Mainhand,
Expand Down
Loading