Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Animations): better EquipOffset #5420

Open
wants to merge 1 commit into
base: nextgen
Choose a base branch
from
Open
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 @@ -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
Loading