Skip to content

Commit

Permalink
Mixin Compat Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cputnam-a11y authored and emonadeo committed Nov 7, 2024
1 parent a882efa commit e8ff28c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
41 changes: 18 additions & 23 deletions src/main/java/com/emonadeo/autorun/mixin/InputClientMixin.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Boolean> 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<Boolean> 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<Boolean> 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<Boolean> info) {
if (AutoRunMod.left) {
info.setReturnValue(true);
}
@ModifyReturnValue(method = "left", at = @At("TAIL"))
public boolean left(boolean original) {
return original || AutoRunMod.left;
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> 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);
}
}

0 comments on commit e8ff28c

Please sign in to comment.