Add player update injection

This commit is contained in:
Howard Stark 2018-08-04 22:58:32 -04:00
parent 9bda792a3e
commit 4608086656
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
4 changed files with 30 additions and 2 deletions

View File

@ -24,8 +24,8 @@ public final class GameEventHandler implements IGameEventListener {
} }
@Override @Override
public void onRenderPass() { public void onPlayerUpdate() {
dispatch(Behavior::onRenderPass); dispatch(Behavior::onPlayerUpdate);
} }
@Override @Override
@ -57,6 +57,11 @@ public final class GameEventHandler implements IGameEventListener {
dispatch(behavior -> behavior.onChunkEvent(event)); dispatch(behavior -> behavior.onChunkEvent(event));
} }
@Override
public void onRenderPass() {
dispatch(Behavior::onRenderPass);
}
private void dispatch(Consumer<Behavior> dispatchFunction) { private void dispatch(Consumer<Behavior> dispatchFunction) {
Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction); Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction);
} }

View File

@ -21,6 +21,9 @@ public interface AbstractGameEventListener extends IGameEventListener {
@Override @Override
default void onTick() {} default void onTick() {}
@Override
default void onPlayerUpdate() {}
@Override @Override
default void onProcessKeyBinds() {} default void onProcessKeyBinds() {}

View File

@ -5,6 +5,7 @@ import baritone.bot.event.events.ChunkEvent;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.EntityRenderer;
/** /**
* @author Brady * @author Brady
@ -19,6 +20,12 @@ public interface IGameEventListener {
*/ */
void onTick(); 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. * Run once per game tick from before keybinds are processed.
* *
@ -43,6 +50,8 @@ public interface IGameEventListener {
/** /**
* Runs once each frame * Runs once each frame
*
* @see EntityRenderer#renderWorldPass(int, float, long)
*/ */
void onRenderPass(); void onRenderPass();
} }

View File

@ -26,4 +26,15 @@ public class MixinEntityPlayerSP {
if (event.isCancelled()) if (event.isCancelled())
ci.cancel(); ci.cancel();
} }
@Inject(
method = "onUpdate",
at = @At(
value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/client/entity/AbstractClientPlayer;onUpdate()V"
)
)
public void onUpdate(CallbackInfo ci) {
}
} }