From cb09af571a1df456e448daad6e2d44424ae23414 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 5 Aug 2018 14:42:46 -0500 Subject: [PATCH] Create object for render event containing partial ticks --- .../java/baritone/bot/GameEventHandler.java | 8 +++---- .../java/baritone/bot/chunk/CachedChunk.java | 4 ++-- .../bot/event/AbstractGameEventListener.java | 3 ++- .../bot/event/IGameEventListener.java | 8 +++++-- .../bot/event/events/RenderEvent.java | 24 +++++++++++++++++++ .../launch/mixins/MixinEntityRenderer.java | 5 ++-- 6 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 src/main/java/baritone/bot/event/events/RenderEvent.java diff --git a/src/main/java/baritone/bot/GameEventHandler.java b/src/main/java/baritone/bot/GameEventHandler.java index 69a22e50..1edaac83 100755 --- a/src/main/java/baritone/bot/GameEventHandler.java +++ b/src/main/java/baritone/bot/GameEventHandler.java @@ -4,6 +4,7 @@ import baritone.bot.behavior.Behavior; import baritone.bot.event.IGameEventListener; import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.ChunkEvent; +import baritone.bot.event.events.RenderEvent; import baritone.bot.event.events.WorldEvent; import net.minecraft.client.settings.KeyBinding; import org.lwjgl.input.Keyboard; @@ -16,8 +17,7 @@ import java.util.function.Consumer; */ public final class GameEventHandler implements IGameEventListener { - GameEventHandler() { - } + GameEventHandler() {} @Override public final void onTick() { @@ -81,8 +81,8 @@ public final class GameEventHandler implements IGameEventListener { } @Override - public void onRenderPass() { - dispatch(Behavior::onRenderPass); + public void onRenderPass(RenderEvent event) { + dispatch(behavior -> onRenderPass(event)); } @Override diff --git a/src/main/java/baritone/bot/chunk/CachedChunk.java b/src/main/java/baritone/bot/chunk/CachedChunk.java index b139eb69..74632fd0 100644 --- a/src/main/java/baritone/bot/chunk/CachedChunk.java +++ b/src/main/java/baritone/bot/chunk/CachedChunk.java @@ -13,7 +13,7 @@ public final class CachedChunk implements IBlockTypeAccess { /** * The size of the chunk data in bits. Equal to 16 KiB. - *
+ *

* Chunks are 16x16x256, each block requires 2 bits. */ public static final int SIZE = 2 * 16 * 16 * 256; @@ -40,7 +40,7 @@ public final class CachedChunk implements IBlockTypeAccess { /** * The actual raw data of this packed chunk. - *
+ *

* Each block is expressed as 2 bits giving a total of 16 KiB */ private final BitSet data; diff --git a/src/main/java/baritone/bot/event/AbstractGameEventListener.java b/src/main/java/baritone/bot/event/AbstractGameEventListener.java index 9a410478..7b7b0d30 100644 --- a/src/main/java/baritone/bot/event/AbstractGameEventListener.java +++ b/src/main/java/baritone/bot/event/AbstractGameEventListener.java @@ -2,6 +2,7 @@ package baritone.bot.event; import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.ChunkEvent; +import baritone.bot.event.events.RenderEvent; import baritone.bot.event.events.WorldEvent; /** @@ -35,7 +36,7 @@ public interface AbstractGameEventListener extends IGameEventListener { default void onChunkEvent(ChunkEvent event) {} @Override - default void onRenderPass() {} + default void onRenderPass(RenderEvent event) {} @Override default void onWorldEvent(WorldEvent event) {} diff --git a/src/main/java/baritone/bot/event/IGameEventListener.java b/src/main/java/baritone/bot/event/IGameEventListener.java index 10066b19..da31b9a8 100755 --- a/src/main/java/baritone/bot/event/IGameEventListener.java +++ b/src/main/java/baritone/bot/event/IGameEventListener.java @@ -2,11 +2,13 @@ package baritone.bot.event; import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.ChunkEvent; +import baritone.bot.event.events.RenderEvent; import baritone.bot.event.events.WorldEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.settings.GameSettings; /** * @author Brady @@ -50,11 +52,13 @@ public interface IGameEventListener { void onChunkEvent(ChunkEvent event); /** - * Runs once each frame + * Runs once per world render pass. Two passes are made when {@link GameSettings#anaglyph} is on. + *

+ * Note: {@link GameSettings#anaglyph} has been removed in Minecraft 1.13 * * @see EntityRenderer#renderWorldPass(int, float, long) */ - void onRenderPass(); + void onRenderPass(RenderEvent event); /** * Runs before and after whenever a new world is loaded diff --git a/src/main/java/baritone/bot/event/events/RenderEvent.java b/src/main/java/baritone/bot/event/events/RenderEvent.java new file mode 100644 index 00000000..e1da4e87 --- /dev/null +++ b/src/main/java/baritone/bot/event/events/RenderEvent.java @@ -0,0 +1,24 @@ +package baritone.bot.event.events; + +/** + * @author Brady + * @since 8/5/2018 12:28 AM + */ +public final class RenderEvent { + + /** + * The current render partial ticks + */ + private final float partialTicks; + + public RenderEvent(float partialTicks) { + this.partialTicks = partialTicks; + } + + /** + * @return The current render partial ticks + */ + public final float getPartialTicks() { + return this.partialTicks; + } +} diff --git a/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java b/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java index ec3fd88b..2bc24970 100644 --- a/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java +++ b/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java @@ -1,6 +1,7 @@ package baritone.launch.mixins; import baritone.bot.Baritone; +import baritone.bot.event.events.RenderEvent; import net.minecraft.client.renderer.EntityRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -18,7 +19,7 @@ public class MixinEntityRenderer { args = { "ldc=hand" } ) ) - private void renderWorldPass(CallbackInfo ci) { - Baritone.INSTANCE.getGameEventHandler().onRenderPass(); + private void renderWorldPass(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + Baritone.INSTANCE.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks)); } }