From 660efe5e16c769ac73cc1a20c5d8941da6de9b2e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 3 Nov 2018 22:11:52 -0700 Subject: [PATCH 01/29] pathing processes wip --- src/api/java/baritone/api/BaritoneAPI.java | 18 ++- src/api/java/baritone/api/IBaritone.java | 81 ++++++++++++ .../java/baritone/api/IBaritoneProvider.java | 66 +-------- .../java/baritone/api/behavior/IBehavior.java | 3 +- .../api/behavior/IPathingBehavior.java | 21 +-- .../api/pathing/goals/GoalRunAway.java | 23 +++- .../api/process/IBaritoneProcess.java | 47 +++++++ .../api/process/ICustomGoalProcess.java | 31 +++++ .../IFollowProcess.java} | 9 +- .../api/process/IGetToBlockProcess.java | 27 ++++ .../IMineProcess.java} | 20 +-- .../baritone/api/process/PathingCommand.java | 30 +++++ .../api/process/PathingCommandType.java | 27 ++++ .../api/utils/interfaces/Toggleable.java | 54 -------- .../launch/mixins/MixinEntityPlayerSP.java | 2 +- .../launch/mixins/MixinMinecraft.java | 2 +- src/main/java/baritone/Baritone.java | 48 +++++-- src/main/java/baritone/BaritoneProvider.java | 50 +------ src/main/java/baritone/behavior/Behavior.java | 41 ------ .../baritone/behavior/PathingBehavior.java | 30 +---- .../java/baritone/event/GameEventHandler.java | 82 ++---------- .../baritone/process/CustomGoalProcess.java | 65 +++++++++ .../FollowProcess.java} | 42 +++--- .../baritone/process/GetToBlockProcess.java | 82 ++++++++++++ .../MineProcess.java} | 98 +++++++------- .../baritone/utils/BaritoneProcessHelper.java | 53 ++++++++ .../utils/ExampleBaritoneControl.java | 22 ++- .../baritone/utils/PathingControlManager.java | 125 ++++++++++++++++++ 28 files changed, 760 insertions(+), 439 deletions(-) create mode 100644 src/api/java/baritone/api/IBaritone.java create mode 100644 src/api/java/baritone/api/process/IBaritoneProcess.java create mode 100644 src/api/java/baritone/api/process/ICustomGoalProcess.java rename src/api/java/baritone/api/{behavior/IFollowBehavior.java => process/IFollowProcess.java} (85%) create mode 100644 src/api/java/baritone/api/process/IGetToBlockProcess.java rename src/api/java/baritone/api/{behavior/IMineBehavior.java => process/IMineProcess.java} (81%) create mode 100644 src/api/java/baritone/api/process/PathingCommand.java create mode 100644 src/api/java/baritone/api/process/PathingCommandType.java delete mode 100644 src/api/java/baritone/api/utils/interfaces/Toggleable.java create mode 100644 src/main/java/baritone/process/CustomGoalProcess.java rename src/main/java/baritone/{behavior/FollowBehavior.java => process/FollowProcess.java} (66%) create mode 100644 src/main/java/baritone/process/GetToBlockProcess.java rename src/main/java/baritone/{behavior/MineBehavior.java => process/MineProcess.java} (78%) create mode 100644 src/main/java/baritone/utils/BaritoneProcessHelper.java create mode 100644 src/main/java/baritone/utils/PathingControlManager.java diff --git a/src/api/java/baritone/api/BaritoneAPI.java b/src/api/java/baritone/api/BaritoneAPI.java index 0ffd1e98..bf878d33 100644 --- a/src/api/java/baritone/api/BaritoneAPI.java +++ b/src/api/java/baritone/api/BaritoneAPI.java @@ -17,10 +17,14 @@ package baritone.api; -import baritone.api.behavior.*; +import baritone.api.behavior.ILookBehavior; +import baritone.api.behavior.IMemoryBehavior; +import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IWorldProvider; import baritone.api.cache.IWorldScanner; import baritone.api.event.listener.IGameEventListener; +import baritone.api.process.IFollowProcess; +import baritone.api.process.IMineProcess; import baritone.api.utils.SettingsUtil; import java.util.Iterator; @@ -36,20 +40,20 @@ import java.util.ServiceLoader; */ public final class BaritoneAPI { - private static final IBaritoneProvider baritone; + private static final IBaritone baritone; private static final Settings settings; static { ServiceLoader baritoneLoader = ServiceLoader.load(IBaritoneProvider.class); Iterator instances = baritoneLoader.iterator(); - baritone = instances.next(); + baritone = instances.next().getBaritoneForPlayer(null); // PWNAGE settings = new Settings(); SettingsUtil.readAndApply(settings); } - public static IFollowBehavior getFollowBehavior() { - return baritone.getFollowBehavior(); + public static IFollowProcess getFollowProcess() { + return baritone.getFollowProcess(); } public static ILookBehavior getLookBehavior() { @@ -60,8 +64,8 @@ public final class BaritoneAPI { return baritone.getMemoryBehavior(); } - public static IMineBehavior getMineBehavior() { - return baritone.getMineBehavior(); + public static IMineProcess getMineProcess() { + return baritone.getMineProcess(); } public static IPathingBehavior getPathingBehavior() { diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java new file mode 100644 index 00000000..2d1982cd --- /dev/null +++ b/src/api/java/baritone/api/IBaritone.java @@ -0,0 +1,81 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api; + +import baritone.api.behavior.*; +import baritone.api.cache.IWorldProvider; +import baritone.api.cache.IWorldScanner; +import baritone.api.event.listener.IGameEventListener; +import baritone.api.process.IFollowProcess; +import baritone.api.process.IMineProcess; + +/** + * @author Brady + * @since 9/29/2018 + */ +public interface IBaritone { + + /** + * @return The {@link IFollowProcess} instance + * @see IFollowProcess + */ + IFollowProcess getFollowProcess(); + + /** + * @return The {@link ILookBehavior} instance + * @see ILookBehavior + */ + ILookBehavior getLookBehavior(); + + /** + * @return The {@link IMemoryBehavior} instance + * @see IMemoryBehavior + */ + IMemoryBehavior getMemoryBehavior(); + + /** + * @return The {@link IMineProcess} instance + * @see IMineProcess + */ + IMineProcess getMineProcess(); + + /** + * @return The {@link IPathingBehavior} instance + * @see IPathingBehavior + */ + IPathingBehavior getPathingBehavior(); + + /** + * @return The {@link IWorldProvider} instance + * @see IWorldProvider + */ + IWorldProvider getWorldProvider(); + + /** + * @return The {@link IWorldScanner} instance + * @see IWorldScanner + */ + IWorldScanner getWorldScanner(); + + /** + * Registers a {@link IGameEventListener} with Baritone's "event bus". + * + * @param listener The listener + */ + void registerEventListener(IGameEventListener listener); +} diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index 88c4adff..9bd96e7e 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -17,70 +17,8 @@ package baritone.api; -import baritone.api.behavior.*; -import baritone.api.cache.IWorldProvider; -import baritone.api.cache.IWorldScanner; -import baritone.api.event.listener.IGameEventListener; +import net.minecraft.client.entity.EntityPlayerSP; -/** - * @author Brady - * @since 9/29/2018 - */ public interface IBaritoneProvider { - - /** - * @see IFollowBehavior - * - * @return The {@link IFollowBehavior} instance - */ - IFollowBehavior getFollowBehavior(); - - /** - * @see ILookBehavior - * - * @return The {@link ILookBehavior} instance - */ - ILookBehavior getLookBehavior(); - - /** - * @see IMemoryBehavior - * - * @return The {@link IMemoryBehavior} instance - */ - IMemoryBehavior getMemoryBehavior(); - - /** - * @see IMineBehavior - * - * @return The {@link IMineBehavior} instance - */ - IMineBehavior getMineBehavior(); - - /** - * @see IPathingBehavior - * - * @return The {@link IPathingBehavior} instance - */ - IPathingBehavior getPathingBehavior(); - - /** - * @see IWorldProvider - * - * @return The {@link IWorldProvider} instance - */ - IWorldProvider getWorldProvider(); - - /** - * @see IWorldScanner - * - * @return The {@link IWorldScanner} instance - */ - IWorldScanner getWorldScanner(); - - /** - * Registers a {@link IGameEventListener} with Baritone's "event bus". - * - * @param listener The listener - */ - void registerEventListener(IGameEventListener listener); + IBaritone getBaritoneForPlayer(EntityPlayerSP player); // tenor be like } diff --git a/src/api/java/baritone/api/behavior/IBehavior.java b/src/api/java/baritone/api/behavior/IBehavior.java index aee144e2..248148e7 100644 --- a/src/api/java/baritone/api/behavior/IBehavior.java +++ b/src/api/java/baritone/api/behavior/IBehavior.java @@ -18,10 +18,9 @@ package baritone.api.behavior; import baritone.api.event.listener.AbstractGameEventListener; -import baritone.api.utils.interfaces.Toggleable; /** * @author Brady * @since 9/23/2018 */ -public interface IBehavior extends AbstractGameEventListener, Toggleable {} +public interface IBehavior extends AbstractGameEventListener {} diff --git a/src/api/java/baritone/api/behavior/IPathingBehavior.java b/src/api/java/baritone/api/behavior/IPathingBehavior.java index 7d88ae59..ced3d861 100644 --- a/src/api/java/baritone/api/behavior/IPathingBehavior.java +++ b/src/api/java/baritone/api/behavior/IPathingBehavior.java @@ -39,35 +39,22 @@ public interface IPathingBehavior extends IBehavior { */ Optional ticksRemainingInSegment(); - /** - * Sets the pathing goal. - * - * @param goal The pathing goal - */ - void setGoal(Goal goal); - /** * @return The current pathing goal */ Goal getGoal(); - /** - * Begins pathing. Calculation will start in a new thread, and once completed, - * movement will commence. Returns whether or not the operation was successful. - * - * @return Whether or not the operation was successful - */ - boolean path(); - /** * @return Whether or not a path is currently being executed. */ boolean isPathing(); /** - * Cancels the pathing behavior or the current path calculation. + * Cancels the pathing behavior or the current path calculation. Also cancels all processes that could be controlling path. + *

+ * Basically, "MAKE IT STOP". */ - void cancel(); + void cancelEverything(); /** * Returns the current path, from the current path executor, if there is one. diff --git a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java index cb7a000e..d01f6eee 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java +++ b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java @@ -20,6 +20,7 @@ package baritone.api.pathing.goals; import net.minecraft.util.math.BlockPos; import java.util.Arrays; +import java.util.Optional; /** * Useful for automated combat (retreating specifically) @@ -32,16 +33,26 @@ public class GoalRunAway implements Goal { private final double distanceSq; + private final Optional maintainY; + public GoalRunAway(double distance, BlockPos... from) { + this(distance, Optional.empty(), from); + } + + public GoalRunAway(double distance, Optional maintainY, BlockPos... from) { if (from.length == 0) { throw new IllegalArgumentException(); } this.from = from; this.distanceSq = distance * distance; + this.maintainY = maintainY; } @Override public boolean isInGoal(int x, int y, int z) { + if (maintainY.isPresent() && maintainY.get() != y) { + return false; + } for (BlockPos p : from) { int diffX = x - p.getX(); int diffZ = z - p.getZ(); @@ -62,11 +73,19 @@ public class GoalRunAway implements Goal { min = h; } } - return -min; + min = -min; + if (maintainY.isPresent()) { + min += GoalYLevel.calculate(maintainY.get(), y); + } + return min; } @Override public String toString() { - return "GoalRunAwayFrom" + Arrays.asList(from); + if (maintainY.isPresent()) { + return "GoalRunAwayFromMaintainY y=" + maintainY.get() + ", " + Arrays.asList(from); + } else { + return "GoalRunAwayFrom" + Arrays.asList(from); + } } } diff --git a/src/api/java/baritone/api/process/IBaritoneProcess.java b/src/api/java/baritone/api/process/IBaritoneProcess.java new file mode 100644 index 00000000..6405be94 --- /dev/null +++ b/src/api/java/baritone/api/process/IBaritoneProcess.java @@ -0,0 +1,47 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.process; + +import baritone.api.IBaritone; + +/** + * A process that can control the PathingBehavior. + *

+ * Differences between a baritone process and a behavior: + * Only one baritone process can be active at a time + * PathingBehavior can only be controlled by a process + *

+ * That's it actually + * + * @author leijurv + */ +public interface IBaritoneProcess { + // javadocs small brain, // comment large brain + + boolean isActive(); // would you like to be in control? + + PathingCommand onTick(); // you're in control, what should baritone do? + + boolean isTemporary(); // CombatPauserProcess should return isTemporary true always, and isActive true only when something is in range + + void onLostControl(); // called if isActive returned true, but another non-temporary process has control. effectively the same as cancel. + + double priority(); // tenor be like + + IBaritone associatedWith(); // which bot is this associated with (5000000iq forward thinking) +} diff --git a/src/api/java/baritone/api/process/ICustomGoalProcess.java b/src/api/java/baritone/api/process/ICustomGoalProcess.java new file mode 100644 index 00000000..c3492df9 --- /dev/null +++ b/src/api/java/baritone/api/process/ICustomGoalProcess.java @@ -0,0 +1,31 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.process; + +import baritone.api.pathing.goals.Goal; + +public interface ICustomGoalProcess extends IBaritoneProcess { + void setGoal(Goal goal); + + void path(); + + default void setGoalAndPath(Goal goal) { + setGoal(goal); + path(); + } +} diff --git a/src/api/java/baritone/api/behavior/IFollowBehavior.java b/src/api/java/baritone/api/process/IFollowProcess.java similarity index 85% rename from src/api/java/baritone/api/behavior/IFollowBehavior.java rename to src/api/java/baritone/api/process/IFollowProcess.java index c960fab3..262ce43f 100644 --- a/src/api/java/baritone/api/behavior/IFollowBehavior.java +++ b/src/api/java/baritone/api/process/IFollowProcess.java @@ -15,15 +15,16 @@ * along with Baritone. If not, see . */ -package baritone.api.behavior; +package baritone.api.process; +import baritone.api.process.IBaritoneProcess; import net.minecraft.entity.Entity; /** * @author Brady * @since 9/23/2018 */ -public interface IFollowBehavior extends IBehavior { +public interface IFollowProcess extends IBaritoneProcess { /** * Set the follow target to the specified entity; @@ -40,5 +41,7 @@ public interface IFollowBehavior extends IBehavior { /** * Cancels the follow behavior, this will clear the current follow target. */ - void cancel(); + default void cancel() { + onLostControl(); + } } diff --git a/src/api/java/baritone/api/process/IGetToBlockProcess.java b/src/api/java/baritone/api/process/IGetToBlockProcess.java new file mode 100644 index 00000000..feaeb747 --- /dev/null +++ b/src/api/java/baritone/api/process/IGetToBlockProcess.java @@ -0,0 +1,27 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.process; + +import net.minecraft.block.Block; + +/** + * but it rescans the world every once in a while so it doesn't get fooled by its cache + */ +public interface IGetToBlockProcess extends IBaritoneProcess { + void getToBlock(Block block); +} diff --git a/src/api/java/baritone/api/behavior/IMineBehavior.java b/src/api/java/baritone/api/process/IMineProcess.java similarity index 81% rename from src/api/java/baritone/api/behavior/IMineBehavior.java rename to src/api/java/baritone/api/process/IMineProcess.java index 78ab6d6a..7ebabc9c 100644 --- a/src/api/java/baritone/api/behavior/IMineBehavior.java +++ b/src/api/java/baritone/api/process/IMineProcess.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.behavior; +package baritone.api.process; import net.minecraft.block.Block; @@ -23,7 +23,7 @@ import net.minecraft.block.Block; * @author Brady * @since 9/23/2018 */ -public interface IMineBehavior extends IBehavior { +public interface IMineProcess extends IBaritoneProcess { /** * Begin to search for and mine the specified blocks until @@ -31,9 +31,9 @@ public interface IMineBehavior extends IBehavior { * are mined. This is based on the first target block to mine. * * @param quantity The number of items to get from blocks mined - * @param blocks The blocks to mine + * @param blocks The blocks to mine */ - void mine(int quantity, String... blocks); + void mineByName(int quantity, String... blocks); /** * Begin to search for and mine the specified blocks until @@ -41,7 +41,7 @@ public interface IMineBehavior extends IBehavior { * are mined. This is based on the first target block to mine. * * @param quantity The number of items to get from blocks mined - * @param blocks The blocks to mine + * @param blocks The blocks to mine */ void mine(int quantity, Block... blocks); @@ -50,8 +50,8 @@ public interface IMineBehavior extends IBehavior { * * @param blocks The blocks to mine */ - default void mine(String... blocks) { - this.mine(0, blocks); + default void mineByName(String... blocks) { + mineByName(0, blocks); } /** @@ -60,11 +60,13 @@ public interface IMineBehavior extends IBehavior { * @param blocks The blocks to mine */ default void mine(Block... blocks) { - this.mine(0, blocks); + mine(0, blocks); } /** * Cancels the current mining task */ - void cancel(); + default void cancel() { + onLostControl(); + } } diff --git a/src/api/java/baritone/api/process/PathingCommand.java b/src/api/java/baritone/api/process/PathingCommand.java new file mode 100644 index 00000000..f5b39501 --- /dev/null +++ b/src/api/java/baritone/api/process/PathingCommand.java @@ -0,0 +1,30 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.process; + +import baritone.api.pathing.goals.Goal; + +public class PathingCommand { + public final Goal goal; + public final PathingCommandType commandType; + + public PathingCommand(Goal goal, PathingCommandType commandType) { + this.goal = goal; + this.commandType = commandType; + } +} diff --git a/src/api/java/baritone/api/process/PathingCommandType.java b/src/api/java/baritone/api/process/PathingCommandType.java new file mode 100644 index 00000000..24eaf3a8 --- /dev/null +++ b/src/api/java/baritone/api/process/PathingCommandType.java @@ -0,0 +1,27 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.process; + +public enum PathingCommandType { + SET_GOAL_AND_PATH, // if you do this one with a null goal it should continue + REQUEST_PAUSE, + + // if you do this one with a null goal it should cancel + REVALIDATE_GOAL_AND_PATH, // idkkkkkkk + FORCE_REVALIDATE_GOAL_AND_PATH // idkkkkkkkkkkkkkkkkkkkkkkkk +} diff --git a/src/api/java/baritone/api/utils/interfaces/Toggleable.java b/src/api/java/baritone/api/utils/interfaces/Toggleable.java deleted file mode 100644 index 359d6ee1..00000000 --- a/src/api/java/baritone/api/utils/interfaces/Toggleable.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.utils.interfaces; - -/** - * @author Brady - * @since 8/20/2018 - */ -public interface Toggleable { - - /** - * Toggles the enabled state of this {@link Toggleable}. - * - * @return The new state. - */ - boolean toggle(); - - /** - * Sets the enabled state of this {@link Toggleable}. - * - * @return The new state. - */ - boolean setEnabled(boolean enabled); - - /** - * @return Whether or not this {@link Toggleable} object is enabled - */ - boolean isEnabled(); - - /** - * Called when the state changes from disabled to enabled - */ - default void onEnable() {} - - /** - * Called when the state changes from enabled to disabled - */ - default void onDisable() {} -} diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index dd121ead..a180df5c 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -85,6 +85,6 @@ public class MixinEntityPlayerSP { ) private boolean isAllowFlying(PlayerCapabilities capabilities) { PathingBehavior pathingBehavior = Baritone.INSTANCE.getPathingBehavior(); - return (!pathingBehavior.isEnabled() || !pathingBehavior.isPathing()) && capabilities.allowFlying; + return !pathingBehavior.isPathing() && capabilities.allowFlying; } } diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 30d4109b..b559ae86 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -142,7 +142,7 @@ public class MixinMinecraft { ) ) private boolean isAllowUserInput(GuiScreen screen) { - return (Baritone.INSTANCE.getPathingBehavior().getCurrent() != null && Baritone.INSTANCE.getPathingBehavior().isEnabled() && player != null) || screen.allowUserInput; + return (Baritone.INSTANCE.getPathingBehavior().getCurrent() != null && player != null) || screen.allowUserInput; } @Inject( diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index a0d5ba84..055929f0 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -18,16 +18,25 @@ package baritone; import baritone.api.BaritoneAPI; -import baritone.api.IBaritoneProvider; +import baritone.api.IBaritone; import baritone.api.Settings; import baritone.api.event.listener.IGameEventListener; -import baritone.behavior.*; +import baritone.api.process.IBaritoneProcess; +import baritone.behavior.Behavior; +import baritone.behavior.LookBehavior; +import baritone.behavior.MemoryBehavior; +import baritone.behavior.PathingBehavior; import baritone.cache.WorldProvider; import baritone.cache.WorldScanner; import baritone.event.GameEventHandler; +import baritone.process.CustomGoalProcess; +import baritone.process.FollowProcess; +import baritone.process.GetToBlockProcess; +import baritone.process.MineProcess; import baritone.utils.BaritoneAutoTest; import baritone.utils.ExampleBaritoneControl; import baritone.utils.InputOverrideHandler; +import baritone.utils.PathingControlManager; import net.minecraft.client.Minecraft; import java.io.File; @@ -44,7 +53,7 @@ import java.util.concurrent.TimeUnit; * @author Brady * @since 7/31/2018 10:50 PM */ -public enum Baritone implements IBaritoneProvider { +public enum Baritone implements IBaritone { /** * Singleton instance of this class @@ -66,8 +75,13 @@ public enum Baritone implements IBaritoneProvider { private PathingBehavior pathingBehavior; private LookBehavior lookBehavior; private MemoryBehavior memoryBehavior; - private FollowBehavior followBehavior; - private MineBehavior mineBehavior; + + private FollowProcess followProcess; + private MineProcess mineProcess; + private GetToBlockProcess getToBlockProcess; + private CustomGoalProcess customGoalProcess; + + private PathingControlManager pathingControlManager; /** * Whether or not Baritone is active @@ -89,15 +103,19 @@ public enum Baritone implements IBaritoneProvider { // We might want to change this... this.settings = BaritoneAPI.getSettings(); + this.pathingControlManager = new PathingControlManager(this); + this.behaviors = new ArrayList<>(); { // the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist pathingBehavior = new PathingBehavior(this); lookBehavior = new LookBehavior(this); memoryBehavior = new MemoryBehavior(this); - followBehavior = new FollowBehavior(this); - mineBehavior = new MineBehavior(this); + followProcess = new FollowProcess(this); + mineProcess = new MineProcess(this); new ExampleBaritoneControl(this); + new CustomGoalProcess(this); // very high iq + new GetToBlockProcess(this); } if (BaritoneAutoTest.ENABLE_AUTO_TEST) { registerEventListener(BaritoneAutoTest.INSTANCE); @@ -113,6 +131,10 @@ public enum Baritone implements IBaritoneProvider { this.initialized = true; } + public PathingControlManager getPathingControlManager() { + return pathingControlManager; + } + public boolean isInitialized() { return this.initialized; } @@ -138,9 +160,13 @@ public enum Baritone implements IBaritoneProvider { this.registerEventListener(behavior); } + public void registerProcess(IBaritoneProcess process) { + + } + @Override - public FollowBehavior getFollowBehavior() { - return followBehavior; + public FollowProcess getFollowProcess() { + return followProcess; } @Override @@ -154,8 +180,8 @@ public enum Baritone implements IBaritoneProvider { } @Override - public MineBehavior getMineBehavior() { - return mineBehavior; + public MineProcess getMineProcess() { + return mineProcess; } @Override diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index 2e9b3b30..a80dfe5e 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -17,59 +17,17 @@ package baritone; +import baritone.api.IBaritone; import baritone.api.IBaritoneProvider; -import baritone.api.behavior.*; -import baritone.api.cache.IWorldProvider; -import baritone.api.cache.IWorldScanner; -import baritone.api.event.listener.IGameEventListener; -import baritone.cache.WorldProvider; -import baritone.cache.WorldScanner; +import net.minecraft.client.entity.EntityPlayerSP; /** - * todo fix this cancer - * * @author Brady * @since 9/29/2018 */ public final class BaritoneProvider implements IBaritoneProvider { - @Override - public IFollowBehavior getFollowBehavior() { - return Baritone.INSTANCE.getFollowBehavior(); - } - - @Override - public ILookBehavior getLookBehavior() { - return Baritone.INSTANCE.getLookBehavior(); - } - - @Override - public IMemoryBehavior getMemoryBehavior() { - return Baritone.INSTANCE.getMemoryBehavior(); - } - - @Override - public IMineBehavior getMineBehavior() { - return Baritone.INSTANCE.getMineBehavior(); - } - - @Override - public IPathingBehavior getPathingBehavior() { - return Baritone.INSTANCE.getPathingBehavior(); - } - - @Override - public IWorldProvider getWorldProvider() { - return WorldProvider.INSTANCE; - } - - @Override - public IWorldScanner getWorldScanner() { - return WorldScanner.INSTANCE; - } - - @Override - public void registerEventListener(IGameEventListener listener) { - Baritone.INSTANCE.registerEventListener(listener); + public IBaritone getBaritoneForPlayer(EntityPlayerSP player) { + return Baritone.INSTANCE; // pwnage } } diff --git a/src/main/java/baritone/behavior/Behavior.java b/src/main/java/baritone/behavior/Behavior.java index 713e98f0..154897d1 100644 --- a/src/main/java/baritone/behavior/Behavior.java +++ b/src/main/java/baritone/behavior/Behavior.java @@ -30,49 +30,8 @@ public class Behavior implements IBehavior { public final Baritone baritone; - /** - * Whether or not this behavior is enabled - */ - private boolean enabled = true; - protected Behavior(Baritone baritone) { this.baritone = baritone; baritone.registerBehavior(this); } - - /** - * Toggles the enabled state of this {@link Behavior}. - * - * @return The new state. - */ - @Override - public final boolean toggle() { - return this.setEnabled(!this.isEnabled()); - } - - /** - * Sets the enabled state of this {@link Behavior}. - * - * @return The new state. - */ - @Override - public final boolean setEnabled(boolean enabled) { - if (enabled == this.enabled) { - return this.enabled; - } - if (this.enabled = enabled) { - this.onEnable(); - } else { - this.onDisable(); - } - return this.enabled; - } - - /** - * @return Whether or not this {@link Behavior} is active. - */ - @Override - public final boolean isEnabled() { - return this.enabled; - } } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 7a3a16b7..1cfd98bd 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -191,7 +191,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, return Optional.of(current.getPath().ticksRemainingFrom(current.getPosition())); } - @Override public void setGoal(Goal goal) { this.goal = goal; } @@ -227,6 +226,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } @Override + public void cancelEverything() { + + } + + // just cancel the current path public void cancel() { queuePathEvent(PathEvent.CANCELED); current = null; @@ -245,7 +249,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, * * @return true if this call started path calculation, false if it was already calculating or executing a path */ - @Override public boolean path() { if (goal == null) { return false; @@ -435,31 +438,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } } - public void revalidateGoal() { - if (!Baritone.settings().cancelOnGoalInvalidation.get()) { - return; - } - synchronized (pathPlanLock) { - if (current == null || goal == null) { - return; - } - Goal intended = current.getPath().getGoal(); - BlockPos end = current.getPath().getDest(); - if (intended.isInGoal(end) && !goal.isInGoal(end)) { - // this path used to end in the goal - // but the goal has changed, so there's no reason to continue... - cancel(); - } - } - } - @Override public void onRenderPass(RenderEvent event) { PathRenderer.render(event, this); } - - @Override - public void onDisable() { - Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); - } } diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index 61756e33..e7cd5847 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -21,7 +21,6 @@ import baritone.Baritone; import baritone.api.event.events.*; import baritone.api.event.events.type.EventState; import baritone.api.event.listener.IGameEventListener; -import baritone.api.utils.interfaces.Toggleable; import baritone.cache.WorldProvider; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; @@ -42,20 +41,12 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onTick(TickEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onTick(event); - } - }); + listeners.forEach(l -> l.onTick(event)); } @Override public final void onPlayerUpdate(PlayerUpdateEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onPlayerUpdate(event); - } - }); + listeners.forEach(l -> l.onPlayerUpdate(event)); } @Override @@ -75,20 +66,12 @@ public final class GameEventHandler implements IGameEventListener, Helper { } } - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onProcessKeyBinds(); - } - }); + listeners.forEach(l -> l.onProcessKeyBinds()); } @Override public final void onSendChatMessage(ChatEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onSendChatMessage(event); - } - }); + listeners.forEach(l -> l.onSendChatMessage(event)); } @Override @@ -114,20 +97,12 @@ public final class GameEventHandler implements IGameEventListener, Helper { } - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onChunkEvent(event); - } - }); + listeners.forEach(l -> l.onChunkEvent(event)); } @Override public final void onRenderPass(RenderEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onRenderPass(event); - } - }); + listeners.forEach(l -> l.onRenderPass(event)); } @Override @@ -143,72 +118,41 @@ public final class GameEventHandler implements IGameEventListener, Helper { } } - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onWorldEvent(event); - } - }); + listeners.forEach(l -> l.onWorldEvent(event)); } @Override public final void onSendPacket(PacketEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onSendPacket(event); - } - }); + listeners.forEach(l -> l.onSendPacket(event)); } @Override public final void onReceivePacket(PacketEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onReceivePacket(event); - } - }); + listeners.forEach(l -> l.onReceivePacket(event)); } @Override public void onPlayerRotationMove(RotationMoveEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onPlayerRotationMove(event); - } - }); + listeners.forEach(l -> l.onPlayerRotationMove(event)); } @Override public void onBlockInteract(BlockInteractEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onBlockInteract(event); - } - }); + listeners.forEach(l -> l.onBlockInteract(event)); } @Override public void onPlayerDeath() { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onPlayerDeath(); - } - }); + listeners.forEach(l -> l.onPlayerDeath()); } @Override public void onPathEvent(PathEvent event) { - listeners.forEach(l -> { - if (canDispatch(l)) { - l.onPathEvent(event); - } - }); + listeners.forEach(l -> l.onPathEvent(event)); } public final void registerEventListener(IGameEventListener listener) { this.listeners.add(listener); } - private boolean canDispatch(IGameEventListener listener) { - return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled(); - } } diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java new file mode 100644 index 00000000..08b142ff --- /dev/null +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -0,0 +1,65 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.process; + +import baritone.Baritone; +import baritone.api.pathing.goals.Goal; +import baritone.api.process.ICustomGoalProcess; +import baritone.api.process.PathingCommand; +import baritone.api.process.PathingCommandType; +import baritone.utils.BaritoneProcessHelper; + +/** + * As set by ExampleBaritoneControl or something idk + * + * @author leijurv + */ +public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess { + private Goal goal; + private boolean active; + + public CustomGoalProcess(Baritone baritone) { + super(baritone); + } + + @Override + public void setGoal(Goal goal) { + this.goal = goal; + } + + @Override + public void path() { + active = true; + } + + @Override + public boolean isActive() { + return active; + } + + @Override + public PathingCommand onTick() { + active = false; // only do this once + return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); + } + + @Override + public void onLostControl() { + active = false; + } +} diff --git a/src/main/java/baritone/behavior/FollowBehavior.java b/src/main/java/baritone/process/FollowProcess.java similarity index 66% rename from src/main/java/baritone/behavior/FollowBehavior.java rename to src/main/java/baritone/process/FollowProcess.java index 00fbe1c5..dcfa21a0 100644 --- a/src/main/java/baritone/behavior/FollowBehavior.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -15,14 +15,15 @@ * along with Baritone. If not, see . */ -package baritone.behavior; +package baritone.process; import baritone.Baritone; -import baritone.api.behavior.IFollowBehavior; -import baritone.api.event.events.TickEvent; +import baritone.api.process.IFollowProcess; import baritone.api.pathing.goals.GoalNear; import baritone.api.pathing.goals.GoalXZ; -import baritone.utils.Helper; +import baritone.api.process.PathingCommand; +import baritone.api.process.PathingCommandType; +import baritone.utils.BaritoneProcessHelper; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; @@ -31,23 +32,16 @@ import net.minecraft.util.math.BlockPos; * * @author leijurv */ -public final class FollowBehavior extends Behavior implements IFollowBehavior, Helper { +public final class FollowProcess extends BaritoneProcessHelper implements IFollowProcess { private Entity following; - public FollowBehavior(Baritone baritone) { + public FollowProcess(Baritone baritone) { super(baritone); } @Override - public void onTick(TickEvent event) { - if (event.getType() == TickEvent.Type.OUT) { - following = null; - return; - } - if (following == null) { - return; - } + public PathingCommand onTick() { // lol this is trashy but it works BlockPos pos; if (Baritone.settings().followOffsetDistance.get() == 0) { @@ -56,9 +50,17 @@ public final class FollowBehavior extends Behavior implements IFollowBehavior, H GoalXZ g = GoalXZ.fromDirection(following.getPositionVector(), Baritone.settings().followOffsetDirection.get(), Baritone.settings().followOffsetDistance.get()); pos = new BlockPos(g.getX(), following.posY, g.getZ()); } - baritone.getPathingBehavior().setGoal(new GoalNear(pos, Baritone.settings().followRadius.get())); - ((PathingBehavior) baritone.getPathingBehavior()).revalidateGoal(); - baritone.getPathingBehavior().path(); + return new PathingCommand(new GoalNear(pos, Baritone.settings().followRadius.get()), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH); + } + + @Override + public boolean isActive() { + return following != null; + } + + @Override + public void onLostControl() { + following = null; } @Override @@ -70,10 +72,4 @@ public final class FollowBehavior extends Behavior implements IFollowBehavior, H public Entity following() { return this.following; } - - @Override - public void cancel() { - baritone.getPathingBehavior().cancel(); - follow(null); - } } diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java new file mode 100644 index 00000000..62dac26e --- /dev/null +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -0,0 +1,82 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.process; + +import baritone.Baritone; +import baritone.api.pathing.goals.Goal; +import baritone.api.pathing.goals.GoalComposite; +import baritone.api.pathing.goals.GoalGetToBlock; +import baritone.api.process.IGetToBlockProcess; +import baritone.api.process.PathingCommand; +import baritone.api.process.PathingCommandType; +import baritone.utils.BaritoneProcessHelper; +import net.minecraft.block.Block; +import net.minecraft.util.math.BlockPos; + +import java.util.Collections; +import java.util.List; + +public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess { + Block gettingTo; + List knownLocations; + + int tickCount = 0; + + public GetToBlockProcess(Baritone baritone) { + super(baritone); + } + + @Override + public void getToBlock(Block block) { + gettingTo = block; + rescan(); + } + + @Override + public boolean isActive() { + return gettingTo != null; + } + + @Override + public PathingCommand onTick() { + if (knownLocations == null) { + rescan(); + } + if (knownLocations.isEmpty()) { + logDirect("No known locations of " + gettingTo); + onLostControl(); + return null; + } + int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); + if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain + Baritone.INSTANCE.getExecutor().execute(this::rescan); + } + Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)); + return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); + } + + @Override + public void onLostControl() { + gettingTo = null; + knownLocations = null; + } + + private void rescan() { + knownLocations = MineProcess.searchWorld(Collections.singletonList(gettingTo), 64); + } +} \ No newline at end of file diff --git a/src/main/java/baritone/behavior/MineBehavior.java b/src/main/java/baritone/process/MineProcess.java similarity index 78% rename from src/main/java/baritone/behavior/MineBehavior.java rename to src/main/java/baritone/process/MineProcess.java index 4d37f5ff..a88fd537 100644 --- a/src/main/java/baritone/behavior/MineBehavior.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -15,18 +15,20 @@ * along with Baritone. If not, see . */ -package baritone.behavior; +package baritone.process; import baritone.Baritone; -import baritone.api.behavior.IMineBehavior; -import baritone.api.event.events.TickEvent; import baritone.api.pathing.goals.*; +import baritone.api.process.IMineProcess; +import baritone.api.process.PathingCommand; +import baritone.api.process.PathingCommandType; import baritone.api.utils.RotationUtils; import baritone.cache.CachedChunk; import baritone.cache.ChunkPacker; import baritone.cache.WorldProvider; import baritone.cache.WorldScanner; import baritone.pathing.movement.MovementHelper; +import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import net.minecraft.block.Block; @@ -44,26 +46,27 @@ import java.util.stream.Collectors; * * @author leijurv */ -public final class MineBehavior extends Behavior implements IMineBehavior, Helper { +public final class MineProcess extends BaritoneProcessHelper implements IMineProcess { + + private static final int ORE_LOCATIONS_COUNT = 64; private List mining; private List knownOreLocations; private BlockPos branchPoint; private int desiredQuantity; + private int tickCount; - public MineBehavior(Baritone baritone) { + public MineProcess(Baritone baritone) { super(baritone); } @Override - public void onTick(TickEvent event) { - if (event.getType() == TickEvent.Type.OUT) { - cancel(); - return; - } - if (mining == null) { - return; - } + public boolean isActive() { + return mining != null; + } + + @Override + public PathingCommand onTick() { if (desiredQuantity > 0) { Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), new Random(), 0); int curr = player().inventory.mainInventory.stream().filter(stack -> item.equals(stack.getItem())).mapToInt(ItemStack::getCount).sum(); @@ -71,45 +74,52 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe if (curr >= desiredQuantity) { logDirect("Have " + curr + " " + item.getItemStackDisplayName(new ItemStack(item, 1))); cancel(); - return; + return null; } } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); - if (mineGoalUpdateInterval != 0 && event.getCount() % mineGoalUpdateInterval == 0) { + if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain Baritone.INSTANCE.getExecutor().execute(this::rescan); } if (Baritone.settings().legitMine.get()) { addNearby(); } - updateGoal(); - baritone.getPathingBehavior().revalidateGoal(); + Goal goal = updateGoal(); + if (goal == null) { + // none in range + // maybe say something in chat? (ahem impact) + cancel(); + return null; + } + return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH); } - private void updateGoal() { - if (mining == null) { - return; - } + @Override + public void onLostControl() { + mine(0, (Block[]) null); + } + + private Goal updateGoal() { List locs = knownOreLocations; if (!locs.isEmpty()) { - List locs2 = prune(new ArrayList<>(locs), mining, 64); + List locs2 = prune(new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT); // can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final - baritone.getPathingBehavior().setGoalAndPath(new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new))); + Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new)); knownOreLocations = locs2; - return; + return goal; } // we don't know any ore locations at the moment if (!Baritone.settings().legitMine.get()) { - return; + return null; } // only in non-Xray mode (aka legit mode) do we do this if (branchPoint == null) { int y = Baritone.settings().legitMineYLevel.get(); - if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) { + if (!associatedWith().getPathingBehavior().isPathing() && playerFeet().y == y) { // cool, path is over and we are at desired y branchPoint = playerFeet(); } else { - baritone.getPathingBehavior().setGoalAndPath(new GoalYLevel(y)); - return; + return new GoalYLevel(y); } } @@ -117,7 +127,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe // TODO mine 1x1 shafts to either side branchPoint = branchPoint.north(10); } - baritone.getPathingBehavior().setGoalAndPath(new GoalBlock(branchPoint)); + return new GoalBlock(branchPoint); } private void rescan() { @@ -127,10 +137,10 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe if (Baritone.settings().legitMine.get()) { return; } - List locs = searchWorld(mining, 64); + List locs = searchWorld(mining, ORE_LOCATIONS_COUNT); if (locs.isEmpty()) { logDebug("No locations for " + mining + " known, cancelling"); - mine(0, (String[]) null); + cancel(); return; } knownOreLocations = locs; @@ -158,7 +168,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe } } - public List searchWorld(List mining, int max) { + public static List searchWorld(List mining, int max) { List locs = new ArrayList<>(); List uninteresting = new ArrayList<>(); //long b = System.currentTimeMillis(); @@ -194,18 +204,18 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe } } } - knownOreLocations = prune(knownOreLocations, mining, 64); + knownOreLocations = prune(knownOreLocations, mining, ORE_LOCATIONS_COUNT); } - public List prune(List locs2, List mining, int max) { + public static List prune(List locs2, List mining, int max) { List locs = locs2 .stream() // remove any that are within loaded chunks that aren't actually what we want - .filter(pos -> world().getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock())) + .filter(pos -> Helper.HELPER.world().getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock())) // remove any that are implausible to mine (encased in bedrock, or touching lava) - .filter(MineBehavior::plausibleToBreak) + .filter(MineProcess::plausibleToBreak) .sorted(Comparator.comparingDouble(Helper.HELPER.playerFeet()::distanceSq)) .collect(Collectors.toList()); @@ -225,13 +235,8 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe } @Override - public void mine(int quantity, String... blocks) { - this.mining = blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).collect(Collectors.toList()); - this.desiredQuantity = quantity; - this.knownOreLocations = new ArrayList<>(); - this.branchPoint = null; - rescan(); - updateGoal(); + public void mineByName(int quantity, String... blocks) { + mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).toArray(Block[]::new)); } @Override @@ -241,12 +246,5 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe this.knownOreLocations = new ArrayList<>(); this.branchPoint = null; rescan(); - updateGoal(); - } - - @Override - public void cancel() { - mine(0, (String[]) null); - baritone.getPathingBehavior().cancel(); } } diff --git a/src/main/java/baritone/utils/BaritoneProcessHelper.java b/src/main/java/baritone/utils/BaritoneProcessHelper.java new file mode 100644 index 00000000..4ca0fe94 --- /dev/null +++ b/src/main/java/baritone/utils/BaritoneProcessHelper.java @@ -0,0 +1,53 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils; + +import baritone.Baritone; +import baritone.api.process.IBaritoneProcess; + +public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper { + public static final double DEFAULT_PRIORITY = 0; + + private final Baritone baritone; + private final double priority; + + public BaritoneProcessHelper(Baritone baritone) { + this(baritone, DEFAULT_PRIORITY); + } + + public BaritoneProcessHelper(Baritone baritone, double priority) { + this.baritone = baritone; + this.priority = priority; + baritone.getPathingControlManager().registerProcess(this); + } + + @Override + public Baritone associatedWith() { + return baritone; + } + + @Override + public boolean isTemporary() { + return false; + } + + @Override + public double priority() { + return priority; + } +} diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 77dbcef5..f461b9a7 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -73,7 +73,6 @@ public class ExampleBaritoneControl extends Behavior implements Helper { "sethome - Sets \"home\"\n" + "home - Paths towards \"home\" \n" + "costs - (debug) all movement costs from current location\n" + - "pause - Toggle pause\n" + "damn - Daniel "; public ExampleBaritoneControl(Baritone baritone) { @@ -228,15 +227,15 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("cancel") || msg.equals("stop")) { - baritone.getMineBehavior().cancel(); - baritone.getFollowBehavior().cancel(); + baritone.getMineProcess().cancel(); + baritone.getFollowProcess().cancel(); pathingBehavior.cancel(); logDirect("ok canceled"); return true; } if (msg.equals("forcecancel")) { - baritone.getMineBehavior().cancel(); - baritone.getFollowBehavior().cancel(); + baritone.getMineProcess().cancel(); + baritone.getFollowProcess().cancel(); pathingBehavior.cancel(); AbstractNodeCostSearch.forceCancel(); pathingBehavior.forceCancel(); @@ -288,7 +287,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("Not found"); return true; } - baritone.getFollowBehavior().follow(toFollow.get()); + baritone.getFollowProcess().follow(toFollow.get()); logDirect("Following " + toFollow.get()); return true; } @@ -320,7 +319,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { int quantity = Integer.parseInt(blockTypes[1]); Block block = ChunkPacker.stringToBlock(blockTypes[0]); Objects.requireNonNull(block); - baritone.getMineBehavior().mine(quantity, block); + baritone.getMineProcess().mine(quantity, block); logDirect("Will mine " + quantity + " " + blockTypes[0]); return true; } catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {} @@ -331,7 +330,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } } - baritone.getMineBehavior().mine(0, blockTypes); + baritone.getMineProcess().mineByName(0, blockTypes); logDirect("Started mining blocks of type " + Arrays.toString(blockTypes)); return true; } @@ -407,7 +406,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } } else { - List locs = baritone.getMineBehavior().searchWorld(Collections.singletonList(block), 64); + List locs = baritone.getMineProcess().searchWorld(Collections.singletonList(block), 64); if (locs.isEmpty()) { logDirect("No locations for " + mining + " known, cancelling"); return true; @@ -479,11 +478,6 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } return true; } - if (msg.equals("pause")) { - boolean enabled = pathingBehavior.toggle(); - logDirect("Pathing Behavior has " + (enabled ? "resumed" : "paused") + "."); - return true; - } if (msg.equals("damn")) { logDirect("daniel"); } diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java new file mode 100644 index 00000000..37c17614 --- /dev/null +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -0,0 +1,125 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils; + +import baritone.Baritone; +import baritone.api.pathing.goals.Goal; +import baritone.api.process.IBaritoneProcess; +import baritone.api.process.PathingCommand; +import baritone.pathing.path.PathExecutor; +import net.minecraft.util.math.BlockPos; + +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.stream.Collectors; + +public class PathingControlManager { + private final Baritone baritone; + private final HashSet processes; // unGh + + public PathingControlManager(Baritone baritone) { + this.baritone = baritone; + this.processes = new HashSet<>(); + } + + public void registerProcess(IBaritoneProcess process) { + processes.add(process); + } + + public void doTheThingWithTheStuff() { + PathingCommand cmd = doTheStuff(); + if (cmd == null) { + baritone.getPathingBehavior().cancel(); + return; + } + + switch (cmd.commandType) { + case REQUEST_PAUSE: + // idk + // ask pathingbehavior if its safe + case FORCE_REVALIDATE_GOAL_AND_PATH: + if (cmd.goal == null) { + baritone.getPathingBehavior().cancel(); // todo only if its safe + return; + } + // pwnage + baritone.getPathingBehavior().setGoal(cmd.goal); + if (revalidateGoal(cmd.goal)) { + baritone.getPathingBehavior().cancel(); // todo only if its safe + } + case REVALIDATE_GOAL_AND_PATH: + if (cmd.goal == null) { + baritone.getPathingBehavior().cancel(); // todo only if its safe + return; + } + baritone.getPathingBehavior().setGoal(cmd.goal); + if (Baritone.settings().cancelOnGoalInvalidation.get() && revalidateGoal(cmd.goal)) { + baritone.getPathingBehavior().cancel(); // todo only if its safe + } + case SET_GOAL_AND_PATH: + // now this i can do + if (cmd.goal != null) { + baritone.getPathingBehavior().setGoalAndPath(cmd.goal); + } + // breaks are for wusses!!!! + } + } + + public boolean revalidateGoal(Goal newGoal) { + PathExecutor current = baritone.getPathingBehavior().getCurrent(); + if (current != null) { + Goal intended = current.getPath().getGoal(); + BlockPos end = current.getPath().getDest(); + if (intended.isInGoal(end) && !newGoal.isInGoal(end)) { + // this path used to end in the goal + // but the goal has changed, so there's no reason to continue... + return true; + } + } + return false; + } + + + public PathingCommand doTheStuff() { + List inContention = processes.stream().filter(IBaritoneProcess::isActive).sorted(Comparator.comparingDouble(IBaritoneProcess::priority)).collect(Collectors.toList()); + boolean found = false; + boolean cancelOthers = false; + PathingCommand exec = null; + for (int i = inContention.size() - 1; i >= 0; i--) { // truly a gamer moment + IBaritoneProcess proc = inContention.get(i); + if (found) { + if (cancelOthers) { + proc.onLostControl(); + } + } else { + exec = proc.onTick(); + if (exec == null) { + if (proc.isActive()) { + throw new IllegalStateException(proc + ""); + } + proc.onLostControl(); + continue; + } + found = true; + cancelOthers = !proc.isTemporary(); + } + } + return exec; + } +} From 338fdb509a4e69d1dd284d1e809f1ff4e23204d7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 4 Nov 2018 10:29:22 -0800 Subject: [PATCH 02/29] it works --- .../api/process/IBaritoneProcess.java | 2 + .../api/process/PathingCommandType.java | 12 ++-- src/main/java/baritone/Baritone.java | 11 ++-- .../baritone/behavior/PathingBehavior.java | 50 ++++++++++++---- .../baritone/process/CustomGoalProcess.java | 54 ++++++++++++++--- .../java/baritone/process/FollowProcess.java | 9 ++- .../baritone/process/GetToBlockProcess.java | 10 +++- .../java/baritone/process/MineProcess.java | 11 +++- .../java/baritone/utils/BaritoneAutoTest.java | 3 +- .../baritone/utils/BaritoneProcessHelper.java | 2 +- .../utils/ExampleBaritoneControl.java | 59 ++++++++----------- .../baritone/utils/PathingControlManager.java | 52 +++++++++------- 12 files changed, 182 insertions(+), 93 deletions(-) diff --git a/src/api/java/baritone/api/process/IBaritoneProcess.java b/src/api/java/baritone/api/process/IBaritoneProcess.java index 6405be94..9eef16fc 100644 --- a/src/api/java/baritone/api/process/IBaritoneProcess.java +++ b/src/api/java/baritone/api/process/IBaritoneProcess.java @@ -44,4 +44,6 @@ public interface IBaritoneProcess { double priority(); // tenor be like IBaritone associatedWith(); // which bot is this associated with (5000000iq forward thinking) + + String displayName(); } diff --git a/src/api/java/baritone/api/process/PathingCommandType.java b/src/api/java/baritone/api/process/PathingCommandType.java index 24eaf3a8..d4f7af44 100644 --- a/src/api/java/baritone/api/process/PathingCommandType.java +++ b/src/api/java/baritone/api/process/PathingCommandType.java @@ -18,10 +18,12 @@ package baritone.api.process; public enum PathingCommandType { - SET_GOAL_AND_PATH, // if you do this one with a null goal it should continue - REQUEST_PAUSE, + SET_GOAL_AND_PATH, // self explanatory, if you do this one with a null goal it should continue - // if you do this one with a null goal it should cancel - REVALIDATE_GOAL_AND_PATH, // idkkkkkkk - FORCE_REVALIDATE_GOAL_AND_PATH // idkkkkkkkkkkkkkkkkkkkkkkkk + REQUEST_PAUSE, // this one just pauses. it doesn't change the goal. + + CANCEL_AND_SET_GOAL, // cancel the current path, and set the goal (regardless of if it's null) + + REVALIDATE_GOAL_AND_PATH, // set the goal, revalidate if cancelOnGoalInvalidation is true, then path. if the goal is null, it will cancel (but only if that setting is true) + FORCE_REVALIDATE_GOAL_AND_PATH // set the goal, revalidate current goal (cancel if no longer valid), cancel if the provided goal is null } diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 055929f0..b655dddc 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -21,7 +21,6 @@ import baritone.api.BaritoneAPI; import baritone.api.IBaritone; import baritone.api.Settings; import baritone.api.event.listener.IGameEventListener; -import baritone.api.process.IBaritoneProcess; import baritone.behavior.Behavior; import baritone.behavior.LookBehavior; import baritone.behavior.MemoryBehavior; @@ -114,8 +113,8 @@ public enum Baritone implements IBaritone { followProcess = new FollowProcess(this); mineProcess = new MineProcess(this); new ExampleBaritoneControl(this); - new CustomGoalProcess(this); // very high iq - new GetToBlockProcess(this); + customGoalProcess = new CustomGoalProcess(this); // very high iq + getToBlockProcess = new GetToBlockProcess(this); } if (BaritoneAutoTest.ENABLE_AUTO_TEST) { registerEventListener(BaritoneAutoTest.INSTANCE); @@ -160,8 +159,12 @@ public enum Baritone implements IBaritone { this.registerEventListener(behavior); } - public void registerProcess(IBaritoneProcess process) { + public CustomGoalProcess getCustomGoalProcess() { + return customGoalProcess; + } + public GetToBlockProcess getGetToBlockProcess() { // very very high iq + return getToBlockProcess; } @Override diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 1cfd98bd..15dffae8 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -52,6 +52,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, private Goal goal; + private boolean safeToCancel; + private boolean pauseRequestedLastTick; + private volatile boolean isPathCalcInProgress; private final Object pathCalcLock = new Object(); @@ -81,7 +84,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, public void onTick(TickEvent event) { dispatchEvents(); if (event.getType() == TickEvent.Type.OUT) { - cancel(); + secretInternalSegmentCancel(); return; } tickPath(); @@ -89,10 +92,17 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } private void tickPath() { + baritone.getPathingControlManager().doTheThingWithTheStuff(); + if (pauseRequestedLastTick && safeToCancel) { + pauseRequestedLastTick = false; + baritone.getInputOverrideHandler().clearAllKeys(); + BlockBreakHelper.stopBreakingBlock(); + return; + } if (current == null) { return; } - boolean safe = current.onTick(); + safeToCancel = current.onTick(); synchronized (pathPlanLock) { if (current.failed() || current.finished()) { current = null; @@ -134,7 +144,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, return; } // at this point, we know current is in progress - if (safe && next != null && next.snipsnapifpossible()) { + if (safeToCancel && next != null && next.snipsnapifpossible()) { // a movement just ended; jump directly onto the next path logDebug("Splicing into planned next path early..."); queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY); @@ -191,13 +201,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, return Optional.of(current.getPath().ticksRemainingFrom(current.getPosition())); } - public void setGoal(Goal goal) { + public void secretInternalSetGoal(Goal goal) { this.goal = goal; } - public boolean setGoalAndPath(Goal goal) { - setGoal(goal); - return path(); + public boolean secretInternalSetGoalAndPath(Goal goal) { + secretInternalSetGoal(goal); + return secretInternalPath(); } @Override @@ -225,22 +235,40 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, return this.current != null; } + public boolean isSafeToCancel() { + return current == null || safeToCancel; + } + + public void requestPause() { + pauseRequestedLastTick = true; + } + + public boolean cancelSegmentIfSafe() { + if (isSafeToCancel()) { + secretInternalSegmentCancel(); + return true; + } + return false; + } + @Override public void cancelEverything() { - + secretInternalSegmentCancel(); + baritone.getPathingControlManager().cancelEverything(); } // just cancel the current path - public void cancel() { + public void secretInternalSegmentCancel() { queuePathEvent(PathEvent.CANCELED); current = null; next = null; - Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + baritone.getInputOverrideHandler().clearAllKeys(); AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel); BlockBreakHelper.stopBreakingBlock(); } public void forceCancel() { // NOT exposed on public api + cancelEverything(); isPathCalcInProgress = false; } @@ -249,7 +277,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, * * @return true if this call started path calculation, false if it was already calculating or executing a path */ - public boolean path() { + public boolean secretInternalPath() { if (goal == null) { return false; } diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index 08b142ff..e402edf8 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -22,8 +22,11 @@ import baritone.api.pathing.goals.Goal; import baritone.api.process.ICustomGoalProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; +import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.utils.BaritoneProcessHelper; +import java.util.Objects; + /** * As set by ExampleBaritoneControl or something idk * @@ -31,35 +34,72 @@ import baritone.utils.BaritoneProcessHelper; */ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess { private Goal goal; - private boolean active; + private State state; + private int ticksExecuting; public CustomGoalProcess(Baritone baritone) { - super(baritone); + super(baritone, 3); } @Override public void setGoal(Goal goal) { this.goal = goal; + state = State.GOAL_SET; } @Override public void path() { - active = true; + if (goal == null) { + goal = baritone.getPathingBehavior().getGoal(); + } + state = State.PATH_REQUESTED; + } + + private enum State { + NONE, + GOAL_SET, + PATH_REQUESTED, + EXECUTING, + } @Override public boolean isActive() { - return active; + return state != State.NONE; } @Override public PathingCommand onTick() { - active = false; // only do this once - return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); + switch (state) { + case GOAL_SET: + if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), goal)) { + state = State.NONE; + } + return new PathingCommand(goal, PathingCommandType.CANCEL_AND_SET_GOAL); + case PATH_REQUESTED: + PathingCommand ret = new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); + state = State.EXECUTING; + ticksExecuting = 0; + return ret; + case EXECUTING: + if (ticksExecuting++ > 2 && !baritone.getPathingBehavior().isPathing() && !AbstractNodeCostSearch.getCurrentlyRunning().isPresent()) { + onLostControl(); + } + return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); + default: + throw new IllegalStateException(); + } } @Override public void onLostControl() { - active = false; + state = State.NONE; + goal = null; + ticksExecuting = 0; + } + + @Override + public String displayName() { + return "Custom Goal " + goal; } } diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index dcfa21a0..bfccdda7 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -18,9 +18,9 @@ package baritone.process; import baritone.Baritone; -import baritone.api.process.IFollowProcess; import baritone.api.pathing.goals.GoalNear; import baritone.api.pathing.goals.GoalXZ; +import baritone.api.process.IFollowProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.utils.BaritoneProcessHelper; @@ -37,7 +37,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo private Entity following; public FollowProcess(Baritone baritone) { - super(baritone); + super(baritone, 1); } @Override @@ -63,6 +63,11 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo following = null; } + @Override + public String displayName() { + return "Follow " + following; + } + @Override public void follow(Entity entity) { this.following = entity; diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 62dac26e..b2fd1363 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -38,7 +38,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl int tickCount = 0; public GetToBlockProcess(Baritone baritone) { - super(baritone); + super(baritone, 2); } @Override @@ -67,6 +67,9 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl Baritone.INSTANCE.getExecutor().execute(this::rescan); } Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)); + if (goal.isInGoal(playerFeet())) { + onLostControl(); + } return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); } @@ -76,6 +79,11 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl knownLocations = null; } + @Override + public String displayName() { + return "Get To Block " + gettingTo; + } + private void rescan() { knownLocations = MineProcess.searchWorld(Collections.singletonList(gettingTo), 64); } diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index a88fd537..823f2091 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -57,7 +57,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro private int tickCount; public MineProcess(Baritone baritone) { - super(baritone); + super(baritone, 0); } @Override @@ -79,7 +79,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain - Baritone.INSTANCE.getExecutor().execute(this::rescan); + baritone.getExecutor().execute(this::rescan); } if (Baritone.settings().legitMine.get()) { addNearby(); @@ -99,6 +99,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro mine(0, (Block[]) null); } + @Override + public String displayName() { + return "Mine " + mining; + } + private Goal updateGoal() { List locs = knownOreLocations; if (!locs.isEmpty()) { @@ -115,7 +120,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro // only in non-Xray mode (aka legit mode) do we do this if (branchPoint == null) { int y = Baritone.settings().legitMineYLevel.get(); - if (!associatedWith().getPathingBehavior().isPathing() && playerFeet().y == y) { + if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) { // cool, path is over and we are at desired y branchPoint = playerFeet(); } else { diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index 70e1a70e..4aee4bd4 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -105,8 +105,7 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { } // Setup Baritone's pathing goal and (if needed) begin pathing - Baritone.INSTANCE.getPathingBehavior().setGoal(GOAL); - Baritone.INSTANCE.getPathingBehavior().path(); + Baritone.INSTANCE.getCustomGoalProcess().setGoalAndPath(GOAL); // If we have reached our goal, print a message and safely close the game if (GOAL.isInGoal(playerFeet())) { diff --git a/src/main/java/baritone/utils/BaritoneProcessHelper.java b/src/main/java/baritone/utils/BaritoneProcessHelper.java index 4ca0fe94..d01e815d 100644 --- a/src/main/java/baritone/utils/BaritoneProcessHelper.java +++ b/src/main/java/baritone/utils/BaritoneProcessHelper.java @@ -23,7 +23,7 @@ import baritone.api.process.IBaritoneProcess; public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper { public static final double DEFAULT_PRIORITY = 0; - private final Baritone baritone; + protected final Baritone baritone; private final double priority; public BaritoneProcessHelper(Baritone baritone) { diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index f461b9a7..90648245 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -33,6 +33,7 @@ import baritone.cache.WorldProvider; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.Movement; import baritone.pathing.movement.Moves; +import baritone.process.CustomGoalProcess; import net.minecraft.block.Block; import net.minecraft.client.multiplayer.ChunkProviderClient; import net.minecraft.entity.Entity; @@ -99,6 +100,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper { public boolean runCommand(String msg0) { String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL PathingBehavior pathingBehavior = baritone.getPathingBehavior(); + PathingControlManager pathControl = baritone.getPathingControlManager(); + CustomGoalProcess CGPgrey = baritone.getCustomGoalProcess(); List> toggleable = Baritone.settings().getAllValuesByType(Boolean.class); for (Settings.Setting setting : toggleable) { if (msg.equalsIgnoreCase(setting.getName())) { @@ -186,21 +189,19 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("unable to parse integer " + ex); return true; } - pathingBehavior.setGoal(goal); + CGPgrey.setGoal(goal); logDirect("Goal: " + goal); return true; } if (msg.equals("path")) { - if (!pathingBehavior.path()) { - if (pathingBehavior.getGoal() == null) { - logDirect("No goal."); - } else { - if (pathingBehavior.getGoal().isInGoal(playerFeet())) { - logDirect("Already in goal"); - } else { - logDirect("Currently executing a path. Please cancel it first."); - } - } + if (pathingBehavior.getGoal() == null) { + logDirect("No goal."); + } else if (pathingBehavior.getGoal().isInGoal(playerFeet())) { + logDirect("Already in goal"); + } else if (pathingBehavior.isPathing()) { + logDirect("Currently executing a path. Please cancel it first."); + } else { + CGPgrey.path(); } return true; } @@ -222,21 +223,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("axis")) { - pathingBehavior.setGoal(new GoalAxis()); - pathingBehavior.path(); + CGPgrey.setGoalAndPath(new GoalAxis()); return true; } if (msg.equals("cancel") || msg.equals("stop")) { baritone.getMineProcess().cancel(); baritone.getFollowProcess().cancel(); - pathingBehavior.cancel(); + pathingBehavior.cancelEverything(); logDirect("ok canceled"); return true; } if (msg.equals("forcecancel")) { baritone.getMineProcess().cancel(); baritone.getFollowProcess().cancel(); - pathingBehavior.cancel(); + pathingBehavior.cancelEverything(); AbstractNodeCostSearch.forceCancel(); pathingBehavior.forceCancel(); logDirect("ok force canceled"); @@ -259,15 +259,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("Inverting goal of player feet"); runAwayFrom = playerFeet(); } - pathingBehavior.setGoal(new GoalRunAway(1, runAwayFrom) { + CGPgrey.setGoalAndPath(new GoalRunAway(1, runAwayFrom) { @Override public boolean isInGoal(int x, int y, int z) { return false; } }); - if (!pathingBehavior.path()) { - logDirect("Currently executing a path. Please cancel it first."); - } return true; } if (msg.startsWith("follow")) { @@ -337,7 +334,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { if (msg.startsWith("thisway")) { try { Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim())); - pathingBehavior.setGoal(goal); + CGPgrey.setGoal(goal); logDirect("Goal: " + goal); } catch (NumberFormatException ex) { logDirect("Error unable to parse '" + msg.substring(7).trim() + "' to a double."); @@ -406,13 +403,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } } else { - List locs = baritone.getMineProcess().searchWorld(Collections.singletonList(block), 64); - if (locs.isEmpty()) { - logDirect("No locations for " + mining + " known, cancelling"); - return true; - } - pathingBehavior.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new))); - pathingBehavior.path(); + baritone.getGetToBlockProcess().getToBlock(block); return true; } } else { @@ -423,10 +414,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } } Goal goal = new GoalBlock(waypoint.getLocation()); - pathingBehavior.setGoal(goal); - if (!pathingBehavior.path() && !goal.isInGoal(playerFeet())) { - logDirect("Currently executing a path. Please cancel it first."); - } + CGPgrey.setGoalAndPath(goal); return true; } if (msg.equals("spawn") || msg.equals("bed")) { @@ -436,10 +424,10 @@ public class ExampleBaritoneControl extends Behavior implements Helper { // for some reason the default spawnpoint is underground sometimes Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ()); logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal); - pathingBehavior.setGoal(goal); + CGPgrey.setGoalAndPath(goal); } else { - Goal goal = new GoalBlock(waypoint.getLocation()); - pathingBehavior.setGoal(goal); + Goal goal = new GoalGetToBlock(waypoint.getLocation()); + CGPgrey.setGoalAndPath(goal); logDirect("Set goal to most recent bed " + goal); } return true; @@ -455,8 +443,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("home not saved"); } else { Goal goal = new GoalBlock(waypoint.getLocation()); - pathingBehavior.setGoal(goal); - pathingBehavior.path(); + CGPgrey.setGoalAndPath(goal); logDirect("Going to saved home " + goal); } return true; diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 37c17614..55308daf 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.pathing.goals.Goal; import baritone.api.process.IBaritoneProcess; import baritone.api.process.PathingCommand; +import baritone.behavior.PathingBehavior; import baritone.pathing.path.PathExecutor; import net.minecraft.util.math.BlockPos; @@ -39,43 +40,51 @@ public class PathingControlManager { } public void registerProcess(IBaritoneProcess process) { + process.onLostControl(); // make sure it's reset processes.add(process); } + public void cancelEverything() { + for (IBaritoneProcess proc : processes) { + proc.onLostControl(); + if (proc.isActive() && !proc.isTemporary()) { // it's okay for a temporary thing (like combat pause) to maintain control even if you say to cancel + // but not for a non temporary thing + throw new IllegalStateException(proc.displayName()); + } + } + } + public void doTheThingWithTheStuff() { PathingCommand cmd = doTheStuff(); if (cmd == null) { - baritone.getPathingBehavior().cancel(); return; } - + PathingBehavior p = baritone.getPathingBehavior(); switch (cmd.commandType) { case REQUEST_PAUSE: - // idk - // ask pathingbehavior if its safe + p.requestPause(); + break; + case CANCEL_AND_SET_GOAL: + p.secretInternalSetGoal(cmd.goal); + p.cancelSegmentIfSafe(); + break; case FORCE_REVALIDATE_GOAL_AND_PATH: - if (cmd.goal == null) { - baritone.getPathingBehavior().cancel(); // todo only if its safe - return; - } - // pwnage - baritone.getPathingBehavior().setGoal(cmd.goal); - if (revalidateGoal(cmd.goal)) { - baritone.getPathingBehavior().cancel(); // todo only if its safe + p.secretInternalSetGoalAndPath(cmd.goal); + if (cmd.goal == null || revalidateGoal(cmd.goal)) { + // pwnage + p.cancelSegmentIfSafe(); } + break; case REVALIDATE_GOAL_AND_PATH: - if (cmd.goal == null) { - baritone.getPathingBehavior().cancel(); // todo only if its safe - return; - } - baritone.getPathingBehavior().setGoal(cmd.goal); - if (Baritone.settings().cancelOnGoalInvalidation.get() && revalidateGoal(cmd.goal)) { - baritone.getPathingBehavior().cancel(); // todo only if its safe + p.secretInternalSetGoalAndPath(cmd.goal); + if (Baritone.settings().cancelOnGoalInvalidation.get() && (cmd.goal == null || revalidateGoal(cmd.goal))) { + p.cancelSegmentIfSafe(); } + break; case SET_GOAL_AND_PATH: // now this i can do if (cmd.goal != null) { - baritone.getPathingBehavior().setGoalAndPath(cmd.goal); + baritone.getPathingBehavior().secretInternalSetGoalAndPath(cmd.goal); } // breaks are for wusses!!!! } @@ -111,11 +120,12 @@ public class PathingControlManager { exec = proc.onTick(); if (exec == null) { if (proc.isActive()) { - throw new IllegalStateException(proc + ""); + throw new IllegalStateException(proc.displayName()); } proc.onLostControl(); continue; } + System.out.println("Executing command " + exec.commandType + " " + exec.goal + " from " + proc.displayName()); found = true; cancelOthers = !proc.isTemporary(); } From cd3aef47a5c362dda1014172e5d3fc1e16e0b0ba Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 4 Nov 2018 10:30:46 -0800 Subject: [PATCH 03/29] that already does that --- src/main/java/baritone/utils/ExampleBaritoneControl.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 90648245..d7c1cf89 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -227,15 +227,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("cancel") || msg.equals("stop")) { - baritone.getMineProcess().cancel(); - baritone.getFollowProcess().cancel(); pathingBehavior.cancelEverything(); logDirect("ok canceled"); return true; } if (msg.equals("forcecancel")) { - baritone.getMineProcess().cancel(); - baritone.getFollowProcess().cancel(); pathingBehavior.cancelEverything(); AbstractNodeCostSearch.forceCancel(); pathingBehavior.forceCancel(); From c0b5d60715cfeb033d10d050e334bcee79e2c54f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 4 Nov 2018 22:17:49 -0800 Subject: [PATCH 04/29] fix --- src/main/java/baritone/utils/PathingControlManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 55308daf..8165f1a1 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -86,7 +86,9 @@ public class PathingControlManager { if (cmd.goal != null) { baritone.getPathingBehavior().secretInternalSetGoalAndPath(cmd.goal); } - // breaks are for wusses!!!! + break; + default: + throw new IllegalStateException(); } } From 2c39cd06ed744f13d5a66d5adbce01f83df1a7b9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 14:19:50 -0800 Subject: [PATCH 05/29] cleanup --- .../api/process/IBaritoneProcess.java | 55 ++++++++++++++++--- .../api/process/PathingCommandType.java | 32 +++++++++-- .../baritone/behavior/PathingBehavior.java | 6 ++ .../baritone/process/CustomGoalProcess.java | 11 ++-- .../java/baritone/process/FollowProcess.java | 2 +- .../baritone/process/GetToBlockProcess.java | 23 +++++--- .../java/baritone/process/MineProcess.java | 7 ++- .../utils/ExampleBaritoneControl.java | 1 - .../baritone/utils/PathingControlManager.java | 10 +++- 9 files changed, 117 insertions(+), 30 deletions(-) diff --git a/src/api/java/baritone/api/process/IBaritoneProcess.java b/src/api/java/baritone/api/process/IBaritoneProcess.java index 9eef16fc..3f907c3d 100644 --- a/src/api/java/baritone/api/process/IBaritoneProcess.java +++ b/src/api/java/baritone/api/process/IBaritoneProcess.java @@ -31,19 +31,58 @@ import baritone.api.IBaritone; * @author leijurv */ public interface IBaritoneProcess { - // javadocs small brain, // comment large brain + /** + * Would this process like to be in control? + * + * @return + */ + boolean isActive(); - boolean isActive(); // would you like to be in control? + /** + * This process is in control of pathing. What should Baritone do? + * + * @param calcFailed true if this specific process was in control last tick, and there was a CALC_FAILED event last tick + * @param isSafeToCancel true if a REQUEST_PAUSE would happen this tick, and PathingBehavior wouldn't actually tick. + * false if the PathExecutor reported pausing would be unsafe at the end of the last tick + * @return what the PathingBehavior should do + */ + PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel); - PathingCommand onTick(); // you're in control, what should baritone do? + /** + * Is this control temporary? + * If a process is temporary, it doesn't call onLostControl on the processes that aren't execute because of it + * For example, CombatPauserProcess and PauseForAutoEatProcess should return isTemporary true always, + * and should return isActive true only if there's something in range this tick, or if the player would like to start eating this tick. + * PauseForAutoEatProcess should only actually right click once onTick is called with isSafeToCancel true though. + * + * @return + */ + boolean isTemporary(); - boolean isTemporary(); // CombatPauserProcess should return isTemporary true always, and isActive true only when something is in range + /** + * Called if isActive returned true, but another non-temporary process has control. Effectively the same as cancel. + * You want control but you don't get it. + */ + void onLostControl(); - void onLostControl(); // called if isActive returned true, but another non-temporary process has control. effectively the same as cancel. + /** + * How to decide which Process gets control if they all report isActive? It's the one with the highest priority. + * + * @return + */ + double priority(); - double priority(); // tenor be like - - IBaritone associatedWith(); // which bot is this associated with (5000000iq forward thinking) + /** + * which bot is this associated with (5000000iq forward thinking) + * + * @return + */ + IBaritone associatedWith(); + /** + * What this process should be displayed to the user as (maybe in a HUD? hint hint) + * + * @return + */ String displayName(); } diff --git a/src/api/java/baritone/api/process/PathingCommandType.java b/src/api/java/baritone/api/process/PathingCommandType.java index d4f7af44..98517ba5 100644 --- a/src/api/java/baritone/api/process/PathingCommandType.java +++ b/src/api/java/baritone/api/process/PathingCommandType.java @@ -18,12 +18,34 @@ package baritone.api.process; public enum PathingCommandType { - SET_GOAL_AND_PATH, // self explanatory, if you do this one with a null goal it should continue + /** + * Set the goal and path. + *

+ * If you use this alongside a null goal, it will continue along its current path and current goal. + */ + SET_GOAL_AND_PATH, - REQUEST_PAUSE, // this one just pauses. it doesn't change the goal. + /** + * Has no effect on the current goal or path, just requests a pause + */ + REQUEST_PAUSE, - CANCEL_AND_SET_GOAL, // cancel the current path, and set the goal (regardless of if it's null) + /** + * Set the goal (regardless of null), and request a cancel of the current path (when safe) + */ + CANCEL_AND_SET_GOAL, - REVALIDATE_GOAL_AND_PATH, // set the goal, revalidate if cancelOnGoalInvalidation is true, then path. if the goal is null, it will cancel (but only if that setting is true) - FORCE_REVALIDATE_GOAL_AND_PATH // set the goal, revalidate current goal (cancel if no longer valid), cancel if the provided goal is null + /** + * Set the goal and path. + *

+ * If cancelOnGoalInvalidation is true, revalidate the current goal, and cancel if it's no longer valid, or if the new goal is null. + */ + REVALIDATE_GOAL_AND_PATH, + + /** + * Set the goal and path. + *

+ * Revalidate the current goal, and cancel if it's no longer valid, or if the new goal is null. + */ + FORCE_REVALIDATE_GOAL_AND_PATH, } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 15dffae8..03641ac5 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -54,6 +54,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, private boolean safeToCancel; private boolean pauseRequestedLastTick; + private boolean calcFailedLastTick; private volatile boolean isPathCalcInProgress; private final Object pathCalcLock = new Object(); @@ -75,6 +76,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, private void dispatchEvents() { ArrayList curr = new ArrayList<>(); toDispatch.drainTo(curr); + calcFailedLastTick = curr.contains(PathEvent.CALC_FAILED); for (PathEvent event : curr) { Baritone.INSTANCE.getGameEventHandler().onPathEvent(event); } @@ -257,6 +259,10 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, baritone.getPathingControlManager().cancelEverything(); } + public boolean calcFailedLastTick() { // NOT exposed on public api + return calcFailedLastTick; + } + // just cancel the current path public void secretInternalSegmentCancel() { queuePathEvent(PathEvent.CANCELED); diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index e402edf8..52769f25 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -22,7 +22,6 @@ import baritone.api.pathing.goals.Goal; import baritone.api.process.ICustomGoalProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; -import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.utils.BaritoneProcessHelper; import java.util.Objects; @@ -35,7 +34,6 @@ import java.util.Objects; public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess { private Goal goal; private State state; - private int ticksExecuting; public CustomGoalProcess(Baritone baritone) { super(baritone, 3); @@ -69,7 +67,7 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG } @Override - public PathingCommand onTick() { + public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { switch (state) { case GOAL_SET: if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), goal)) { @@ -79,12 +77,14 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG case PATH_REQUESTED: PathingCommand ret = new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); state = State.EXECUTING; - ticksExecuting = 0; return ret; case EXECUTING: - if (ticksExecuting++ > 2 && !baritone.getPathingBehavior().isPathing() && !AbstractNodeCostSearch.getCurrentlyRunning().isPresent()) { + if (calcFailed) { onLostControl(); } + if (goal.isInGoal(playerFeet())) { + onLostControl(); // we're there xd + } return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); default: throw new IllegalStateException(); @@ -95,7 +95,6 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG public void onLostControl() { state = State.NONE; goal = null; - ticksExecuting = 0; } @Override diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index bfccdda7..f662fa1d 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -41,7 +41,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo } @Override - public PathingCommand onTick() { + public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { // lol this is trashy but it works BlockPos pos; if (Baritone.settings().followOffsetDistance.get() == 0) { diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index b2fd1363..8dd07560 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -32,10 +32,10 @@ import java.util.Collections; import java.util.List; public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess { - Block gettingTo; - List knownLocations; + private Block gettingTo; + private List knownLocations; - int tickCount = 0; + private int tickCount = 0; public GetToBlockProcess(Baritone baritone) { super(baritone, 2); @@ -53,14 +53,23 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } @Override - public PathingCommand onTick() { + public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { if (knownLocations == null) { rescan(); } if (knownLocations.isEmpty()) { - logDirect("No known locations of " + gettingTo); - onLostControl(); - return null; + logDirect("No known locations of " + gettingTo + ", canceling GetToBlock"); + if (isSafeToCancel) { + onLostControl(); + } + return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL); + } + if (calcFailed) { + logDirect("Unable to find any path to " + gettingTo + ", canceling GetToBlock"); + if (isSafeToCancel) { + onLostControl(); + } + return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL); } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 823f2091..2efeca03 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -66,7 +66,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } @Override - public PathingCommand onTick() { + public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { if (desiredQuantity > 0) { Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), new Random(), 0); int curr = player().inventory.mainInventory.stream().filter(stack -> item.equals(stack.getItem())).mapToInt(ItemStack::getCount).sum(); @@ -77,6 +77,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return null; } } + if (calcFailed) { + logDirect("Unable to find any path to " + mining + ", canceling Mine"); + cancel(); + return null; + } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain baritone.getExecutor().execute(this::rescan); diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index d7c1cf89..74c17d60 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -100,7 +100,6 @@ public class ExampleBaritoneControl extends Behavior implements Helper { public boolean runCommand(String msg0) { String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL PathingBehavior pathingBehavior = baritone.getPathingBehavior(); - PathingControlManager pathControl = baritone.getPathingControlManager(); CustomGoalProcess CGPgrey = baritone.getCustomGoalProcess(); List> toggleable = Baritone.settings().getAllValuesByType(Boolean.class); for (Settings.Setting setting : toggleable) { diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 8165f1a1..bfb84d3c 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -33,6 +33,8 @@ import java.util.stream.Collectors; public class PathingControlManager { private final Baritone baritone; private final HashSet processes; // unGh + private IBaritoneProcess inControlLastTick; + private IBaritoneProcess inControlThisTick; public PathingControlManager(Baritone baritone) { this.baritone = baritone; @@ -54,7 +56,12 @@ public class PathingControlManager { } } + public IBaritoneProcess inControlThisTick() { + return inControlThisTick; + } + public void doTheThingWithTheStuff() { + inControlLastTick = inControlThisTick; PathingCommand cmd = doTheStuff(); if (cmd == null) { return; @@ -119,7 +126,7 @@ public class PathingControlManager { proc.onLostControl(); } } else { - exec = proc.onTick(); + exec = proc.onTick(proc == inControlLastTick && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel()); if (exec == null) { if (proc.isActive()) { throw new IllegalStateException(proc.displayName()); @@ -128,6 +135,7 @@ public class PathingControlManager { continue; } System.out.println("Executing command " + exec.commandType + " " + exec.goal + " from " + proc.displayName()); + inControlThisTick = proc; found = true; cancelOthers = !proc.isTemporary(); } From e11e3dfd864dede96cb9764deb98f6b55ffe4f92 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 14:22:30 -0800 Subject: [PATCH 06/29] explain --- src/api/java/baritone/api/process/IBaritoneProcess.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/process/IBaritoneProcess.java b/src/api/java/baritone/api/process/IBaritoneProcess.java index 3f907c3d..d05bd8ef 100644 --- a/src/api/java/baritone/api/process/IBaritoneProcess.java +++ b/src/api/java/baritone/api/process/IBaritoneProcess.java @@ -43,7 +43,8 @@ public interface IBaritoneProcess { * * @param calcFailed true if this specific process was in control last tick, and there was a CALC_FAILED event last tick * @param isSafeToCancel true if a REQUEST_PAUSE would happen this tick, and PathingBehavior wouldn't actually tick. - * false if the PathExecutor reported pausing would be unsafe at the end of the last tick + * false if the PathExecutor reported pausing would be unsafe at the end of the last tick. + * Effectively "could request cancel or pause and have it happen right away" * @return what the PathingBehavior should do */ PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel); From 30408384c6d3eb131ecc9b2b900a8cfdd05f967d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 14:37:05 -0800 Subject: [PATCH 07/29] fix --- src/api/java/baritone/api/behavior/IPathingBehavior.java | 4 +++- src/main/java/baritone/behavior/PathingBehavior.java | 9 +++++++-- src/main/java/baritone/process/GetToBlockProcess.java | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/behavior/IPathingBehavior.java b/src/api/java/baritone/api/behavior/IPathingBehavior.java index ced3d861..622c453a 100644 --- a/src/api/java/baritone/api/behavior/IPathingBehavior.java +++ b/src/api/java/baritone/api/behavior/IPathingBehavior.java @@ -53,8 +53,10 @@ public interface IPathingBehavior extends IBehavior { * Cancels the pathing behavior or the current path calculation. Also cancels all processes that could be controlling path. *

* Basically, "MAKE IT STOP". + * + * @return whether or not the pathing behavior was canceled. All processes are guaranteed to be canceled, but the PathingBehavior might be in the middle of an uncancelable action like a parkour jump */ - void cancelEverything(); + boolean cancelEverything(); /** * Returns the current path, from the current path executor, if there is one. diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 03641ac5..9582f3c5 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -254,9 +254,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } @Override - public void cancelEverything() { - secretInternalSegmentCancel(); + public boolean cancelEverything() { + boolean doIt = isSafeToCancel(); + if (doIt) { + secretInternalSegmentCancel(); + } baritone.getPathingControlManager().cancelEverything(); + return doIt; } public boolean calcFailedLastTick() { // NOT exposed on public api @@ -275,6 +279,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, public void forceCancel() { // NOT exposed on public api cancelEverything(); + secretInternalSegmentCancel(); isPathCalcInProgress = false; } diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 8dd07560..7f5340ed 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -79,7 +79,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl if (goal.isInGoal(playerFeet())) { onLostControl(); } - return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); + return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH); } @Override From 23286dd8b8d1ceaf6fd26e6247c365456f0a38e8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 14:38:32 -0800 Subject: [PATCH 08/29] disallow null PathingCommandType --- src/api/java/baritone/api/process/PathingCommand.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/api/java/baritone/api/process/PathingCommand.java b/src/api/java/baritone/api/process/PathingCommand.java index f5b39501..082928b3 100644 --- a/src/api/java/baritone/api/process/PathingCommand.java +++ b/src/api/java/baritone/api/process/PathingCommand.java @@ -26,5 +26,8 @@ public class PathingCommand { public PathingCommand(Goal goal, PathingCommandType commandType) { this.goal = goal; this.commandType = commandType; + if (commandType == null) { + throw new IllegalArgumentException(); + } } } From 8aa5a6756aa040aa99c79edefa929333668ce1f6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 14:41:17 -0800 Subject: [PATCH 09/29] add to api --- src/api/java/baritone/api/BaritoneAPI.java | 10 ++++++++++ src/api/java/baritone/api/IBaritone.java | 10 +++++++++- src/main/java/baritone/Baritone.java | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/BaritoneAPI.java b/src/api/java/baritone/api/BaritoneAPI.java index bf878d33..b9dbcd04 100644 --- a/src/api/java/baritone/api/BaritoneAPI.java +++ b/src/api/java/baritone/api/BaritoneAPI.java @@ -23,7 +23,9 @@ import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IWorldProvider; import baritone.api.cache.IWorldScanner; import baritone.api.event.listener.IGameEventListener; +import baritone.api.process.ICustomGoalProcess; import baritone.api.process.IFollowProcess; +import baritone.api.process.IGetToBlockProcess; import baritone.api.process.IMineProcess; import baritone.api.utils.SettingsUtil; @@ -84,6 +86,14 @@ public final class BaritoneAPI { return baritone.getWorldScanner(); } + public static ICustomGoalProcess getCustomGoalProcess() { + return baritone.getCustomGoalProcess(); + } + + public static IGetToBlockProcess getGetToBlockProcess() { + return baritone.getGetToBlockProcess(); + } + public static void registerEventListener(IGameEventListener listener) { baritone.registerEventListener(listener); } diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index 2d1982cd..aee9dead 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -17,11 +17,15 @@ package baritone.api; -import baritone.api.behavior.*; +import baritone.api.behavior.ILookBehavior; +import baritone.api.behavior.IMemoryBehavior; +import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IWorldProvider; import baritone.api.cache.IWorldScanner; import baritone.api.event.listener.IGameEventListener; +import baritone.api.process.ICustomGoalProcess; import baritone.api.process.IFollowProcess; +import baritone.api.process.IGetToBlockProcess; import baritone.api.process.IMineProcess; /** @@ -72,6 +76,10 @@ public interface IBaritone { */ IWorldScanner getWorldScanner(); + ICustomGoalProcess getCustomGoalProcess(); + + IGetToBlockProcess getGetToBlockProcess(); + /** * Registers a {@link IGameEventListener} with Baritone's "event bus". * diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index b655dddc..1cd482cf 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -159,10 +159,12 @@ public enum Baritone implements IBaritone { this.registerEventListener(behavior); } + @Override public CustomGoalProcess getCustomGoalProcess() { return customGoalProcess; } + @Override public GetToBlockProcess getGetToBlockProcess() { // very very high iq return getToBlockProcess; } From cb153e039bb5e28bf3c76103111c750788fdb08e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 14:43:57 -0800 Subject: [PATCH 10/29] not used and not publicly exposed --- src/main/java/baritone/Baritone.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 1cd482cf..89806f98 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -82,11 +82,6 @@ public enum Baritone implements IBaritone { private PathingControlManager pathingControlManager; - /** - * Whether or not Baritone is active - */ - private boolean active; - Baritone() { this.gameEventHandler = new GameEventHandler(); } @@ -126,7 +121,6 @@ public enum Baritone implements IBaritone { } catch (IOException ignored) {} } - this.active = true; this.initialized = true; } @@ -209,10 +203,6 @@ public enum Baritone implements IBaritone { this.gameEventHandler.registerEventListener(listener); } - public boolean isActive() { - return this.active; - } - public Settings getSettings() { return this.settings; } From 4d0bfce7122a09d7f0c5e7ea8cfb3369e741a85e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 14:47:40 -0800 Subject: [PATCH 11/29] make InputOverrideHandler a Behavior --- src/main/java/baritone/Baritone.java | 14 +++++++++----- .../java/baritone/utils/InputOverrideHandler.java | 8 +++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 89806f98..50320289 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -65,7 +65,6 @@ public enum Baritone implements IBaritone { private boolean initialized; private GameEventHandler gameEventHandler; - private InputOverrideHandler inputOverrideHandler; private Settings settings; private File dir; private ThreadPoolExecutor threadPool; @@ -74,6 +73,7 @@ public enum Baritone implements IBaritone { private PathingBehavior pathingBehavior; private LookBehavior lookBehavior; private MemoryBehavior memoryBehavior; + private InputOverrideHandler inputOverrideHandler; private FollowProcess followProcess; private MineProcess mineProcess; @@ -91,26 +91,30 @@ public enum Baritone implements IBaritone { return; } this.threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); - this.inputOverrideHandler = new InputOverrideHandler(); + // Acquire the "singleton" instance of the settings directly from the API // We might want to change this... this.settings = BaritoneAPI.getSettings(); - this.pathingControlManager = new PathingControlManager(this); - this.behaviors = new ArrayList<>(); { // the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist pathingBehavior = new PathingBehavior(this); lookBehavior = new LookBehavior(this); memoryBehavior = new MemoryBehavior(this); + inputOverrideHandler = new InputOverrideHandler(this); + new ExampleBaritoneControl(this); + } + + this.pathingControlManager = new PathingControlManager(this); + { followProcess = new FollowProcess(this); mineProcess = new MineProcess(this); - new ExampleBaritoneControl(this); customGoalProcess = new CustomGoalProcess(this); // very high iq getToBlockProcess = new GetToBlockProcess(this); } + if (BaritoneAutoTest.ENABLE_AUTO_TEST) { registerEventListener(BaritoneAutoTest.INSTANCE); } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 9cf7d1da..4d325fc7 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -17,6 +17,8 @@ package baritone.utils; +import baritone.Baritone; +import baritone.behavior.Behavior; import net.minecraft.client.settings.KeyBinding; import java.util.HashMap; @@ -30,7 +32,11 @@ import java.util.Map; * @author Brady * @since 7/31/2018 11:20 PM */ -public final class InputOverrideHandler implements Helper { +public final class InputOverrideHandler extends Behavior implements Helper { + + public InputOverrideHandler(Baritone baritone) { + super(baritone); + } /** * Maps keybinds to whether or not we are forcing their state down. From 2da3222115ece37de5aab28e1c21c9b35e2ae462 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 14:55:13 -0800 Subject: [PATCH 12/29] fix --- src/main/java/baritone/behavior/PathingBehavior.java | 1 + src/main/java/baritone/process/CustomGoalProcess.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 9582f3c5..d2a55127 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -87,6 +87,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, dispatchEvents(); if (event.getType() == TickEvent.Type.OUT) { secretInternalSegmentCancel(); + baritone.getPathingControlManager().cancelEverything(); return; } tickPath(); diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index 52769f25..1e1b7473 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -82,7 +82,7 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG if (calcFailed) { onLostControl(); } - if (goal.isInGoal(playerFeet())) { + if (goal == null || goal.isInGoal(playerFeet())) { onLostControl(); // we're there xd } return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); From 52246e41c86ecba00b710b86544bd2babad60777 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 15:16:23 -0800 Subject: [PATCH 13/29] appease codacy --- src/main/java/baritone/utils/PathingControlManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index bfb84d3c..6d91b734 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -28,6 +28,7 @@ import net.minecraft.util.math.BlockPos; import java.util.Comparator; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; public class PathingControlManager { @@ -126,7 +127,7 @@ public class PathingControlManager { proc.onLostControl(); } } else { - exec = proc.onTick(proc == inControlLastTick && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel()); + exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel()); if (exec == null) { if (proc.isActive()) { throw new IllegalStateException(proc.displayName()); From 5692e79e021eaca2fe0671fa891747c53fc1f7e7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 15:25:19 -0800 Subject: [PATCH 14/29] more docs --- .../java/baritone/api/process/IBaritoneProcess.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/process/IBaritoneProcess.java b/src/api/java/baritone/api/process/IBaritoneProcess.java index d05bd8ef..a214d06d 100644 --- a/src/api/java/baritone/api/process/IBaritoneProcess.java +++ b/src/api/java/baritone/api/process/IBaritoneProcess.java @@ -34,7 +34,7 @@ public interface IBaritoneProcess { /** * Would this process like to be in control? * - * @return + * @return true if yes */ boolean isActive(); @@ -56,7 +56,7 @@ public interface IBaritoneProcess { * and should return isActive true only if there's something in range this tick, or if the player would like to start eating this tick. * PauseForAutoEatProcess should only actually right click once onTick is called with isSafeToCancel true though. * - * @return + * @return true if temporary */ boolean isTemporary(); @@ -69,21 +69,21 @@ public interface IBaritoneProcess { /** * How to decide which Process gets control if they all report isActive? It's the one with the highest priority. * - * @return + * @return a double representing the priority */ double priority(); /** * which bot is this associated with (5000000iq forward thinking) * - * @return + * @return the IBaritone object */ IBaritone associatedWith(); /** * What this process should be displayed to the user as (maybe in a HUD? hint hint) * - * @return + * @return a display name that's suitable for a HUD (hint hint) */ String displayName(); } From 472e89239cd1f0d8e6847368e093ed62a8f2df49 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 5 Nov 2018 18:07:47 -0600 Subject: [PATCH 15/29] IBaritoneProcess javadoc update --- .../api/process/IBaritoneProcess.java | 52 +++++++++++-------- .../api/process/ICustomGoalProcess.java | 1 + .../baritone/api/process/IFollowProcess.java | 1 - .../api/process/IGetToBlockProcess.java | 1 + 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/api/java/baritone/api/process/IBaritoneProcess.java b/src/api/java/baritone/api/process/IBaritoneProcess.java index a214d06d..db7588ab 100644 --- a/src/api/java/baritone/api/process/IBaritoneProcess.java +++ b/src/api/java/baritone/api/process/IBaritoneProcess.java @@ -18,6 +18,8 @@ package baritone.api.process; import baritone.api.IBaritone; +import baritone.api.behavior.IPathingBehavior; +import baritone.api.event.events.PathEvent; /** * A process that can control the PathingBehavior. @@ -31,59 +33,67 @@ import baritone.api.IBaritone; * @author leijurv */ public interface IBaritoneProcess { + /** * Would this process like to be in control? * - * @return true if yes + * @return Whether or not this process would like to be in contorl. */ boolean isActive(); /** - * This process is in control of pathing. What should Baritone do? + * Called when this process is in control of pathing; Returns what Baritone should do. * - * @param calcFailed true if this specific process was in control last tick, and there was a CALC_FAILED event last tick - * @param isSafeToCancel true if a REQUEST_PAUSE would happen this tick, and PathingBehavior wouldn't actually tick. - * false if the PathExecutor reported pausing would be unsafe at the end of the last tick. - * Effectively "could request cancel or pause and have it happen right away" - * @return what the PathingBehavior should do + * @param calcFailed {@code true} if this specific process was in control last tick, + * and there was a {@link PathEvent#CALC_FAILED} event last tick + * @param isSafeToCancel {@code true} if a {@link PathingCommandType#REQUEST_PAUSE} would happen this tick, and + * {@link IPathingBehavior} wouldn't actually tick. {@code false} if the PathExecutor reported + * pausing would be unsafe at the end of the last tick. Effectively "could request cancel or + * pause and have it happen right away" + * @return What the {@link IPathingBehavior} should do */ PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel); /** - * Is this control temporary? - * If a process is temporary, it doesn't call onLostControl on the processes that aren't execute because of it - * For example, CombatPauserProcess and PauseForAutoEatProcess should return isTemporary true always, - * and should return isActive true only if there's something in range this tick, or if the player would like to start eating this tick. - * PauseForAutoEatProcess should only actually right click once onTick is called with isSafeToCancel true though. + * Returns whether or not this process should be treated as "temporary". + *

+ * If a process is temporary, it doesn't call {@link #onLostControl} on the processes that aren't execute because of it. + *

+ * For example, {@code CombatPauserProcess} and {@code PauseForAutoEatProcess} should return {@code true} always, + * and should return {@link #isActive} {@code true} only if there's something in range this tick, or if the player would like + * to start eating this tick. {@code PauseForAutoEatProcess} should only actually right click once onTick is called with + * {@code isSafeToCancel} true though. * - * @return true if temporary + * @return Whethor or not if this control is temporary */ boolean isTemporary(); /** - * Called if isActive returned true, but another non-temporary process has control. Effectively the same as cancel. - * You want control but you don't get it. + * Called if {@link #isActive} returned {@code true}, but another non-temporary + * process has control. Effectively the same as cancel. You want control but you + * don't get it. */ void onLostControl(); /** - * How to decide which Process gets control if they all report isActive? It's the one with the highest priority. + * Used to determine which Process gains control if multiple are reporting {@link #isActive()}. The one + * that returns the highest value will be given control. * - * @return a double representing the priority + * @return A double representing the priority */ double priority(); /** - * which bot is this associated with (5000000iq forward thinking) + * Returns which bot this process is associated with. (5000000iq forward thinking) * - * @return the IBaritone object + * @return The Bot associated with this process */ IBaritone associatedWith(); /** - * What this process should be displayed to the user as (maybe in a HUD? hint hint) + * Returns a user-friendly name for this process. Suitable for a HUD. * - * @return a display name that's suitable for a HUD (hint hint) + * @return A display name that's suitable for a HUD */ String displayName(); } diff --git a/src/api/java/baritone/api/process/ICustomGoalProcess.java b/src/api/java/baritone/api/process/ICustomGoalProcess.java index c3492df9..0484d4c5 100644 --- a/src/api/java/baritone/api/process/ICustomGoalProcess.java +++ b/src/api/java/baritone/api/process/ICustomGoalProcess.java @@ -20,6 +20,7 @@ package baritone.api.process; import baritone.api.pathing.goals.Goal; public interface ICustomGoalProcess extends IBaritoneProcess { + void setGoal(Goal goal); void path(); diff --git a/src/api/java/baritone/api/process/IFollowProcess.java b/src/api/java/baritone/api/process/IFollowProcess.java index 262ce43f..cb9ecde6 100644 --- a/src/api/java/baritone/api/process/IFollowProcess.java +++ b/src/api/java/baritone/api/process/IFollowProcess.java @@ -17,7 +17,6 @@ package baritone.api.process; -import baritone.api.process.IBaritoneProcess; import net.minecraft.entity.Entity; /** diff --git a/src/api/java/baritone/api/process/IGetToBlockProcess.java b/src/api/java/baritone/api/process/IGetToBlockProcess.java index feaeb747..ff3dc9b5 100644 --- a/src/api/java/baritone/api/process/IGetToBlockProcess.java +++ b/src/api/java/baritone/api/process/IGetToBlockProcess.java @@ -23,5 +23,6 @@ import net.minecraft.block.Block; * but it rescans the world every once in a while so it doesn't get fooled by its cache */ public interface IGetToBlockProcess extends IBaritoneProcess { + void getToBlock(Block block); } From fdee1b94534114a4e0a589952a107b2950401244 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 5 Nov 2018 18:11:16 -0600 Subject: [PATCH 16/29] More javadocs --- .../java/baritone/api/process/PathingCommand.java | 2 ++ .../baritone/api/process/PathingCommandType.java | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/process/PathingCommand.java b/src/api/java/baritone/api/process/PathingCommand.java index 082928b3..0d0d7db3 100644 --- a/src/api/java/baritone/api/process/PathingCommand.java +++ b/src/api/java/baritone/api/process/PathingCommand.java @@ -20,7 +20,9 @@ package baritone.api.process; import baritone.api.pathing.goals.Goal; public class PathingCommand { + public final Goal goal; + public final PathingCommandType commandType; public PathingCommand(Goal goal, PathingCommandType commandType) { diff --git a/src/api/java/baritone/api/process/PathingCommandType.java b/src/api/java/baritone/api/process/PathingCommandType.java index 98517ba5..f2336d26 100644 --- a/src/api/java/baritone/api/process/PathingCommandType.java +++ b/src/api/java/baritone/api/process/PathingCommandType.java @@ -17,11 +17,14 @@ package baritone.api.process; +import baritone.api.Settings; + public enum PathingCommandType { + /** * Set the goal and path. *

- * If you use this alongside a null goal, it will continue along its current path and current goal. + * If you use this alongside a {@code null} goal, it will continue along its current path and current goal. */ SET_GOAL_AND_PATH, @@ -31,21 +34,22 @@ public enum PathingCommandType { REQUEST_PAUSE, /** - * Set the goal (regardless of null), and request a cancel of the current path (when safe) + * Set the goal (regardless of {@code null}), and request a cancel of the current path (when safe) */ CANCEL_AND_SET_GOAL, /** * Set the goal and path. *

- * If cancelOnGoalInvalidation is true, revalidate the current goal, and cancel if it's no longer valid, or if the new goal is null. + * If {@link Settings#cancelOnGoalInvalidation} is {@code true}, revalidate the + * current goal, and cancel if it's no longer valid, or if the new goal is {@code null}. */ REVALIDATE_GOAL_AND_PATH, /** * Set the goal and path. *

- * Revalidate the current goal, and cancel if it's no longer valid, or if the new goal is null. + * Revalidate the current goal, and cancel if it's no longer valid, or if the new goal is {@code null}. */ - FORCE_REVALIDATE_GOAL_AND_PATH, + FORCE_REVALIDATE_GOAL_AND_PATH } From ebd3ce42d04ee8ca52d6d1af3451ff653d960ca6 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 5 Nov 2018 18:28:29 -0600 Subject: [PATCH 17/29] whoops --- src/api/java/baritone/api/behavior/IPathingBehavior.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/behavior/IPathingBehavior.java b/src/api/java/baritone/api/behavior/IPathingBehavior.java index 622c453a..c8728965 100644 --- a/src/api/java/baritone/api/behavior/IPathingBehavior.java +++ b/src/api/java/baritone/api/behavior/IPathingBehavior.java @@ -50,11 +50,12 @@ public interface IPathingBehavior extends IBehavior { boolean isPathing(); /** - * Cancels the pathing behavior or the current path calculation. Also cancels all processes that could be controlling path. + * Cancels the pathing behavior or the current path calculation, and all processes that could be controlling path. *

* Basically, "MAKE IT STOP". * - * @return whether or not the pathing behavior was canceled. All processes are guaranteed to be canceled, but the PathingBehavior might be in the middle of an uncancelable action like a parkour jump + * @return Whether or not the pathing behavior was canceled. All processes are guaranteed to be canceled, but the + * PathingBehavior might be in the middle of an uncancelable action like a parkour jump */ boolean cancelEverything(); From 99da815f49fe1bd4bcbc7314cac3a37e44312371 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 5 Nov 2018 18:40:25 -0600 Subject: [PATCH 18/29] Massive brain --- .../api/process/ICustomGoalProcess.java | 22 ++++++- .../baritone/process/CustomGoalProcess.java | 58 ++++++++++++------- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/api/java/baritone/api/process/ICustomGoalProcess.java b/src/api/java/baritone/api/process/ICustomGoalProcess.java index 0484d4c5..5084aff2 100644 --- a/src/api/java/baritone/api/process/ICustomGoalProcess.java +++ b/src/api/java/baritone/api/process/ICustomGoalProcess.java @@ -21,12 +21,30 @@ import baritone.api.pathing.goals.Goal; public interface ICustomGoalProcess extends IBaritoneProcess { + /** + * Sets the pathing goal + * + * @param goal The new goal + */ void setGoal(Goal goal); + /** + * Starts path calculation and execution. + */ void path(); + /** + * @return The current goal + */ + Goal getGoal(); + + /** + * Sets the goal and begins the path execution. + * + * @param goal The new goal + */ default void setGoalAndPath(Goal goal) { - setGoal(goal); - path(); + this.setGoal(goal); + this.path(); } } diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index 1e1b7473..8b3d1773 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -32,7 +32,17 @@ import java.util.Objects; * @author leijurv */ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess { + + /** + * The current goal + */ private Goal goal; + + /** + * The current process state. + * + * @see State + */ private State state; public CustomGoalProcess(Baritone baritone) { @@ -42,50 +52,47 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG @Override public void setGoal(Goal goal) { this.goal = goal; - state = State.GOAL_SET; + this.state = State.GOAL_SET; } @Override public void path() { - if (goal == null) { - goal = baritone.getPathingBehavior().getGoal(); + if (this.goal == null) { + this.goal = baritone.getPathingBehavior().getGoal(); } - state = State.PATH_REQUESTED; + this.state = State.PATH_REQUESTED; } - private enum State { - NONE, - GOAL_SET, - PATH_REQUESTED, - EXECUTING, - + @Override + public Goal getGoal() { + return this.goal; } @Override public boolean isActive() { - return state != State.NONE; + return this.state != State.NONE; } @Override public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { - switch (state) { + switch (this.state) { case GOAL_SET: - if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), goal)) { - state = State.NONE; + if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), this.goal)) { + this.state = State.NONE; } - return new PathingCommand(goal, PathingCommandType.CANCEL_AND_SET_GOAL); + return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL); case PATH_REQUESTED: - PathingCommand ret = new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); - state = State.EXECUTING; + PathingCommand ret = new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH); + this.state = State.EXECUTING; return ret; case EXECUTING: if (calcFailed) { onLostControl(); } - if (goal == null || goal.isInGoal(playerFeet())) { + if (this.goal == null || this.goal.isInGoal(playerFeet())) { onLostControl(); // we're there xd } - return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH); + return new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH); default: throw new IllegalStateException(); } @@ -93,12 +100,19 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG @Override public void onLostControl() { - state = State.NONE; - goal = null; + this.state = State.NONE; + this.goal = null; } @Override public String displayName() { - return "Custom Goal " + goal; + return "Custom Goal " + this.goal; + } + + protected enum State { + NONE, + GOAL_SET, + PATH_REQUESTED, + EXECUTING } } From 2aee91be102db254026d090413480947160a37d8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 16:46:24 -0800 Subject: [PATCH 19/29] fix it up a bit --- .../baritone/process/CustomGoalProcess.java | 3 --- .../utils/ExampleBaritoneControl.java | 20 +++++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index 8b3d1773..98c700e3 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -57,9 +57,6 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG @Override public void path() { - if (this.goal == null) { - this.goal = baritone.getPathingBehavior().getGoal(); - } this.state = State.PATH_REQUESTED; } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 74c17d60..e908d1c4 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -100,7 +100,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { public boolean runCommand(String msg0) { String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL PathingBehavior pathingBehavior = baritone.getPathingBehavior(); - CustomGoalProcess CGPgrey = baritone.getCustomGoalProcess(); + CustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); List> toggleable = Baritone.settings().getAllValuesByType(Boolean.class); for (Settings.Setting setting : toggleable) { if (msg.equalsIgnoreCase(setting.getName())) { @@ -188,7 +188,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("unable to parse integer " + ex); return true; } - CGPgrey.setGoal(goal); + customGoalProcess.setGoal(goal); logDirect("Goal: " + goal); return true; } @@ -200,7 +200,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } else if (pathingBehavior.isPathing()) { logDirect("Currently executing a path. Please cancel it first."); } else { - CGPgrey.path(); + customGoalProcess.setGoalAndPath(pathingBehavior.getGoal()); } return true; } @@ -222,7 +222,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("axis")) { - CGPgrey.setGoalAndPath(new GoalAxis()); + customGoalProcess.setGoalAndPath(new GoalAxis()); return true; } if (msg.equals("cancel") || msg.equals("stop")) { @@ -254,7 +254,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("Inverting goal of player feet"); runAwayFrom = playerFeet(); } - CGPgrey.setGoalAndPath(new GoalRunAway(1, runAwayFrom) { + customGoalProcess.setGoalAndPath(new GoalRunAway(1, runAwayFrom) { @Override public boolean isInGoal(int x, int y, int z) { return false; @@ -329,7 +329,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { if (msg.startsWith("thisway")) { try { Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim())); - CGPgrey.setGoal(goal); + customGoalProcess.setGoal(goal); logDirect("Goal: " + goal); } catch (NumberFormatException ex) { logDirect("Error unable to parse '" + msg.substring(7).trim() + "' to a double."); @@ -409,7 +409,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } } Goal goal = new GoalBlock(waypoint.getLocation()); - CGPgrey.setGoalAndPath(goal); + customGoalProcess.setGoalAndPath(goal); return true; } if (msg.equals("spawn") || msg.equals("bed")) { @@ -419,10 +419,10 @@ public class ExampleBaritoneControl extends Behavior implements Helper { // for some reason the default spawnpoint is underground sometimes Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ()); logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal); - CGPgrey.setGoalAndPath(goal); + customGoalProcess.setGoalAndPath(goal); } else { Goal goal = new GoalGetToBlock(waypoint.getLocation()); - CGPgrey.setGoalAndPath(goal); + customGoalProcess.setGoalAndPath(goal); logDirect("Set goal to most recent bed " + goal); } return true; @@ -438,7 +438,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("home not saved"); } else { Goal goal = new GoalBlock(waypoint.getLocation()); - CGPgrey.setGoalAndPath(goal); + customGoalProcess.setGoalAndPath(goal); logDirect("Going to saved home " + goal); } return true; From d121ca182f2dedc08c3ec20c774caf61d13c5968 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 17:26:49 -0800 Subject: [PATCH 20/29] spammy --- src/main/java/baritone/utils/PathingControlManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 6d91b734..e75f7796 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -135,7 +135,7 @@ public class PathingControlManager { proc.onLostControl(); continue; } - System.out.println("Executing command " + exec.commandType + " " + exec.goal + " from " + proc.displayName()); + //System.out.println("Executing command " + exec.commandType + " " + exec.goal + " from " + proc.displayName()); inControlThisTick = proc; found = true; cancelOthers = !proc.isTemporary(); From a1b71219cbbe9426e18aa4f68a20e4ddfb18d1ed Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 18:31:59 -0800 Subject: [PATCH 21/29] make sure to pick up dropped items while mining, fixes #170 --- src/api/java/baritone/api/Settings.java | 7 +++- .../baritone/process/GetToBlockProcess.java | 2 +- .../java/baritone/process/MineProcess.java | 42 +++++++++++++++---- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 0d8529dd..6fbd14c6 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -24,8 +24,8 @@ import net.minecraft.util.text.ITextComponent; import java.awt.*; import java.lang.reflect.Field; -import java.util.List; import java.util.*; +import java.util.List; import java.util.function.Consumer; /** @@ -376,6 +376,11 @@ public class Settings { */ public Setting mineGoalUpdateInterval = new Setting<>(5); + /** + * While mining, should it also consider dropped items of the correct type as a pathing destination (as well as ore blocks)? + */ + public Setting mineScanDroppedItems = new Setting<>(true); + /** * Cancel the current path if the goal has changed, and the path originally ended in the goal but doesn't anymore. *

diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 7f5340ed..d35b4fb4 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -94,6 +94,6 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } private void rescan() { - knownLocations = MineProcess.searchWorld(Collections.singletonList(gettingTo), 64); + knownLocations = MineProcess.searchWorld(Collections.singletonList(gettingTo), 64, world()); } } \ No newline at end of file diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 2efeca03..e4f3db21 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -32,10 +32,13 @@ import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import net.minecraft.world.chunk.EmptyChunk; import java.util.*; @@ -112,7 +115,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro private Goal updateGoal() { List locs = knownOreLocations; if (!locs.isEmpty()) { - List locs2 = prune(new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT); + List locs2 = prune(new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT, world()); // can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new)); knownOreLocations = locs2; @@ -147,7 +150,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro if (Baritone.settings().legitMine.get()) { return; } - List locs = searchWorld(mining, ORE_LOCATIONS_COUNT); + List locs = searchWorld(mining, ORE_LOCATIONS_COUNT, world()); + locs.addAll(droppedItemsScan(mining, world())); if (locs.isEmpty()) { logDebug("No locations for " + mining + " known, cancelling"); cancel(); @@ -178,7 +182,30 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } - public static List searchWorld(List mining, int max) { + public static List droppedItemsScan(List mining, World world) { + if (!Baritone.settings().mineScanDroppedItems.get()) { + return new ArrayList<>(); + } + Set searchingFor = new HashSet<>(); + for (Block block : mining) { + Item drop = block.getItemDropped(block.getDefaultState(), new Random(), 0); + Item ore = Item.getItemFromBlock(block); + searchingFor.add(drop); + searchingFor.add(ore); + } + List ret = new ArrayList<>(); + for (Entity entity : world.loadedEntityList) { + if (entity instanceof EntityItem) { + EntityItem ei = (EntityItem) entity; + if (searchingFor.contains(ei.getItem().getItem())) { + ret.add(entity.getPosition()); + } + } + } + return ret; + } + + public static List searchWorld(List mining, int max, World world) { List locs = new ArrayList<>(); List uninteresting = new ArrayList<>(); //long b = System.currentTimeMillis(); @@ -198,7 +225,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(uninteresting, max, 10, 26)); //System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms"); } - return prune(locs, mining, max); + return prune(locs, mining, max, world); } public void addNearby() { @@ -214,15 +241,16 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } } - knownOreLocations = prune(knownOreLocations, mining, ORE_LOCATIONS_COUNT); + knownOreLocations = prune(knownOreLocations, mining, ORE_LOCATIONS_COUNT, world()); } - public static List prune(List locs2, List mining, int max) { + public static List prune(List locs2, List mining, int max, World world) { + List dropped = droppedItemsScan(mining, world); List locs = locs2 .stream() // remove any that are within loaded chunks that aren't actually what we want - .filter(pos -> Helper.HELPER.world().getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock())) + .filter(pos -> world.getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock()) || dropped.contains(pos)) // remove any that are implausible to mine (encased in bedrock, or touching lava) .filter(MineProcess::plausibleToBreak) From 6ca7f47bf9de5f54a9f17c8404482d123ff76fb7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 19:31:05 -0800 Subject: [PATCH 22/29] +0.5y not helpful --- src/main/java/baritone/process/MineProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index e4f3db21..bfceac75 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -198,7 +198,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro if (entity instanceof EntityItem) { EntityItem ei = (EntityItem) entity; if (searchingFor.contains(ei.getItem().getItem())) { - ret.add(entity.getPosition()); + ret.add(new BlockPos(entity)); } } } From 604ef2bb64e98c61d6201e3c41fa9336bfc04be0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 20:01:46 -0800 Subject: [PATCH 23/29] misc cleanup --- src/main/java/baritone/Baritone.java | 14 +++++++------- .../java/baritone/behavior/PathingBehavior.java | 4 ++-- src/main/java/baritone/cache/CachedWorld.java | 4 ++-- src/main/java/baritone/cache/WorldData.java | 2 +- src/main/java/baritone/cache/WorldProvider.java | 4 ++-- src/main/java/baritone/event/GameEventHandler.java | 8 +++++++- .../java/baritone/pathing/movement/Movement.java | 6 ------ .../java/baritone/process/GetToBlockProcess.java | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 50320289..69dc1b2a 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -67,7 +67,7 @@ public enum Baritone implements IBaritone { private GameEventHandler gameEventHandler; private Settings settings; private File dir; - private ThreadPoolExecutor threadPool; + private List behaviors; private PathingBehavior pathingBehavior; @@ -82,16 +82,16 @@ public enum Baritone implements IBaritone { private PathingControlManager pathingControlManager; + private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); + Baritone() { - this.gameEventHandler = new GameEventHandler(); + this.gameEventHandler = new GameEventHandler(this); } public synchronized void init() { if (initialized) { return; } - this.threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); - // Acquire the "singleton" instance of the settings directly from the API // We might want to change this... @@ -148,7 +148,7 @@ public enum Baritone implements IBaritone { return this.behaviors; } - public Executor getExecutor() { + public static Executor getExecutor() { return threadPool; } @@ -215,7 +215,7 @@ public enum Baritone implements IBaritone { return Baritone.INSTANCE.settings; // yolo } - public File getDir() { - return this.dir; + public static File getDir() { + return Baritone.INSTANCE.dir; // should be static I guess } } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index d2a55127..77c9839d 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -78,7 +78,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, toDispatch.drainTo(curr); calcFailedLastTick = curr.contains(PathEvent.CALC_FAILED); for (PathEvent event : curr) { - Baritone.INSTANCE.getGameEventHandler().onPathEvent(event); + baritone.getGameEventHandler().onPathEvent(event); } } @@ -370,7 +370,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, isPathCalcInProgress = true; } CalculationContext context = new CalculationContext(); // not safe to create on the other thread, it looks up a lot of stuff in minecraft - Baritone.INSTANCE.getExecutor().execute(() -> { + Baritone.getExecutor().execute(() -> { if (talkAboutIt) { logDebug("Starting to search for path from " + start + " to " + goal); } diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index 14b66839..48e4ccb2 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -67,8 +67,8 @@ public final class CachedWorld implements ICachedWorld, Helper { System.out.println("Cached world directory: " + directory); // Insert an invalid region element cachedRegions.put(0, null); - Baritone.INSTANCE.getExecutor().execute(new PackerThread()); - Baritone.INSTANCE.getExecutor().execute(() -> { + Baritone.getExecutor().execute(new PackerThread()); + Baritone.getExecutor().execute(() -> { try { Thread.sleep(30000); while (true) { diff --git a/src/main/java/baritone/cache/WorldData.java b/src/main/java/baritone/cache/WorldData.java index b489d933..36a239fa 100644 --- a/src/main/java/baritone/cache/WorldData.java +++ b/src/main/java/baritone/cache/WorldData.java @@ -43,7 +43,7 @@ public class WorldData implements IWorldData { } public void onClose() { - Baritone.INSTANCE.getExecutor().execute(() -> { + Baritone.getExecutor().execute(() -> { System.out.println("Started saving the world in a new thread"); cache.save(); }); diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index 2aef54c6..e3a53bba 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -74,8 +74,8 @@ public enum WorldProvider implements IWorldProvider, Helper { } else { //remote - directory = new File(Baritone.INSTANCE.getDir(), mc.getCurrentServerData().serverIP); - readme = Baritone.INSTANCE.getDir(); + directory = new File(Baritone.getDir(), mc.getCurrentServerData().serverIP); + readme = Baritone.getDir(); } // lol wtf is this baritone folder in my minecraft save? try (FileOutputStream out = new FileOutputStream(new File(readme, "readme.txt"))) { diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index e7cd5847..fd031a0a 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -37,8 +37,14 @@ import java.util.ArrayList; */ public final class GameEventHandler implements IGameEventListener, Helper { + private final Baritone baritone; + private final ArrayList listeners = new ArrayList<>(); + public GameEventHandler(Baritone baritone) { + this.baritone = baritone; + } + @Override public final void onTick(TickEvent event) { listeners.forEach(l -> l.onTick(event)); @@ -51,7 +57,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onProcessKeyBinds() { - InputOverrideHandler inputHandler = Baritone.INSTANCE.getInputOverrideHandler(); + InputOverrideHandler inputHandler = baritone.getInputOverrideHandler(); // Simulate the key being held down this tick for (InputOverrideHandler.Input input : InputOverrideHandler.Input.values()) { diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index aacd7f9f..0bdedbf0 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -226,12 +226,6 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { state.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced)); } - public void cancel() { - currentState.getInputStates().replaceAll((input, forced) -> false); - currentState.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced)); - currentState.setStatus(MovementStatus.CANCELED); - } - @Override public void reset() { currentState = new MovementState().setStatus(MovementStatus.PREPPING); diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index d35b4fb4..94e02e03 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -73,7 +73,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain - Baritone.INSTANCE.getExecutor().execute(this::rescan); + Baritone.getExecutor().execute(this::rescan); } Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)); if (goal.isInGoal(playerFeet())) { From aac0d623fa238f0c8b7eed1ed10028ea5b6c1145 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 20:02:27 -0800 Subject: [PATCH 24/29] why not just... --- src/launch/java/baritone/launch/mixins/MixinMinecraft.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index b559ae86..3826f0d7 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -83,10 +83,9 @@ public class MixinMinecraft { ) ) private void runTick(CallbackInfo ci) { - Minecraft mc = (Minecraft) (Object) this; Baritone.INSTANCE.getGameEventHandler().onTick(new TickEvent( EventState.PRE, - (mc.player != null && mc.world != null) + (player != null && world != null) ? TickEvent.Type.IN : TickEvent.Type.OUT )); From a182c22d369315d95207a741ed6b67c04b5fea16 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 20:05:47 -0800 Subject: [PATCH 25/29] this can be moved i think --- .../java/baritone/event/GameEventHandler.java | 18 ------------------ .../baritone/utils/InputOverrideHandler.java | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index fd031a0a..1de1b728 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -24,10 +24,7 @@ import baritone.api.event.listener.IGameEventListener; import baritone.cache.WorldProvider; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; -import baritone.utils.InputOverrideHandler; -import net.minecraft.client.settings.KeyBinding; import net.minecraft.world.chunk.Chunk; -import org.lwjgl.input.Keyboard; import java.util.ArrayList; @@ -57,21 +54,6 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onProcessKeyBinds() { - InputOverrideHandler inputHandler = baritone.getInputOverrideHandler(); - - // Simulate the key being held down this tick - for (InputOverrideHandler.Input input : InputOverrideHandler.Input.values()) { - KeyBinding keyBinding = input.getKeyBinding(); - - if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) { - int keyCode = keyBinding.getKeyCode(); - - if (keyCode < Keyboard.KEYBOARD_SIZE) { - KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode); - } - } - } - listeners.forEach(l -> l.onProcessKeyBinds()); } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 4d325fc7..f7239d0b 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.behavior.Behavior; import net.minecraft.client.settings.KeyBinding; +import org.lwjgl.input.Keyboard; import java.util.HashMap; import java.util.Map; @@ -67,6 +68,22 @@ public final class InputOverrideHandler extends Behavior implements Helper { inputForceStateMap.put(input.getKeyBinding(), forced); } + @Override + public final void onProcessKeyBinds() { + // Simulate the key being held down this tick + for (InputOverrideHandler.Input input : Input.values()) { + KeyBinding keyBinding = input.getKeyBinding(); + + if (isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) { + int keyCode = keyBinding.getKeyCode(); + + if (keyCode < Keyboard.KEYBOARD_SIZE) { + KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode); + } + } + } + } + /** * An {@link Enum} representing the possible inputs that we may want to force. */ From 527691a2ec803ff05c80d2f8aba333c4e183d899 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 20:37:54 -0800 Subject: [PATCH 26/29] fix blockbreakhelper toxic cloud in movement --- .../baritone/pathing/movement/Movement.java | 47 ++++--------------- .../java/baritone/utils/BlockBreakHelper.java | 20 +++++++- .../baritone/utils/InputOverrideHandler.java | 12 +++++ 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 0bdedbf0..fb316ed3 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -24,14 +24,12 @@ import baritone.api.utils.BetterBlockPos; import baritone.api.utils.Rotation; import baritone.api.utils.RotationUtils; import baritone.api.utils.VecUtils; -import baritone.utils.BlockBreakHelper; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.InputOverrideHandler; import net.minecraft.block.BlockLiquid; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.chunk.EmptyChunk; import java.util.ArrayList; @@ -115,52 +113,31 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { @Override public MovementStatus update() { player().capabilities.isFlying = false; - MovementState latestState = updateState(currentState); + currentState = updateState(currentState); if (MovementHelper.isLiquid(playerFeet())) { - latestState.setInput(Input.JUMP, true); + currentState.setInput(Input.JUMP, true); } if (player().isEntityInsideOpaqueBlock()) { - latestState.setInput(Input.CLICK_LEFT, true); + currentState.setInput(Input.CLICK_LEFT, true); } // If the movement target has to force the new rotations, or we aren't using silent move, then force the rotations - latestState.getTarget().getRotation().ifPresent(rotation -> + currentState.getTarget().getRotation().ifPresent(rotation -> Baritone.INSTANCE.getLookBehavior().updateTarget( rotation, - latestState.getTarget().hasToForceRotations())); + currentState.getTarget().hasToForceRotations())); // TODO: calculate movement inputs from latestState.getGoal().position // latestState.getTarget().position.ifPresent(null); NULL CONSUMER REALLY SHOULDN'T BE THE FINAL THING YOU SHOULD REALLY REPLACE THIS WITH ALMOST ACTUALLY ANYTHING ELSE JUST PLEASE DON'T LEAVE IT AS IT IS THANK YOU KANYE - this.didBreakLastTick = false; - - latestState.getInputStates().forEach((input, forced) -> { - if (Baritone.settings().leftClickWorkaround.get()) { - RayTraceResult trace = mc.objectMouseOver; - boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK; - boolean isLeftClick = forced && input == Input.CLICK_LEFT; - - // If we're forcing left click, we're in a gui screen, and we're looking - // at a block, break the block without a direct game input manipulation. - if (mc.currentScreen != null && isLeftClick && isBlockTrace) { - BlockBreakHelper.tryBreakBlock(trace.getBlockPos(), trace.sideHit); - this.didBreakLastTick = true; - return; - } - } + currentState.getInputStates().forEach((input, forced) -> { Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced); }); - latestState.getInputStates().replaceAll((input, forced) -> false); - - if (!this.didBreakLastTick) { - BlockBreakHelper.stopBreakingBlock(); - } - - currentState = latestState; + currentState.getInputStates().replaceAll((input, forced) -> false); // If the current status indicates a completed movement if (currentState.getStatus().isComplete()) { - onFinish(latestState); + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); } return currentState.getStatus(); @@ -218,14 +195,6 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { return dest; } - /** - * Run cleanup on state finish and declare success. - */ - public void onFinish(MovementState state) { - state.getInputStates().replaceAll((input, forced) -> false); - state.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced)); - } - @Override public void reset() { currentState = new MovementState().setStatus(MovementStatus.PREPPING); diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index 1bc4a44a..b1e9ae53 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -20,6 +20,7 @@ package baritone.utils; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; /** * @author Brady @@ -32,6 +33,7 @@ public final class BlockBreakHelper implements Helper { * between attempts, then we re-initialize the breaking process. */ private static BlockPos lastBlock; + private static boolean didBreakLastTick; private BlockBreakHelper() {} @@ -48,7 +50,23 @@ public final class BlockBreakHelper implements Helper { public static void stopBreakingBlock() { if (mc.playerController != null) { mc.playerController.resetBlockRemoving(); - } + } lastBlock = null; } + + public static boolean tick(boolean isLeftClick) { + RayTraceResult trace = mc.objectMouseOver; + boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK; + + // If we're forcing left click, we're in a gui screen, and we're looking + // at a block, break the block without a direct game input manipulation. + if (mc.currentScreen != null && isLeftClick && isBlockTrace) { + tryBreakBlock(trace.getBlockPos(), trace.sideHit); + didBreakLastTick = true; + } else if (didBreakLastTick) { + stopBreakingBlock(); + didBreakLastTick = false; + } + return !didBreakLastTick && isLeftClick; + } } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index f7239d0b..b42b0ee1 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -18,6 +18,7 @@ package baritone.utils; import baritone.Baritone; +import baritone.api.event.events.TickEvent; import baritone.behavior.Behavior; import net.minecraft.client.settings.KeyBinding; import org.lwjgl.input.Keyboard; @@ -84,6 +85,17 @@ public final class InputOverrideHandler extends Behavior implements Helper { } } + @Override + public final void onTick(TickEvent event) { + if (event.getType() == TickEvent.Type.OUT) { + return; + } + if (Baritone.settings().leftClickWorkaround.get()) { + boolean stillClick = BlockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT.keyBinding)); + setInputForceState(Input.CLICK_LEFT, stillClick); + } + } + /** * An {@link Enum} representing the possible inputs that we may want to force. */ From c50af5acfd5239181ed96e663307e5784e341415 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 6 Nov 2018 08:02:08 -0600 Subject: [PATCH 27/29] A couple minor cleanups --- .../java/baritone/api/IBaritoneProvider.java | 13 ++++++++- .../baritone/api/process/PathingCommand.java | 28 +++++++++++++++++-- .../java/baritone/event/GameEventHandler.java | 7 +++-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index 9bd96e7e..745842ce 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -19,6 +19,17 @@ package baritone.api; import net.minecraft.client.entity.EntityPlayerSP; +/** + * @author Leijurv + */ public interface IBaritoneProvider { - IBaritone getBaritoneForPlayer(EntityPlayerSP player); // tenor be like + + /** + * Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be + * replaced with {@code #getBaritoneForUser(IBaritoneUser)} when {@code bot-system} is merged. + * + * @param player The player + * @return The {@link IBaritone} instance. + */ + IBaritone getBaritoneForPlayer(EntityPlayerSP player); } diff --git a/src/api/java/baritone/api/process/PathingCommand.java b/src/api/java/baritone/api/process/PathingCommand.java index 0d0d7db3..753e1a2d 100644 --- a/src/api/java/baritone/api/process/PathingCommand.java +++ b/src/api/java/baritone/api/process/PathingCommand.java @@ -19,17 +19,39 @@ package baritone.api.process; import baritone.api.pathing.goals.Goal; +import java.util.Objects; + +/** + * @author Leijurv + */ public class PathingCommand { + /** + * The target goal, may be {@code null}. + */ public final Goal goal; + /** + * The command type. + * + * @see PathingCommandType + */ public final PathingCommandType commandType; + /** + * Create a new {@link PathingCommand}. + * + * @see Goal + * @see PathingCommandType + * + * @param goal The target goal, may be {@code null}. + * @param commandType The command type, cannot be {@code null}. + * @throws NullPointerException if {@code commandType} is {@code null}. + */ public PathingCommand(Goal goal, PathingCommandType commandType) { + Objects.requireNonNull(commandType); + this.goal = goal; this.commandType = commandType; - if (commandType == null) { - throw new IllegalArgumentException(); - } } } diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index 1de1b728..b42b3e06 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -27,6 +27,7 @@ import baritone.utils.Helper; import net.minecraft.world.chunk.Chunk; import java.util.ArrayList; +import java.util.List; /** * @author Brady @@ -36,7 +37,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { private final Baritone baritone; - private final ArrayList listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); public GameEventHandler(Baritone baritone) { this.baritone = baritone; @@ -54,7 +55,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onProcessKeyBinds() { - listeners.forEach(l -> l.onProcessKeyBinds()); + listeners.forEach(IGameEventListener::onProcessKeyBinds); } @Override @@ -131,7 +132,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public void onPlayerDeath() { - listeners.forEach(l -> l.onPlayerDeath()); + listeners.forEach(IGameEventListener::onPlayerDeath); } @Override From ae200a56b008782bd1131c607597ffa47cb9cb94 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 6 Nov 2018 08:19:26 -0800 Subject: [PATCH 28/29] CaPiTaLiZe --- src/api/java/baritone/api/process/PathingCommand.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/process/PathingCommand.java b/src/api/java/baritone/api/process/PathingCommand.java index 753e1a2d..2caef158 100644 --- a/src/api/java/baritone/api/process/PathingCommand.java +++ b/src/api/java/baritone/api/process/PathingCommand.java @@ -22,7 +22,7 @@ import baritone.api.pathing.goals.Goal; import java.util.Objects; /** - * @author Leijurv + * @author leijurv */ public class PathingCommand { @@ -41,12 +41,11 @@ public class PathingCommand { /** * Create a new {@link PathingCommand}. * - * @see Goal - * @see PathingCommandType - * - * @param goal The target goal, may be {@code null}. + * @param goal The target goal, may be {@code null}. * @param commandType The command type, cannot be {@code null}. * @throws NullPointerException if {@code commandType} is {@code null}. + * @see Goal + * @see PathingCommandType */ public PathingCommand(Goal goal, PathingCommandType commandType) { Objects.requireNonNull(commandType); From 382c7e78882267a8275102eae5dacce9452a210a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 6 Nov 2018 08:22:19 -0800 Subject: [PATCH 29/29] reformat, optimize imports --- src/api/java/baritone/api/behavior/ILookBehavior.java | 2 +- src/api/java/baritone/api/behavior/IPathingBehavior.java | 2 +- src/api/java/baritone/api/cache/ICachedRegion.java | 3 +-- src/api/java/baritone/api/cache/ICachedWorld.java | 4 ++-- src/api/java/baritone/api/cache/IWaypointCollection.java | 6 ++---- src/api/java/baritone/api/pathing/calc/IPath.java | 3 +-- .../java/baritone/launch/mixins/MixinAnvilChunkLoader.java | 4 +++- .../baritone/launch/mixins/MixinChunkProviderServer.java | 4 +++- src/launch/java/baritone/launch/mixins/MixinEntity.java | 3 ++- .../java/baritone/launch/mixins/MixinEntityRenderer.java | 2 +- .../java/baritone/launch/mixins/MixinNetworkManager.java | 3 ++- src/main/java/baritone/cache/Waypoint.java | 6 +++--- 12 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/api/java/baritone/api/behavior/ILookBehavior.java b/src/api/java/baritone/api/behavior/ILookBehavior.java index b5b5d63b..058a5dd8 100644 --- a/src/api/java/baritone/api/behavior/ILookBehavior.java +++ b/src/api/java/baritone/api/behavior/ILookBehavior.java @@ -33,7 +33,7 @@ public interface ILookBehavior extends IBehavior { * otherwise, it should be {@code false}; * * @param rotation The target rotations - * @param force Whether or not to "force" the rotations + * @param force Whether or not to "force" the rotations */ void updateTarget(Rotation rotation, boolean force); } diff --git a/src/api/java/baritone/api/behavior/IPathingBehavior.java b/src/api/java/baritone/api/behavior/IPathingBehavior.java index c8728965..e9ebe405 100644 --- a/src/api/java/baritone/api/behavior/IPathingBehavior.java +++ b/src/api/java/baritone/api/behavior/IPathingBehavior.java @@ -55,7 +55,7 @@ public interface IPathingBehavior extends IBehavior { * Basically, "MAKE IT STOP". * * @return Whether or not the pathing behavior was canceled. All processes are guaranteed to be canceled, but the - * PathingBehavior might be in the middle of an uncancelable action like a parkour jump + * PathingBehavior might be in the middle of an uncancelable action like a parkour jump */ boolean cancelEverything(); diff --git a/src/api/java/baritone/api/cache/ICachedRegion.java b/src/api/java/baritone/api/cache/ICachedRegion.java index 5f9199fa..6b9048a5 100644 --- a/src/api/java/baritone/api/cache/ICachedRegion.java +++ b/src/api/java/baritone/api/cache/ICachedRegion.java @@ -29,11 +29,10 @@ public interface ICachedRegion extends IBlockTypeAccess { * however, the block coordinates should in on a scale from 0 to 511 (inclusive) * because region sizes are 512x512 blocks. * - * @see ICachedWorld#isCached(int, int) - * * @param blockX The block X coordinate * @param blockZ The block Z coordinate * @return Whether or not the specified XZ location is cached + * @see ICachedWorld#isCached(int, int) */ boolean isCached(int blockX, int blockZ); diff --git a/src/api/java/baritone/api/cache/ICachedWorld.java b/src/api/java/baritone/api/cache/ICachedWorld.java index f8196ebb..5e06a475 100644 --- a/src/api/java/baritone/api/cache/ICachedWorld.java +++ b/src/api/java/baritone/api/cache/ICachedWorld.java @@ -61,8 +61,8 @@ public interface ICachedWorld { * information that is returned by this method may not be up to date, because * older cached chunks can contain data that is much more likely to have changed. * - * @param block The special block to search for - * @param maximum The maximum number of position results to receive + * @param block The special block to search for + * @param maximum The maximum number of position results to receive * @param maxRegionDistanceSq The maximum region distance, squared * @return The locations found that match the special block */ diff --git a/src/api/java/baritone/api/cache/IWaypointCollection.java b/src/api/java/baritone/api/cache/IWaypointCollection.java index 051b199e..4dd80a3e 100644 --- a/src/api/java/baritone/api/cache/IWaypointCollection.java +++ b/src/api/java/baritone/api/cache/IWaypointCollection.java @@ -50,19 +50,17 @@ public interface IWaypointCollection { /** * Gets all of the waypoints that have the specified tag * - * @see IWaypointCollection#getAllWaypoints() - * * @param tag The tag * @return All of the waypoints with the specified tag + * @see IWaypointCollection#getAllWaypoints() */ Set getByTag(IWaypoint.Tag tag); /** * Gets all of the waypoints in this collection, regardless of the tag. * - * @see IWaypointCollection#getByTag(IWaypoint.Tag) - * * @return All of the waypoints in this collection + * @see IWaypointCollection#getByTag(IWaypoint.Tag) */ Set getAllWaypoints(); } diff --git a/src/api/java/baritone/api/pathing/calc/IPath.java b/src/api/java/baritone/api/pathing/calc/IPath.java index c9d58818..fddc0232 100644 --- a/src/api/java/baritone/api/pathing/calc/IPath.java +++ b/src/api/java/baritone/api/pathing/calc/IPath.java @@ -125,10 +125,9 @@ public interface IPath { * Cuts off this path using the min length and cutoff factor settings, and returns the resulting path. * Default implementation just returns this path, without the intended functionality. * + * @return The result of this cut-off operation * @see Settings#pathCutoffMinimumLength * @see Settings#pathCutoffFactor - * - * @return The result of this cut-off operation */ default IPath staticCutoff(Goal destination) { return this; diff --git a/src/launch/java/baritone/launch/mixins/MixinAnvilChunkLoader.java b/src/launch/java/baritone/launch/mixins/MixinAnvilChunkLoader.java index 4ffb5abc..8b3ea0af 100644 --- a/src/launch/java/baritone/launch/mixins/MixinAnvilChunkLoader.java +++ b/src/launch/java/baritone/launch/mixins/MixinAnvilChunkLoader.java @@ -32,7 +32,9 @@ import java.io.File; @Mixin(AnvilChunkLoader.class) public class MixinAnvilChunkLoader implements IAnvilChunkLoader { - @Shadow @Final private File chunkSaveLocation; + @Shadow + @Final + private File chunkSaveLocation; @Override public File getChunkSaveLocation() { diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkProviderServer.java b/src/launch/java/baritone/launch/mixins/MixinChunkProviderServer.java index 246c368e..6d5a5421 100644 --- a/src/launch/java/baritone/launch/mixins/MixinChunkProviderServer.java +++ b/src/launch/java/baritone/launch/mixins/MixinChunkProviderServer.java @@ -31,7 +31,9 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(ChunkProviderServer.class) public class MixinChunkProviderServer implements IChunkProviderServer { - @Shadow @Final private IChunkLoader chunkLoader; + @Shadow + @Final + private IChunkLoader chunkLoader; @Override public IChunkLoader getChunkLoader() { diff --git a/src/launch/java/baritone/launch/mixins/MixinEntity.java b/src/launch/java/baritone/launch/mixins/MixinEntity.java index db8b513f..c2a1e107 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntity.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntity.java @@ -37,7 +37,8 @@ import static org.spongepowered.asm.lib.Opcodes.GETFIELD; @Mixin(Entity.class) public class MixinEntity { - @Shadow public float rotationYaw; + @Shadow + public float rotationYaw; /** * Event called to override the movement direction when walking diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java b/src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java index 0fc1b246..174b9e3c 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java @@ -33,7 +33,7 @@ public class MixinEntityRenderer { at = @At( value = "INVOKE_STRING", target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V", - args = { "ldc=hand" } + args = {"ldc=hand"} ) ) private void renderWorldPass(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { diff --git a/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java b/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java index 3f5f297b..bf15bfc3 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java +++ b/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java @@ -77,7 +77,8 @@ public class MixinNetworkManager { ) private void preProcessPacket(ChannelHandlerContext context, Packet packet, CallbackInfo ci) { if (this.direction == EnumPacketDirection.CLIENTBOUND) { - Baritone.INSTANCE.getGameEventHandler().onReceivePacket(new PacketEvent((NetworkManager) (Object) this, EventState.PRE, packet));} + Baritone.INSTANCE.getGameEventHandler().onReceivePacket(new PacketEvent((NetworkManager) (Object) this, EventState.PRE, packet)); + } } @Inject( diff --git a/src/main/java/baritone/cache/Waypoint.java b/src/main/java/baritone/cache/Waypoint.java index 00f4410a..19e574f9 100644 --- a/src/main/java/baritone/cache/Waypoint.java +++ b/src/main/java/baritone/cache/Waypoint.java @@ -42,9 +42,9 @@ public class Waypoint implements IWaypoint { * Constructor called when a Waypoint is read from disk, adds the creationTimestamp * as a parameter so that it is reserved after a waypoint is wrote to the disk. * - * @param name The waypoint name - * @param tag The waypoint tag - * @param location The waypoint location + * @param name The waypoint name + * @param tag The waypoint tag + * @param location The waypoint location * @param creationTimestamp When the waypoint was created */ Waypoint(String name, Tag tag, BlockPos location, long creationTimestamp) {