Skip to content

Commit

Permalink
feat(Animations): better EquipOffset (#5420)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan authored Jan 25, 2025
1 parent 4e57074 commit 8e0db36
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(HeldItemRenderer.class)
public abstract class MixinHeldItemRenderer {
Expand All @@ -55,6 +56,10 @@ public abstract class MixinHeldItemRenderer {
@Shadow
private ItemStack offHand;

@Shadow
@Final
private static float EQUIP_OFFSET_TRANSLATE_Y;

@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;push()V", shift = At.Shift.AFTER))
private void hookRenderFirstPersonItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
if (ModuleAnimations.INSTANCE.getRunning()) {
Expand Down Expand Up @@ -162,8 +167,8 @@ private int hookItemUseItem(AbstractClientPlayerEntity instance) {
target = "Lnet/minecraft/client/render/item/HeldItemRenderer;applyEquipOffset(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/Arm;F)V",
ordinal = 3
), index = 2)
private float applyEquipOffset(float equipProgress) {
if (ModuleAnimations.INSTANCE.getRunning() && !ModuleAnimations.INSTANCE.getEquipOffset()) {
private float injectIgnoreBlocking(float equipProgress) {
if (ModuleAnimations.EquipOffset.INSTANCE.getRunning() && ModuleAnimations.EquipOffset.INSTANCE.getIgnoreBlocking()) {
return 0.0F;
}

Expand Down Expand Up @@ -229,4 +234,29 @@ private float injectSilentHotbarNoCooldown(float original) {
return original;
}

@Inject(method = "resetEquipProgress", at = @At("HEAD"), cancellable = true)
private void injectIgnorePlace(Hand hand, CallbackInfo ci) {
if (ModuleAnimations.INSTANCE.getRunning() && ModuleAnimations.EquipOffset.INSTANCE.getIgnorePlace()) {
ci.cancel();
}
}

@Inject(method = "shouldSkipHandAnimationOnSwap", at = @At("RETURN"), cancellable = true)
private void injectIgnoreAmount(ItemStack from, ItemStack to, CallbackInfoReturnable<Boolean> cir) {
if (ModuleAnimations.INSTANCE.getRunning() && !cir.getReturnValueZ()) {
cir.setReturnValue(!ModuleAnimations.EquipOffset.INSTANCE.getRunning()
|| (from.getCount() == to.getCount() || ModuleAnimations.EquipOffset.INSTANCE.getIgnoreAmount())
&& ItemStack.areItemsAndComponentsEqual(from, to)
);
}
}

@ModifyArg(method = "applyEquipOffset", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;translate(FFF)V"), index = 1)
private float injectDisableEquipOffset(float y) {
if (ModuleAnimations.INSTANCE.getRunning() && !ModuleAnimations.EquipOffset.INSTANCE.getRunning()) {
return EQUIP_OFFSET_TRANSLATE_Y;
}

return y;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ object ModuleAnimations : ClientModule("Animations", Category.RENDER) {
init {
tree(MainHand)
tree(OffHand)
tree(EquipOffset)
}

object MainHand : ToggleableConfigurable(this, "MainHand", false) {
Expand Down Expand Up @@ -72,19 +73,18 @@ object ModuleAnimations : ClientModule("Animations", Category.RENDER) {
* of a sword.
* This choice is only used when the [ModuleSwordBlock] module is enabled.
*/
var blockAnimationChoice = choices(
val blockAnimationChoice = choices(
"BlockingAnimation", OneSevenAnimation, arrayOf(
OneSevenAnimation,
PushdownAnimation
)
)

/**
* If true, the original Minecraft equip offset will be applied.
* This causes the blocking to look weirdly fast and cause the sword to almost disappear from
* the screen.
*/
var equipOffset by boolean("EquipOffset", false)
object EquipOffset : ToggleableConfigurable(this, "EquipOffset", true) {
val ignoreBlocking by boolean("IgnoreBlocking", true)
val ignorePlace by boolean("IgnorePlace", true)
val ignoreAmount by boolean("IgnoreAmount", false)
}

/**
* if true, the walk animation will also be applied in the air.
Expand Down

0 comments on commit 8e0db36

Please sign in to comment.