From f727e71eaf538f2727ff4d6b2d9fdeab67b37a16 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 10 Jan 2019 19:57:09 -0600 Subject: [PATCH 1/7] Expose IPathingControlManager in IBaritone --- src/api/java/baritone/api/IBaritone.java | 3 +++ src/main/java/baritone/Baritone.java | 1 + 2 files changed, 4 insertions(+) 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 41fa36c5..c3a8e272 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; } From 1ad6a0d5b58ff1f27ab978d684e02728022bf909 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 10 Jan 2019 18:21:02 -0800 Subject: [PATCH 2/7] remove all that crap lol --- .../baritone/pathing/movement/Movement.java | 2 +- .../pathing/movement/MovementState.java | 37 +------------------ 2 files changed, 2 insertions(+), 37 deletions(-) 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); } From 5f29bb3e7f4a98d8bdbd2b82e317083d8da4c01d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 10 Jan 2019 18:55:55 -0800 Subject: [PATCH 3/7] gotta go fast --- src/main/java/baritone/utils/BlockStateInterface.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 From 09e94eaa8e55f635bae4fcae0b82d69b224e95b2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 11 Jan 2019 13:02:03 -0800 Subject: [PATCH 4/7] not anymore --- src/main/java/baritone/pathing/movement/CalculationContext.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 55933038..4c3b299d 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -75,7 +75,6 @@ public class CalculationContext { this.world = baritone.getPlayerContext().world(); this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld(); this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread); // TODO TODO TODO - // new CalculationContext() needs to happen, can't add an argument (i'll beat you), can we get the world provider from currentlyTicking? this.toolSet = new ToolSet(player); this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(baritone.getPlayerContext(), false); this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.provider.isNether(); From bec7f9be966196e5498fb1b5d1937cb9aa8a18f2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 11 Jan 2019 13:18:31 -0800 Subject: [PATCH 5/7] this lets proguard optimize out one more double division --- .../baritone/pathing/movement/movements/MovementTraverse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 0788ff8c..4a87a8a6 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 + context.placeBlockCost + hardness1 + hardness2; } return COST_INF; From f23630064e3310f9674b25cdced8f9239e2f414d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 12 Jan 2019 22:33:46 -0800 Subject: [PATCH 6/7] reorder --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 6c62925e..70c2419e 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -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); } From f8681d179d82001dd98b42c1f21a525d6b57b577 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 13 Jan 2019 00:00:52 -0800 Subject: [PATCH 7/7] TODO use nanotime when calc starts on dec 31 --- .../java/baritone/pathing/calc/AStarPathFinder.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 70c2419e..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()) { @@ -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)");