From 68874751daa799300fb2b674babc067fb52e7c1b Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Sun, 5 Aug 2018 19:23:51 -0400 Subject: [PATCH 1/8] Remove misleading LookBehaviorUtil method --- src/main/java/baritone/bot/behavior/impl/LookBehavior.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/baritone/bot/behavior/impl/LookBehavior.java b/src/main/java/baritone/bot/behavior/impl/LookBehavior.java index 175d01d5..89733c95 100644 --- a/src/main/java/baritone/bot/behavior/impl/LookBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/LookBehavior.java @@ -23,11 +23,6 @@ public class LookBehavior extends Behavior { */ private Optional> target = Optional.empty(); - public void updateTarget(BlockPos blockPos) { - Utils.calcRotationFromVec3d(player().getPositionEyes(1.0F), - Utils.calcCenterFromCoords(blockPos, world())); - } - public void updateTarget(Tuple target) { this.target = Optional.of(target); } From 956e212e395d3b753068fa7474e9821ac30f7c31 Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Sun, 5 Aug 2018 19:26:31 -0400 Subject: [PATCH 2/8] Change LookBehavior target initialization location --- src/main/java/baritone/bot/behavior/impl/LookBehavior.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/bot/behavior/impl/LookBehavior.java b/src/main/java/baritone/bot/behavior/impl/LookBehavior.java index 89733c95..ec0c97b8 100644 --- a/src/main/java/baritone/bot/behavior/impl/LookBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/LookBehavior.java @@ -12,7 +12,7 @@ public class LookBehavior extends Behavior { public static final LookBehavior INSTANCE = new LookBehavior(); public LookBehavior() { - + target = Optional.empty(); } /** @@ -21,7 +21,7 @@ public class LookBehavior extends Behavior { * getFirst() -> yaw * getSecond() -> pitch */ - private Optional> target = Optional.empty(); + private Optional> target; public void updateTarget(Tuple target) { this.target = Optional.of(target); From 19e5784af966b87db2f1ce517056a0a433187e45 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 5 Aug 2018 18:40:10 -0500 Subject: [PATCH 3/8] Fix typo lol --- src/main/java/baritone/bot/event/AbstractGameEventListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/bot/event/AbstractGameEventListener.java b/src/main/java/baritone/bot/event/AbstractGameEventListener.java index 7b7b0d30..bb52fcaf 100644 --- a/src/main/java/baritone/bot/event/AbstractGameEventListener.java +++ b/src/main/java/baritone/bot/event/AbstractGameEventListener.java @@ -7,7 +7,7 @@ import baritone.bot.event.events.WorldEvent; /** * An implementation of {@link IGameEventListener} that has all methods - * overriden with empty bodies, allowing inheritors of this class to choose + * overridden with empty bodies, allowing inheritors of this class to choose * which events they would like to listen in on. * * Has no implementors at the moment, but will likely be used with the From 89189c532eba947cf3a74df713633f7eb57774d6 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 5 Aug 2018 18:41:57 -0500 Subject: [PATCH 4/8] Make Helper#world return WorldClient instead of World --- src/main/java/baritone/bot/utils/Helper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/baritone/bot/utils/Helper.java b/src/main/java/baritone/bot/utils/Helper.java index 516c7955..17638b1b 100755 --- a/src/main/java/baritone/bot/utils/Helper.java +++ b/src/main/java/baritone/bot/utils/Helper.java @@ -4,7 +4,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; /** * @author Brady @@ -18,7 +17,7 @@ public interface Helper { return mc.player; } - default World world() { + default WorldClient world() { return mc.world; } From 379d35840893ee19d9bc4be28427a093056bc0bb Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Sun, 5 Aug 2018 19:50:24 -0400 Subject: [PATCH 5/8] Add EventTick w/ state guarantees --- .../java/baritone/bot/GameEventHandler.java | 9 ++---- .../bot/behavior/impl/LookBehavior.java | 2 -- .../bot/behavior/impl/PathingBehavior.java | 3 +- .../bot/event/AbstractGameEventListener.java | 7 ++--- .../bot/event/IGameEventListener.java | 7 ++--- .../baritone/bot/event/events/TickEvent.java | 29 +++++++++++++++++++ .../bot/pathing/path/PathExecutor.java | 4 ++- .../launch/mixins/MixinMinecraft.java | 9 +++++- 8 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 src/main/java/baritone/bot/event/events/TickEvent.java diff --git a/src/main/java/baritone/bot/GameEventHandler.java b/src/main/java/baritone/bot/GameEventHandler.java index b3570110..9ecd8803 100755 --- a/src/main/java/baritone/bot/GameEventHandler.java +++ b/src/main/java/baritone/bot/GameEventHandler.java @@ -2,10 +2,7 @@ package baritone.bot; 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 baritone.bot.event.events.*; import net.minecraft.client.settings.KeyBinding; import org.lwjgl.input.Keyboard; @@ -20,8 +17,8 @@ public final class GameEventHandler implements IGameEventListener { GameEventHandler() {} @Override - public final void onTick() { - dispatch(Behavior::onTick); + public final void onTick(TickEvent event) { + dispatch(behavior -> behavior.onTick(event)); } @Override diff --git a/src/main/java/baritone/bot/behavior/impl/LookBehavior.java b/src/main/java/baritone/bot/behavior/impl/LookBehavior.java index ec0c97b8..e1897e92 100644 --- a/src/main/java/baritone/bot/behavior/impl/LookBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/LookBehavior.java @@ -1,9 +1,7 @@ package baritone.bot.behavior.impl; import baritone.bot.behavior.Behavior; -import baritone.bot.utils.Utils; import net.minecraft.util.Tuple; -import net.minecraft.util.math.BlockPos; import java.util.Optional; diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index fe7cbe9c..cbc51a7c 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -3,6 +3,7 @@ package baritone.bot.behavior.impl; import baritone.bot.behavior.Behavior; import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.RenderEvent; +import baritone.bot.event.events.TickEvent; import baritone.bot.pathing.calc.AStarPathFinder; import baritone.bot.pathing.calc.IPathFinder; import baritone.bot.pathing.goals.Goal; @@ -34,7 +35,7 @@ public class PathingBehavior extends Behavior { private Goal goal; @Override - public void onTick() { + public void onTick(TickEvent event) { //System.out.println("Ticking"); if (current == null) { return; diff --git a/src/main/java/baritone/bot/event/AbstractGameEventListener.java b/src/main/java/baritone/bot/event/AbstractGameEventListener.java index bb52fcaf..df23110f 100644 --- a/src/main/java/baritone/bot/event/AbstractGameEventListener.java +++ b/src/main/java/baritone/bot/event/AbstractGameEventListener.java @@ -1,9 +1,6 @@ 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 baritone.bot.event.events.*; /** * An implementation of {@link IGameEventListener} that has all methods @@ -21,7 +18,7 @@ import baritone.bot.event.events.WorldEvent; public interface AbstractGameEventListener extends IGameEventListener { @Override - default void onTick() {} + default void onTick(TickEvent event) {} @Override default void onPlayerUpdate() {} diff --git a/src/main/java/baritone/bot/event/IGameEventListener.java b/src/main/java/baritone/bot/event/IGameEventListener.java index da31b9a8..6a381beb 100755 --- a/src/main/java/baritone/bot/event/IGameEventListener.java +++ b/src/main/java/baritone/bot/event/IGameEventListener.java @@ -1,9 +1,6 @@ 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 baritone.bot.event.events.*; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; @@ -21,7 +18,7 @@ public interface IGameEventListener { * * @see Minecraft#runTick() */ - void onTick(); + void onTick(TickEvent event); /** * Run once per game tick from before the player rotation is sent to the server. diff --git a/src/main/java/baritone/bot/event/events/TickEvent.java b/src/main/java/baritone/bot/event/events/TickEvent.java new file mode 100644 index 00000000..4e6790ba --- /dev/null +++ b/src/main/java/baritone/bot/event/events/TickEvent.java @@ -0,0 +1,29 @@ +package baritone.bot.event.events; + +import baritone.bot.event.events.type.EventState; +import javafx.event.EventType; + +public final class TickEvent { + + private final EventState state; + private final Type type; + + public TickEvent(EventState state, Type type) { + this.state = state; + this.type = type; + } + + + public enum Type { + /** + * When guarantees can be made about + * the game state and in-game variables. + */ + IN, + /** + * No guarantees can be made about the game state. + * This probably means we are at the main menu. + */ + OUT, + } +} diff --git a/src/main/java/baritone/bot/pathing/path/PathExecutor.java b/src/main/java/baritone/bot/pathing/path/PathExecutor.java index 1184ef3b..9ef967de 100644 --- a/src/main/java/baritone/bot/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/bot/pathing/path/PathExecutor.java @@ -1,6 +1,7 @@ package baritone.bot.pathing.path; import baritone.bot.behavior.Behavior; +import baritone.bot.event.events.TickEvent; import baritone.bot.pathing.movement.ActionCosts; import baritone.bot.pathing.movement.Movement; import baritone.bot.pathing.movement.MovementState; @@ -33,7 +34,8 @@ public class PathExecutor extends Behavior { this.pathPosition = 0; } - public void onTick() { + @Override + public void onTick(TickEvent event) { if (pathPosition >= path.length()) { //stop bugging me, I'm done //TODO Baritone.INSTANCE.behaviors.remove(this) diff --git a/src/main/java/baritone/launch/mixins/MixinMinecraft.java b/src/main/java/baritone/launch/mixins/MixinMinecraft.java index 4dbc40bf..4fd13314 100755 --- a/src/main/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/main/java/baritone/launch/mixins/MixinMinecraft.java @@ -1,6 +1,7 @@ package baritone.launch.mixins; import baritone.bot.Baritone; +import baritone.bot.event.events.TickEvent; import baritone.bot.event.events.WorldEvent; import baritone.bot.event.events.type.EventState; import net.minecraft.client.Minecraft; @@ -47,7 +48,13 @@ public class MixinMinecraft { ) ) private void runTick(CallbackInfo ci) { - Baritone.INSTANCE.getGameEventHandler().onTick(); + Minecraft mc = (Minecraft) (Object) this; + Baritone.INSTANCE.getGameEventHandler().onTick(new TickEvent( + EventState.PRE, + (mc.player != null && mc.world != null) + ? TickEvent.Type.IN + : TickEvent.Type.OUT + )); } @Redirect( From 8ef9f9db701e29c8836688c8c593f39ed73449f1 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 5 Aug 2018 18:56:21 -0500 Subject: [PATCH 6/8] Minor clean ups in PathingBehavior --- .../bot/behavior/impl/PathingBehavior.java | 69 ++++++++----------- src/main/java/baritone/bot/utils/Helper.java | 4 ++ 2 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index cbc51a7c..9261c05e 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -3,7 +3,6 @@ package baritone.bot.behavior.impl; import baritone.bot.behavior.Behavior; import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.RenderEvent; -import baritone.bot.event.events.TickEvent; import baritone.bot.pathing.calc.AStarPathFinder; import baritone.bot.pathing.calc.IPathFinder; import baritone.bot.pathing.goals.Goal; @@ -35,12 +34,12 @@ public class PathingBehavior extends Behavior { private Goal goal; @Override - public void onTick(TickEvent event) { - //System.out.println("Ticking"); + public void onTick() { + // System.out.println("Ticking"); if (current == null) { return; } - //current.onTick(); + // current.onTick(); if (current.failed() || current.finished()) { current = null; } @@ -57,16 +56,12 @@ public class PathingBehavior extends Behavior { return current.getPath(); } - private static void chatRaw(String s) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(s)); - } - @Override public void onSendChatMessage(ChatEvent event) { String msg = event.getMessage(); if (msg.equals("goal")) { goal = new GoalBlock(playerFeet()); - chatRaw("Goal: " + goal); + displayChatMessageRaw("Goal: " + goal); event.cancel(); return; } @@ -85,33 +80,27 @@ public class PathingBehavior extends Behavior { * @param talkAboutIt */ public void findPathInNewThread(final BlockPos start, final boolean talkAboutIt) { - - new Thread() { - @Override - public void run() { - if (talkAboutIt) { - - chatRaw("Starting to search for path from " + start + " to " + goal); - } - - try { - IPath path = findPath(start); - if (path != null) { - current = new PathExecutor(path); - } - } catch (Exception e) { - } - /*isThereAnythingInProgress = false; - if (!currentPath.goal.isInGoal(currentPath.end)) { - if (talkAboutIt) { - Out.gui("I couldn't get all the way to " + goal + ", but I'm going to get as close as I can. " + currentPath.numNodes + " nodes considered", Out.Mode.Standard); - } - planAhead(); - } else if (talkAboutIt) { - Out.gui("Finished finding a path from " + start + " to " + goal + ". " + currentPath.numNodes + " nodes considered", Out.Mode.Debug); - }*/ + new Thread(() -> { + if (talkAboutIt) { + displayChatMessageRaw("Starting to search for path from " + start + " to " + goal); } - }.start(); + + try { + IPath path = findPath(start); + if (path != null) { + current = new PathExecutor(path); + } + } catch (Exception ignored) {} + /*isThereAnythingInProgress = false; + if (!currentPath.goal.isInGoal(currentPath.end)) { + if (talkAboutIt) { + Out.gui("I couldn't get all the way to " + goal + ", but I'm going to get as close as I can. " + currentPath.numNodes + " nodes considered", Out.Mode.Standard); + } + planAhead(); + } else if (talkAboutIt) { + Out.gui("Finished finding a path from " + start + " to " + goal + ". " + currentPath.numNodes + " nodes considered", Out.Mode.Debug); + }*/ + }).start(); } /** @@ -122,7 +111,7 @@ public class PathingBehavior extends Behavior { */ private IPath findPath(BlockPos start) { if (goal == null) { - chatRaw("no goal"); + displayChatMessageRaw("no goal"); return null; } try { @@ -137,8 +126,8 @@ public class PathingBehavior extends Behavior { @Override public void onRenderPass(RenderEvent event) { - //System.out.println("Render passing"); - //System.out.println(event.getPartialTicks()); + // System.out.println("Render passing"); + // System.out.println(event.getPartialTicks()); drawPath(player(), event.getPartialTicks(), Color.RED); } @@ -167,7 +156,7 @@ public class PathingBehavior extends Behavior { } } - //GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f); + // GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f); GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); @@ -187,6 +176,4 @@ public class PathingBehavior extends Behavior { worldrenderer.pos(bp1x + 0.5D - d0, bp1y + 0.5D - d1, bp1z + 0.5D - d2).endVertex(); tessellator.draw(); } - - } diff --git a/src/main/java/baritone/bot/utils/Helper.java b/src/main/java/baritone/bot/utils/Helper.java index 17638b1b..e3d002f7 100755 --- a/src/main/java/baritone/bot/utils/Helper.java +++ b/src/main/java/baritone/bot/utils/Helper.java @@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextComponentString; /** * @author Brady @@ -25,4 +26,7 @@ public interface Helper { return new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ); } + default void displayChatMessageRaw(String message) { + mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(message)); + } } From cc0cd7b2706fa42d820fbaaf477b44280cdea838 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 5 Aug 2018 18:57:50 -0500 Subject: [PATCH 7/8] Fix onTick signature in PathingBehavior --- src/main/java/baritone/bot/behavior/impl/PathingBehavior.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index 9261c05e..62af0b80 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -3,6 +3,7 @@ package baritone.bot.behavior.impl; import baritone.bot.behavior.Behavior; import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.RenderEvent; +import baritone.bot.event.events.TickEvent; import baritone.bot.pathing.calc.AStarPathFinder; import baritone.bot.pathing.calc.IPathFinder; import baritone.bot.pathing.goals.Goal; @@ -34,7 +35,7 @@ public class PathingBehavior extends Behavior { private Goal goal; @Override - public void onTick() { + public void onTick(TickEvent event) { // System.out.println("Ticking"); if (current == null) { return; From 9e9ad16686c67b83ac54cee98f8e14b379b45a14 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 5 Aug 2018 19:00:45 -0500 Subject: [PATCH 8/8] Fix another typo --- src/main/java/baritone/bot/behavior/Behavior.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/bot/behavior/Behavior.java b/src/main/java/baritone/bot/behavior/Behavior.java index e61f5850..8fcdbf51 100644 --- a/src/main/java/baritone/bot/behavior/Behavior.java +++ b/src/main/java/baritone/bot/behavior/Behavior.java @@ -47,7 +47,7 @@ public class Behavior implements AbstractGameEventListener, Helper { /** * Function to determine what the new enabled state of this * {@link Behavior} should be given the old state, and the - * proposed state. Intended to be overriden by behaviors + * proposed state. Intended to be overridden by behaviors * that should always be active, given that the bot itself is * active. *