From ed1941abdb7f153b6ca8a3ac5ea946532d72f0e5 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 28 Oct 2018 18:37:21 -0500 Subject: [PATCH] Fix desynchronized allowFlying state --- .../launch/mixins/MixinEntityPlayerSP.java | 15 +++++++++++++++ .../java/baritone/behavior/PathingBehavior.java | 1 - .../java/baritone/pathing/movement/Movement.java | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 39bc8af1..dd121ead 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -21,10 +21,13 @@ import baritone.Baritone; import baritone.api.event.events.ChatEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.type.EventState; +import baritone.behavior.PathingBehavior; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.PlayerCapabilities; 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.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; /** @@ -72,4 +75,16 @@ public class MixinEntityPlayerSP { private void onPostUpdate(CallbackInfo ci) { Baritone.INSTANCE.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.POST)); } + + @Redirect( + method = "onLivingUpdate", + at = @At( + value = "FIELD", + target = "net/minecraft/entity/player/PlayerCapabilities.allowFlying:Z" + ) + ) + private boolean isAllowFlying(PlayerCapabilities capabilities) { + PathingBehavior pathingBehavior = Baritone.INSTANCE.getPathingBehavior(); + return (!pathingBehavior.isEnabled() || !pathingBehavior.isPathing()) && capabilities.allowFlying; + } } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index a5845146..65fa6cd5 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -83,7 +83,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, cancel(); return; } - mc.playerController.setPlayerCapabilities(mc.player); tickPath(); dispatchEvents(); } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 16ceeefe..a2edb2c9 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -114,7 +114,7 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { */ @Override public MovementStatus update() { - player().capabilities.allowFlying = false; + player().capabilities.isFlying = false; MovementState latestState = updateState(currentState); if (BlockStateInterface.isLiquid(playerFeet())) { latestState.setInput(Input.JUMP, true);