From 74d82f23398cad94e900243bafc8f9fc4d004e1b Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Mon, 17 Jun 2024 00:10:58 -0500 Subject: [PATCH 1/2] fix neoforge and forge for 1.20.5+ --- buildSrc/build.gradle | 2 +- neoforge/build.gradle | 2 +- .../mixins/MixinClientPlayerEntity.java | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index b613c5d6b..a6855791f 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -40,5 +40,5 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0' implementation group: 'commons-io', name: 'commons-io', version: '2.7' - implementation group: 'xyz.wagyourtail.unimined', name: 'xyz.wagyourtail.unimined.gradle.plugin', version: '1.2.3' + implementation group: 'xyz.wagyourtail.unimined', name: 'xyz.wagyourtail.unimined.gradle.plugin', version: '1.2.9' } \ No newline at end of file diff --git a/neoforge/build.gradle b/neoforge/build.gradle index c6c3d5c5c..6b97406fd 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -68,7 +68,7 @@ dependencies { processResources { inputs.property "version", project.version - filesMatching("META-INF/mods.toml") { + filesMatching("META-INF/neoforge.mods.toml") { expand "version": project.version } } diff --git a/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java b/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java index 24e807f62..4be5d910f 100644 --- a/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java +++ b/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java @@ -27,17 +27,37 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.entity.player.Abilities; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Group; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + /** * @author Brady * @since 8/1/2018 */ @Mixin(LocalPlayer.class) public class MixinClientPlayerEntity { + @Unique + private static final MethodHandle MAY_FLY; + static { + MethodHandle mayFly1; + try { + var lookup = MethodHandles.publicLookup(); + mayFly1 = lookup.findVirtual(LocalPlayer.class, "mayFly", MethodType.methodType(boolean.class)); + } catch (NoSuchMethodException e) { + mayFly1 = null; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + MAY_FLY = mayFly1; + } @Inject( method = "tick", @@ -61,6 +81,7 @@ private void onPreUpdate(CallbackInfo ci) { target = "net/minecraft/world/entity/player/Abilities.mayfly:Z" ) ) + @Group(name = "mayFly", min = 1, max = 1) private boolean isAllowFlying(Abilities capabilities) { IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this); if (baritone == null) { @@ -69,6 +90,22 @@ private boolean isAllowFlying(Abilities capabilities) { return !baritone.getPathingBehavior().isPathing() && capabilities.mayfly; } + @Redirect( + method = "aiStep", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/player/LocalPlayer;mayFly()Z" + ) + ) + @Group(name = "mayFly", min = 1, max = 1) + private boolean onMayFlyNeoforge(LocalPlayer instance) throws Throwable { + IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((LocalPlayer) (Object) this); + if (baritone == null) { + return (boolean) MAY_FLY.invokeExact(instance); + } + return !baritone.getPathingBehavior().isPathing() && (boolean) MAY_FLY.invokeExact(instance); + } + @Redirect( method = "aiStep", at = @At( From 81f7375591dd7b5539c60edec0f9eb3004591faa Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Mon, 17 Jun 2024 00:26:34 -0500 Subject: [PATCH 2/2] fix mixin eating my try-catch --- .../launch/mixins/MixinClientPlayerEntity.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java b/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java index 4be5d910f..9f59a9adc 100644 --- a/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java +++ b/src/launch/java/baritone/launch/mixins/MixinClientPlayerEntity.java @@ -45,18 +45,18 @@ @Mixin(LocalPlayer.class) public class MixinClientPlayerEntity { @Unique - private static final MethodHandle MAY_FLY; - static { - MethodHandle mayFly1; + private static final MethodHandle MAY_FLY = baritone$resolveMayFly(); + + @Unique + private static MethodHandle baritone$resolveMayFly() { try { var lookup = MethodHandles.publicLookup(); - mayFly1 = lookup.findVirtual(LocalPlayer.class, "mayFly", MethodType.methodType(boolean.class)); + return lookup.findVirtual(LocalPlayer.class, "mayFly", MethodType.methodType(boolean.class)); } catch (NoSuchMethodException e) { - mayFly1 = null; + return null; } catch (IllegalAccessException e) { throw new RuntimeException(e); } - MAY_FLY = mayFly1; } @Inject(