diff --git a/src/api/java/baritone/api/BaritoneAPI.java b/src/api/java/baritone/api/BaritoneAPI.java new file mode 100644 index 00000000..56a26745 --- /dev/null +++ b/src/api/java/baritone/api/BaritoneAPI.java @@ -0,0 +1,76 @@ +/* + * 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.*; + +/** + * API exposure for various things implemented in Baritone. + *

+ * W.I.P + * + * @author Brady + * @since 9/23/2018 + */ +public class BaritoneAPI { + + private static IFollowBehavior followBehavior; + private static ILookBehavior lookBehavior; + private static IMemoryBehavior memoryBehavior; + private static IMineBehavior mineBehavior; + private static IPathingBehavior pathingBehavior; + + public static IFollowBehavior getFollowBehavior() { + return followBehavior; + } + + public static ILookBehavior getLookBehavior() { + return lookBehavior; + } + + public static IMemoryBehavior getMemoryBehavior() { + return memoryBehavior; + } + + public static IMineBehavior getMineBehavior() { + return mineBehavior; + } + + public static IPathingBehavior getPathingBehavior() { + return pathingBehavior; + } + + /** + * FOR INTERNAL USE ONLY + */ + // @formatter:off + public static void registerDefaultBehaviors( + IFollowBehavior followBehavior, + ILookBehavior lookBehavior, + IMemoryBehavior memoryBehavior, + IMineBehavior mineBehavior, + IPathingBehavior pathingBehavior + ) { + BaritoneAPI.followBehavior = followBehavior; + BaritoneAPI.lookBehavior = lookBehavior; + BaritoneAPI.memoryBehavior = memoryBehavior; + BaritoneAPI.mineBehavior = mineBehavior; + BaritoneAPI.pathingBehavior = pathingBehavior; + } + // @formatter:on +} diff --git a/src/api/java/baritone/api/behavior/IPathingBehavior.java b/src/api/java/baritone/api/behavior/IPathingBehavior.java new file mode 100644 index 00000000..e21d999d --- /dev/null +++ b/src/api/java/baritone/api/behavior/IPathingBehavior.java @@ -0,0 +1,68 @@ +/* + * 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.behavior; + +import baritone.api.pathing.goals.Goal; + +import java.util.Optional; + +/** + * @author Brady + * @since 9/23/2018 + */ +public interface IPathingBehavior extends IBehavior { + + /** + * Returns the estimated remaining ticks in the current pathing + * segment. Given that the return type is an optional, {@link Optional#empty()} + * will be returned in the case that there is no current segment being pathed. + * + * @return The estimated remaining ticks in the current segment. + */ + 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. + */ + void cancel(); +} diff --git a/src/main/java/baritone/pathing/goals/Goal.java b/src/api/java/baritone/api/pathing/goals/Goal.java similarity index 92% rename from src/main/java/baritone/pathing/goals/Goal.java rename to src/api/java/baritone/api/pathing/goals/Goal.java index 0f01ca92..38cfb9d7 100644 --- a/src/main/java/baritone/pathing/goals/Goal.java +++ b/src/api/java/baritone/api/pathing/goals/Goal.java @@ -15,9 +15,8 @@ * along with Baritone. If not, see . */ -package baritone.pathing.goals; +package baritone.api.pathing.goals; -import baritone.pathing.movement.ActionCosts; import net.minecraft.util.math.BlockPos; /** @@ -25,7 +24,7 @@ import net.minecraft.util.math.BlockPos; * * @author leijurv */ -public interface Goal extends ActionCosts { +public interface Goal { /** * Returns whether or not the specified position diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 61b2982a..d3db4918 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -17,6 +17,7 @@ package baritone; +import baritone.api.BaritoneAPI; import baritone.behavior.Behavior; import baritone.api.event.listener.IGameEventListener; import baritone.behavior.*; @@ -89,6 +90,16 @@ public enum Baritone { registerBehavior(LocationTrackingBehavior.INSTANCE); registerBehavior(FollowBehavior.INSTANCE); registerBehavior(MineBehavior.INSTANCE); + + // TODO: Clean this up + // Maybe combine this call in someway with the registerBehavior calls? + BaritoneAPI.registerDefaultBehaviors( + FollowBehavior.INSTANCE, + LookBehavior.INSTANCE, + MemoryBehavior.INSTANCE, + MineBehavior.INSTANCE, + PathingBehavior.INSTANCE + ); } this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); if (!Files.exists(dir.toPath())) { diff --git a/src/main/java/baritone/behavior/MineBehavior.java b/src/main/java/baritone/behavior/MineBehavior.java index 2dde364b..ccee818f 100644 --- a/src/main/java/baritone/behavior/MineBehavior.java +++ b/src/main/java/baritone/behavior/MineBehavior.java @@ -25,7 +25,7 @@ import baritone.cache.CachedChunk; import baritone.cache.ChunkPacker; import baritone.cache.WorldProvider; import baritone.cache.WorldScanner; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.goals.GoalBlock; import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalTwoBlocks; diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 7820066c..ecf28b94 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -18,6 +18,7 @@ package baritone.behavior; import baritone.Baritone; +import baritone.api.behavior.IPathingBehavior; import baritone.api.event.events.PathEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.RenderEvent; @@ -25,7 +26,7 @@ import baritone.api.event.events.TickEvent; import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.calc.IPathFinder; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.goals.GoalXZ; import baritone.pathing.movement.MovementHelper; import baritone.pathing.path.IPath; @@ -46,7 +47,7 @@ import java.util.HashSet; import java.util.Optional; import java.util.stream.Collectors; -public final class PathingBehavior extends Behavior implements Helper { +public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper { public static final PathingBehavior INSTANCE = new PathingBehavior(); @@ -172,6 +173,7 @@ public final class PathingBehavior extends Behavior implements Helper { } } + @Override public Optional ticksRemainingInSegment() { if (current == null) { return Optional.empty(); @@ -179,10 +181,12 @@ public final class PathingBehavior extends Behavior implements Helper { return Optional.of(current.getPath().ticksRemainingFrom(current.getPosition())); } + @Override public void setGoal(Goal goal) { this.goal = goal; } + @Override public Goal getGoal() { return goal; } @@ -195,10 +199,19 @@ public final class PathingBehavior extends Behavior implements Helper { return next; } + // TODO: Expose this method in the API? + // In order to do so, we'd need to move over IPath which has a whole lot of references to other + // things that may not need to be exposed necessarily, so we'll need to figure that out. public Optional getPath() { return Optional.ofNullable(current).map(PathExecutor::getPath); } + @Override + public boolean isPathing() { + return this.current != null; + } + + @Override public void cancel() { dispatchPathEvent(PathEvent.CANCELED); current = null; @@ -212,6 +225,7 @@ public final class PathingBehavior extends Behavior implements Helper { * * @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; @@ -234,7 +248,10 @@ public final class PathingBehavior extends Behavior implements Helper { } } - public BlockPos pathStart() { + /** + * @return The starting {@link BlockPos} for a new path + */ + private BlockPos pathStart() { BetterBlockPos feet = playerFeet(); if (BlockStateInterface.get(feet.down()).getBlock().equals(Blocks.AIR) && MovementHelper.canWalkOn(feet.down().down())) { return feet.down(); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 515f4b16..ddee9582 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -19,7 +19,7 @@ package baritone.pathing.calc; import baritone.Baritone; import baritone.pathing.calc.openset.BinaryHeapOpenSet; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Moves; diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 5c8d0da9..587a3b7d 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -18,7 +18,7 @@ package baritone.pathing.calc; import baritone.behavior.PathingBehavior; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.path.IPath; import baritone.utils.pathing.BetterBlockPos; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; diff --git a/src/main/java/baritone/pathing/calc/IPathFinder.java b/src/main/java/baritone/pathing/calc/IPathFinder.java index 3723865d..6ed2b3a7 100644 --- a/src/main/java/baritone/pathing/calc/IPathFinder.java +++ b/src/main/java/baritone/pathing/calc/IPathFinder.java @@ -17,7 +17,7 @@ package baritone.pathing.calc; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.path.IPath; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/pathing/calc/Path.java b/src/main/java/baritone/pathing/calc/Path.java index 85450f27..7f8cf085 100644 --- a/src/main/java/baritone/pathing/calc/Path.java +++ b/src/main/java/baritone/pathing/calc/Path.java @@ -17,7 +17,7 @@ package baritone.pathing.calc; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.movement.Movement; import baritone.pathing.movement.Moves; import baritone.pathing.path.IPath; diff --git a/src/main/java/baritone/pathing/calc/PathNode.java b/src/main/java/baritone/pathing/calc/PathNode.java index 9b960a83..6d4142aa 100644 --- a/src/main/java/baritone/pathing/calc/PathNode.java +++ b/src/main/java/baritone/pathing/calc/PathNode.java @@ -17,7 +17,7 @@ package baritone.pathing.calc; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.movement.ActionCosts; /** diff --git a/src/main/java/baritone/pathing/goals/GoalAxis.java b/src/main/java/baritone/pathing/goals/GoalAxis.java index a75d2bb7..1882a7e3 100644 --- a/src/main/java/baritone/pathing/goals/GoalAxis.java +++ b/src/main/java/baritone/pathing/goals/GoalAxis.java @@ -18,6 +18,7 @@ package baritone.pathing.goals; import baritone.Baritone; +import baritone.api.pathing.goals.Goal; public class GoalAxis implements Goal { diff --git a/src/main/java/baritone/pathing/goals/GoalBlock.java b/src/main/java/baritone/pathing/goals/GoalBlock.java index f5cd2dfb..ea28c057 100644 --- a/src/main/java/baritone/pathing/goals/GoalBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalBlock.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.api.pathing.goals.Goal; import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/pathing/goals/GoalComposite.java b/src/main/java/baritone/pathing/goals/GoalComposite.java index b7bb9e6e..a4dafa45 100644 --- a/src/main/java/baritone/pathing/goals/GoalComposite.java +++ b/src/main/java/baritone/pathing/goals/GoalComposite.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.api.pathing.goals.Goal; import net.minecraft.util.math.BlockPos; import java.util.Arrays; diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index 3ade972f..8f249ed0 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.api.pathing.goals.Goal; import baritone.utils.interfaces.IGoalRenderPos; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/pathing/goals/GoalNear.java b/src/main/java/baritone/pathing/goals/GoalNear.java index 0d0c9c75..f312c9ee 100644 --- a/src/main/java/baritone/pathing/goals/GoalNear.java +++ b/src/main/java/baritone/pathing/goals/GoalNear.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.api.pathing.goals.Goal; import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/pathing/goals/GoalRunAway.java b/src/main/java/baritone/pathing/goals/GoalRunAway.java index d0702640..9ca74711 100644 --- a/src/main/java/baritone/pathing/goals/GoalRunAway.java +++ b/src/main/java/baritone/pathing/goals/GoalRunAway.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.api.pathing.goals.Goal; import net.minecraft.util.math.BlockPos; import java.util.Arrays; diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 428279a1..c5036c35 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.api.pathing.goals.Goal; import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/pathing/goals/GoalXZ.java b/src/main/java/baritone/pathing/goals/GoalXZ.java index 7f200e64..8053ee04 100644 --- a/src/main/java/baritone/pathing/goals/GoalXZ.java +++ b/src/main/java/baritone/pathing/goals/GoalXZ.java @@ -18,6 +18,7 @@ package baritone.pathing.goals; import baritone.Baritone; +import baritone.api.pathing.goals.Goal; import baritone.utils.Utils; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; diff --git a/src/main/java/baritone/pathing/goals/GoalYLevel.java b/src/main/java/baritone/pathing/goals/GoalYLevel.java index 2ac46981..fa4af522 100644 --- a/src/main/java/baritone/pathing/goals/GoalYLevel.java +++ b/src/main/java/baritone/pathing/goals/GoalYLevel.java @@ -17,12 +17,15 @@ package baritone.pathing.goals; +import baritone.api.pathing.goals.Goal; +import baritone.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside; + /** * Useful for mining (getting to diamond / iron level) * * @author leijurv */ -public class GoalYLevel implements Goal { +public class GoalYLevel implements Goal, ActionCostsButOnlyTheOnesThatMakeMickeyDieInside { /** * The target Y level diff --git a/src/main/java/baritone/pathing/path/CutoffPath.java b/src/main/java/baritone/pathing/path/CutoffPath.java index 295f3830..e517452e 100644 --- a/src/main/java/baritone/pathing/path/CutoffPath.java +++ b/src/main/java/baritone/pathing/path/CutoffPath.java @@ -17,7 +17,7 @@ package baritone.pathing.path; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.movement.Movement; import baritone.utils.pathing.BetterBlockPos; diff --git a/src/main/java/baritone/pathing/path/IPath.java b/src/main/java/baritone/pathing/path/IPath.java index 59cb8cac..0701abf6 100644 --- a/src/main/java/baritone/pathing/path/IPath.java +++ b/src/main/java/baritone/pathing/path/IPath.java @@ -18,7 +18,7 @@ package baritone.pathing.path; import baritone.Baritone; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.movement.Movement; import baritone.utils.Helper; import baritone.utils.Utils; diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 5d0fcdaf..1bcfd3a2 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -19,6 +19,7 @@ package baritone.utils; import baritone.Baritone; import baritone.Settings; +import baritone.api.pathing.goals.Goal; import baritone.behavior.Behavior; import baritone.api.event.events.ChatEvent; import baritone.behavior.FollowBehavior; diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 86f49e5e..e5c35650 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -18,7 +18,7 @@ package baritone.utils; import baritone.Baritone; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalTwoBlocks; import baritone.pathing.goals.GoalXZ; diff --git a/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java b/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java index 5f7b98d0..c15e1747 100644 --- a/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java +++ b/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java @@ -18,7 +18,7 @@ package baritone.pathing.calc.openset; import baritone.pathing.calc.PathNode; -import baritone.pathing.goals.Goal; +import baritone.api.pathing.goals.Goal; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized;