diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index bbff9f9b..6bdb7d10 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -21,6 +21,7 @@ import baritone.api.behavior.ILookBehavior; import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IWorldProvider; import baritone.api.event.listener.IEventBus; +import baritone.api.pathing.calc.IPathingControlManager; import baritone.api.process.ICustomGoalProcess; import baritone.api.process.IFollowProcess; import baritone.api.process.IGetToBlockProcess; @@ -64,6 +65,8 @@ public interface IBaritone { */ IWorldProvider getWorldProvider(); + IPathingControlManager getPathingControlManager(); + IInputOverrideHandler getInputOverrideHandler(); ICustomGoalProcess getCustomGoalProcess(); diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 8a3bf8c3..ec745a27 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -129,6 +129,7 @@ public class Baritone implements IBaritone { this.initialized = true; } + @Override public PathingControlManager getPathingControlManager() { return this.pathingControlManager; } diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 6c62925e..b32fc99f 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -64,7 +64,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel MutableMoveResult res = new MutableMoveResult(); Favoring favored = favoring; BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world.getWorldBorder()); - long startTime = System.nanoTime() / 1000000L; + long startTime = System.currentTimeMillis(); boolean slowPath = Baritone.settings().slowPath.get(); if (slowPath) { logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.get() + "ms instead of " + primaryTimeout + "ms"); @@ -81,7 +81,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) { if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond) - long now = System.nanoTime() / 1000000L; // since nanoTime is slow on windows (takes many microseconds) + long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds) if (now - failureTimeoutTime >= 0 || (!failing && now - primaryTimeoutTime >= 0)) { break; } @@ -96,7 +96,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel mostRecentConsidered = currentNode; numNodes++; if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) { - logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); + logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext)); } for (Moves moves : Moves.values()) { @@ -125,10 +125,10 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel if (actionCost <= 0 || Double.isNaN(actionCost)) { throw new IllegalStateException(moves + " calculated implausible cost " + actionCost); } + // check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218 continue; } - // check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation if (!moves.dynamicXZ && (res.x != newX || res.z != newZ)) { throw new IllegalStateException(moves + " " + res.x + " " + newX + " " + res.z + " " + newZ); } @@ -181,7 +181,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel System.out.println(numMovementsConsidered + " movements considered"); System.out.println("Open set size: " + openSet.size()); System.out.println("PathNode map size: " + mapSize()); - System.out.println((int) (numNodes * 1.0 / ((System.nanoTime() / 1000000L - startTime) / 1000F)) + " nodes per second"); + System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second"); double bestDist = 0; for (int i = 0; i < bestSoFar.length; i++) { if (bestSoFar[i] == null) { @@ -192,7 +192,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel bestDist = dist; } if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared - logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); + logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); if (COEFFICIENTS[i] >= 3) { System.out.println("Warning: cost coefficient is greater than three! Probably means that"); System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)"); diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 2db8bf8d..ce78c231 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -127,7 +127,7 @@ public abstract class Movement implements IMovement, MovementHelper { currentState.getInputStates().forEach((input, forced) -> { baritone.getInputOverrideHandler().setInputForceState(input, forced); }); - currentState.getInputStates().replaceAll((input, forced) -> false); + currentState.getInputStates().clear(); // If the current status indicates a completed movement if (currentState.getStatus().isComplete()) { diff --git a/src/main/java/baritone/pathing/movement/MovementState.java b/src/main/java/baritone/pathing/movement/MovementState.java index 4432c503..73539698 100644 --- a/src/main/java/baritone/pathing/movement/MovementState.java +++ b/src/main/java/baritone/pathing/movement/MovementState.java @@ -20,7 +20,6 @@ package baritone.pathing.movement; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.Rotation; import baritone.api.utils.input.Input; -import net.minecraft.util.math.Vec3d; import java.util.HashMap; import java.util.Map; @@ -29,7 +28,6 @@ import java.util.Optional; public class MovementState { private MovementStatus status; - private MovementTarget goal = new MovementTarget(); private MovementTarget target = new MovementTarget(); private final Map inputState = new HashMap<>(); @@ -42,15 +40,6 @@ public class MovementState { return status; } - public MovementTarget getGoal() { - return this.goal; - } - - public MovementState setGoal(MovementTarget goal) { - this.goal = goal; - return this; - } - public MovementTarget getTarget() { return this.target; } @@ -65,23 +54,12 @@ public class MovementState { return this; } - public boolean getInput(Input input) { - return this.inputState.getOrDefault(input, false); - } - public Map getInputStates() { return this.inputState; } public static class MovementTarget { - /** - * Necessary movement to achieve - *

- * TODO: Decide desiredMovement type - */ - public Vec3d position; - /** * Yaw and pitch angles that must be matched */ @@ -95,27 +73,14 @@ public class MovementState { private boolean forceRotations; public MovementTarget() { - this(null, null, false); - } - - public MovementTarget(Vec3d position) { - this(position, null, false); + this(null, false); } public MovementTarget(Rotation rotation, boolean forceRotations) { - this(null, rotation, forceRotations); - } - - public MovementTarget(Vec3d position, Rotation rotation, boolean forceRotations) { - this.position = position; this.rotation = rotation; this.forceRotations = forceRotations; } - public final Optional getPosition() { - return Optional.ofNullable(this.position); - } - public final Optional getRotation() { return Optional.ofNullable(this.rotation); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 40597e97..e417da5f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -141,7 +141,7 @@ public class MovementTraverse extends Movement { if (srcDown == Blocks.FLOWING_WATER || srcDown == Blocks.WATER) { return COST_INF; // this is obviously impossible } - WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are sneak backplacing, we are sneaking lol + WC = WC * (SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST);//since we are sneak backplacing, we are sneaking lol return WC + placeCost + hardness1 + hardness2; } return COST_INF; diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index be49c97c..5f8cac6a 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -46,6 +46,8 @@ public class BlockStateInterface { private Chunk prev = null; private CachedRegion prevCached = null; + private final boolean useTheRealWorld; + private static final IBlockState AIR = Blocks.AIR.getDefaultState(); public BlockStateInterface(IPlayerContext ctx) { @@ -64,6 +66,7 @@ public class BlockStateInterface { } else { this.loadedChunks = worldLoaded; // this will only be used on the main thread } + this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.get(); if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) { throw new IllegalStateException(); } @@ -94,7 +97,7 @@ public class BlockStateInterface { return AIR; } - if (!Baritone.settings().pathThroughCachedOnly.get()) { + if (useTheRealWorld) { Chunk cached = prev; // there's great cache locality in block state lookups // generally it's within each movement