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
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<Behavior> dispatchFunction) {
Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction);
}

View File

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

View File

@ -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();
}

View File

@ -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) {
}
}