From 4608086656dbcb1e370e5ab0e0222fd15a0bbe83 Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Sat, 4 Aug 2018 22:58:32 -0400 Subject: [PATCH] Add player update injection --- src/main/java/baritone/bot/GameEventHandler.java | 9 +++++++-- .../baritone/bot/event/AbstractGameEventListener.java | 3 +++ .../java/baritone/bot/event/IGameEventListener.java | 9 +++++++++ .../baritone/launch/mixins/MixinEntityPlayerSP.java | 11 +++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/bot/GameEventHandler.java b/src/main/java/baritone/bot/GameEventHandler.java index 7b5f719c..35cfe22a 100755 --- a/src/main/java/baritone/bot/GameEventHandler.java +++ b/src/main/java/baritone/bot/GameEventHandler.java @@ -24,8 +24,8 @@ public final class GameEventHandler implements IGameEventListener { } @Override - public void onRenderPass() { - dispatch(Behavior::onRenderPass); + public void onPlayerUpdate() { + dispatch(Behavior::onPlayerUpdate); } @Override @@ -57,6 +57,11 @@ public final class GameEventHandler implements IGameEventListener { dispatch(behavior -> behavior.onChunkEvent(event)); } + @Override + public void onRenderPass() { + dispatch(Behavior::onRenderPass); + } + private void dispatch(Consumer dispatchFunction) { Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction); } diff --git a/src/main/java/baritone/bot/event/AbstractGameEventListener.java b/src/main/java/baritone/bot/event/AbstractGameEventListener.java index 4a2b259e..eda61a62 100644 --- a/src/main/java/baritone/bot/event/AbstractGameEventListener.java +++ b/src/main/java/baritone/bot/event/AbstractGameEventListener.java @@ -21,6 +21,9 @@ public interface AbstractGameEventListener extends IGameEventListener { @Override default void onTick() {} + @Override + default void onPlayerUpdate() {} + @Override default void onProcessKeyBinds() {} diff --git a/src/main/java/baritone/bot/event/IGameEventListener.java b/src/main/java/baritone/bot/event/IGameEventListener.java index a6d3054f..515ba6c4 100755 --- a/src/main/java/baritone/bot/event/IGameEventListener.java +++ b/src/main/java/baritone/bot/event/IGameEventListener.java @@ -5,6 +5,7 @@ import baritone.bot.event.events.ChunkEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.renderer.EntityRenderer; /** * @author Brady @@ -19,6 +20,12 @@ public interface IGameEventListener { */ void onTick(); + /** + * Run once per game tick from before the player rotation is sent to the server. + * @see EntityPlayerSP#onUpdate() + */ + void onPlayerUpdate(); + /** * Run once per game tick from before keybinds are processed. * @@ -43,6 +50,8 @@ public interface IGameEventListener { /** * Runs once each frame + * + * @see EntityRenderer#renderWorldPass(int, float, long) */ void onRenderPass(); } diff --git a/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 2a4ebca3..c062a1db 100644 --- a/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -26,4 +26,15 @@ public class MixinEntityPlayerSP { if (event.isCancelled()) ci.cancel(); } + + @Inject( + method = "onUpdate", + at = @At( + value = "INVOKE_ASSIGN", + target = "Lnet/minecraft/client/entity/AbstractClientPlayer;onUpdate()V" + ) + ) + public void onUpdate(CallbackInfo ci) { + + } }