From e8ff28cf5c4c6fffefa7d788114163f87bf2c267 Mon Sep 17 00:00:00 2001 From: cputnam-a11y Date: Wed, 6 Nov 2024 23:25:25 -0600 Subject: [PATCH] Mixin Compat Changes --- .../autorun/mixin/InputClientMixin.java | 41 ++++++++----------- .../autorun/mixin/LocalPlayerClientMixin.java | 20 ++++----- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/emonadeo/autorun/mixin/InputClientMixin.java b/src/main/java/com/emonadeo/autorun/mixin/InputClientMixin.java index af2924e..49568cc 100644 --- a/src/main/java/com/emonadeo/autorun/mixin/InputClientMixin.java +++ b/src/main/java/com/emonadeo/autorun/mixin/InputClientMixin.java @@ -1,9 +1,8 @@ package com.emonadeo.autorun.mixin; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.emonadeo.autorun.AutoRunMod; @@ -14,32 +13,28 @@ @Environment(EnvType.CLIENT) @Mixin(Input.class) public class InputClientMixin { - - @Inject(method = "forward", at = @At("HEAD"), cancellable = true) - public void forward(CallbackInfoReturnable info) { - if (AutoRunMod.forward) { - info.setReturnValue(true); - } + // In the standard mixin world, + // a redirect implies that you want to stop all + // other mods from touching anything relating to this + // and crash the game if they try. + // For mod compatibility, it is better to find a more specific injector + @ModifyReturnValue(method = "forward", at = @At("TAIL")) + public boolean forward(boolean original) { + return original || AutoRunMod.forward; } - @Inject(method = "backward", at = @At("HEAD"), cancellable = true) - public void backward(CallbackInfoReturnable info) { - if (AutoRunMod.backward) { - info.setReturnValue(true); - } + @ModifyReturnValue(method = "backward", at = @At("TAIL")) + public boolean backward(boolean original) { + return original || AutoRunMod.backward; } - @Inject(method = "right", at = @At("HEAD"), cancellable = true) - public void right(CallbackInfoReturnable info) { - if (AutoRunMod.right) { - info.setReturnValue(true); - } + @ModifyReturnValue(method = "right", at = @At("TAIL")) + public boolean right(boolean original) { + return original || AutoRunMod.right; } - @Inject(method = "left", at = @At("HEAD"), cancellable = true) - public void left(CallbackInfoReturnable info) { - if (AutoRunMod.left) { - info.setReturnValue(true); - } + @ModifyReturnValue(method = "left", at = @At("TAIL")) + public boolean left(boolean original) { + return original || AutoRunMod.left; } } diff --git a/src/main/java/com/emonadeo/autorun/mixin/LocalPlayerClientMixin.java b/src/main/java/com/emonadeo/autorun/mixin/LocalPlayerClientMixin.java index 13337c0..e7b4440 100644 --- a/src/main/java/com/emonadeo/autorun/mixin/LocalPlayerClientMixin.java +++ b/src/main/java/com/emonadeo/autorun/mixin/LocalPlayerClientMixin.java @@ -1,27 +1,27 @@ package com.emonadeo.autorun.mixin; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - import com.emonadeo.autorun.AutoRunMod; - +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; @Environment(EnvType.CLIENT) @Mixin(LocalPlayer.class) public class LocalPlayerClientMixin { - - @Redirect(method = "aiStep()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/KeyMapping;isDown()Z")) - public boolean isSprinting(KeyMapping keySprint) { + // effectively a conditional redirect, + // only overriding other mods if the condition is met + @WrapOperation(method = "aiStep()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/KeyMapping;isDown()Z")) + public boolean isSprinting(KeyMapping instance, Operation original) { Minecraft client = Minecraft.getInstance(); - if (AutoRunMod.sprint && keySprint == client.options.keySprint) { + if (AutoRunMod.sprint && instance == client.options.keySprint) { return true; } - return keySprint.isDown(); + return original.call(instance); } } \ No newline at end of file