Automatically disable auto-jump while pathing is active, fixes #31

This commit is contained in:
Brady 2018-08-21 17:04:10 -05:00
parent a9cac7718e
commit 194dd7abe7
No known key found for this signature in database
GPG Key ID: 73A788379A197567
9 changed files with 95 additions and 10 deletions

View File

@ -18,6 +18,8 @@
package baritone.bot.behavior.impl; package baritone.bot.behavior.impl;
import baritone.bot.behavior.Behavior; import baritone.bot.behavior.Behavior;
import baritone.bot.event.events.PlayerUpdateEvent;
import baritone.bot.event.events.type.EventState;
import baritone.bot.utils.Rotation; import baritone.bot.utils.Rotation;
public class LookBehavior extends Behavior { public class LookBehavior extends Behavior {
@ -39,8 +41,8 @@ public class LookBehavior extends Behavior {
} }
@Override @Override
public void onPlayerUpdate() { public void onPlayerUpdate(PlayerUpdateEvent event) {
if (target != null) { if (event.getState() == EventState.PRE && target != null) {
player().rotationYaw = target.getFirst(); player().rotationYaw = target.getFirst();
float oldPitch = player().rotationPitch; float oldPitch = player().rotationPitch;
float desiredPitch = target.getSecond(); float desiredPitch = target.getSecond();

View File

@ -2,6 +2,8 @@ package baritone.bot.behavior.impl;
import baritone.bot.behavior.Behavior; import baritone.bot.behavior.Behavior;
import baritone.bot.event.events.PacketEvent; import baritone.bot.event.events.PacketEvent;
import baritone.bot.event.events.PlayerUpdateEvent;
import baritone.bot.event.events.type.EventState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketCloseWindow; import net.minecraft.network.play.client.CPacketCloseWindow;
@ -35,7 +37,8 @@ public class MemoryBehavior extends Behavior {
private final Map<BlockPos, RememberedInventory> rememberedInventories = new HashMap<>(); private final Map<BlockPos, RememberedInventory> rememberedInventories = new HashMap<>();
@Override @Override
public void onPlayerUpdate() { public void onPlayerUpdate(PlayerUpdateEvent event) {
if (event.getState() == EventState.PRE)
updateInventory(); updateInventory();
} }

View File

@ -19,6 +19,7 @@ package baritone.bot.behavior.impl;
import baritone.bot.Baritone; import baritone.bot.Baritone;
import baritone.bot.behavior.Behavior; import baritone.bot.behavior.Behavior;
import baritone.bot.event.events.PlayerUpdateEvent;
import baritone.bot.event.events.RenderEvent; import baritone.bot.event.events.RenderEvent;
import baritone.bot.event.events.TickEvent; import baritone.bot.event.events.TickEvent;
import baritone.bot.pathing.calc.AStarPathFinder; import baritone.bot.pathing.calc.AStarPathFinder;
@ -53,6 +54,8 @@ public class PathingBehavior extends Behavior {
private final Object pathPlanLock = new Object(); private final Object pathPlanLock = new Object();
private boolean lastAutoJump;
@Override @Override
public void onTick(TickEvent event) { public void onTick(TickEvent event) {
if (event.getType() == TickEvent.Type.OUT) { if (event.getType() == TickEvent.Type.OUT) {
@ -132,6 +135,21 @@ public class PathingBehavior extends Behavior {
} }
} }
@Override
public void onPlayerUpdate(PlayerUpdateEvent event) {
if (current != null) {
switch (event.getState()) {
case PRE:
lastAutoJump = mc.gameSettings.autoJump;
mc.gameSettings.autoJump = false;
break;
case POST:
mc.gameSettings.autoJump = lastAutoJump;
break;
}
}
}
public Optional<Double> ticksRemainingInSegment() { public Optional<Double> ticksRemainingInSegment() {
if (current == null) { if (current == null) {
return Optional.empty(); return Optional.empty();

View File

@ -69,8 +69,8 @@ public final class GameEventHandler implements IGameEventListener, Helper {
} }
@Override @Override
public final void onPlayerUpdate() { public final void onPlayerUpdate(PlayerUpdateEvent event) {
dispatch(IGameEventListener::onPlayerUpdate); dispatch(listener -> listener.onPlayerUpdate(event));
} }
@Override @Override

View File

@ -0,0 +1,44 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.bot.event.events;
import baritone.bot.event.events.type.EventState;
/**
* @author Brady
* @since 8/21/2018
*/
public final class PlayerUpdateEvent {
/**
* The state of the event
*/
private final EventState state;
public PlayerUpdateEvent(EventState state) {
this.state = state;
}
/**
* @return The state of the event
*/
public final EventState getState() {
return this.state;
}
}

View File

@ -52,7 +52,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
default void onTick(TickEvent event) {} default void onTick(TickEvent event) {}
@Override @Override
default void onPlayerUpdate() {} default void onPlayerUpdate(PlayerUpdateEvent event) {}
@Override @Override
default void onProcessKeyBinds() {} default void onProcessKeyBinds() {}

View File

@ -63,7 +63,7 @@ public interface IGameEventListener {
* Run once per game tick from before the player rotation is sent to the server. * Run once per game tick from before the player rotation is sent to the server.
* @see EntityPlayerSP#onUpdate() * @see EntityPlayerSP#onUpdate()
*/ */
void onPlayerUpdate(); void onPlayerUpdate(PlayerUpdateEvent event);
/** /**
* Run once per game tick from before keybinds are processed. * Run once per game tick from before keybinds are processed.

View File

@ -19,6 +19,8 @@ package baritone.launch.mixins;
import baritone.bot.Baritone; import baritone.bot.Baritone;
import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.PlayerUpdateEvent;
import baritone.bot.event.events.type.EventState;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@ -53,7 +55,20 @@ public class MixinEntityPlayerSP {
by = -3 by = -3
) )
) )
private void onUpdate(CallbackInfo ci) { private void onPreUpdate(CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onPlayerUpdate(); Baritone.INSTANCE.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE));
}
@Inject(
method = "onUpdate",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/entity/EntityPlayerSP.onUpdateWalkingPlayer()V",
shift = At.Shift.BY,
by = 2
)
)
private void onPostUpdate(CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST));
} }
} }

View File

@ -4,6 +4,9 @@
"refmap": "mixins.client.refmap.json", "refmap": "mixins.client.refmap.json",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"verbose": false, "verbose": false,
"injectors": {
"maxShiftBy": 2
},
"client": [ "client": [
"MixinEntityPlayerSP", "MixinEntityPlayerSP",
"MixinEntityRenderer", "MixinEntityRenderer",