diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index 2cfdb8a2..2592c9d7 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -102,8 +102,11 @@ public class PathingBehavior extends Behavior { } planAhead(); } else if (talkAboutIt) { - Out.gui("Finished finding a path from " + start + " to " + goal + ". " + currentPath.numNodes + " nodes considered", Out.Mode.Debug); + Out.gui(, Out.Mode.Debug); }*/ + if (talkAboutIt && current != null && current.getPath() != null) { + displayChatMessageRaw("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); + } }).start(); } diff --git a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java index b4767c18..9bafd1a6 100644 --- a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java @@ -67,7 +67,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch { } if (goal.isInGoal(currentNodePos)) { currentlyRunning = null; - return Optional.of(new Path(startNode, currentNode, goal)); + return Optional.of(new Path(startNode, currentNode, goal, numNodes)); } //long constructStart = System.nanoTime(); Movement[] possibleMovements = getConnectedPositions(currentNodePos);//movement that we could take that start at myPos, in random order @@ -128,7 +128,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch { } System.out.println("Path goes for " + dist + " blocks"); currentlyRunning = null; - return Optional.of(new Path(startNode, bestSoFar[i], goal)); + return Optional.of(new Path(startNode, bestSoFar[i], goal, numNodes)); } } System.out.println("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + bestDist + " blocks =("); diff --git a/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java index e909e0b6..6cf968e9 100644 --- a/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java @@ -103,7 +103,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { @Override public Optional pathToMostRecentNodeConsidered() { - return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, goal)); + return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, goal, 0)); } @Override @@ -111,7 +111,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { if (startNode == null || bestSoFar[0] == null) return Optional.empty(); - return Optional.of(new Path(startNode, bestSoFar[0], goal)); + return Optional.of(new Path(startNode, bestSoFar[0], goal, 0)); } @Override diff --git a/src/main/java/baritone/bot/pathing/calc/Path.java b/src/main/java/baritone/bot/pathing/calc/Path.java index 92445e0d..0750d472 100644 --- a/src/main/java/baritone/bot/pathing/calc/Path.java +++ b/src/main/java/baritone/bot/pathing/calc/Path.java @@ -38,10 +38,13 @@ class Path implements IPath { final List movements; - Path(PathNode start, PathNode end, Goal goal) { + private final int numNodes; + + Path(PathNode start, PathNode end, Goal goal, int numNodes) { this.start = start.pos; this.end = end.pos; this.goal = goal; + this.numNodes = numNodes; this.path = new ArrayList<>(); this.movements = new ArrayList<>(); assemblePath(start, end); @@ -119,4 +122,9 @@ class Path implements IPath { public Collection getBlocksToPlace() { return movements.stream().map(move -> move.positionsToPlace).flatMap(Arrays::stream).collect(Collectors.toCollection(HashSet::new)); } + + @Override + public int getNumNodesConsidered() { + return numNodes; + } } diff --git a/src/main/java/baritone/bot/pathing/path/IPath.java b/src/main/java/baritone/bot/pathing/path/IPath.java index 0e0baeae..a63ac408 100644 --- a/src/main/java/baritone/bot/pathing/path/IPath.java +++ b/src/main/java/baritone/bot/pathing/path/IPath.java @@ -104,4 +104,6 @@ public interface IPath { * @return an unordered collection of positions */ Collection getBlocksToPlace(); + + int getNumNodesConsidered(); } diff --git a/src/main/resources/baritone/pathfinding/Path.java b/src/main/resources/baritone/pathfinding/Path.java index 07c3383f..12f703a1 100644 --- a/src/main/resources/baritone/pathfinding/Path.java +++ b/src/main/resources/baritone/pathfinding/Path.java @@ -9,10 +9,6 @@ import baritone.pathfinding.goals.Goal; import baritone.ui.LookManager; import baritone.util.Out; import baritone.util.ToolSet; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.logging.Level; -import java.util.logging.Logger; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -20,8 +16,12 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.logging.Level; +import java.util.logging.Logger; + /** - * * @author leijurv */ public class Path { @@ -38,9 +38,8 @@ public class Path { /** * note that this ISN'T the number of nodes in this path, it's actually the * number of nodes used to calculate this path. this is here for idk why - * */ - public final int numNodes; + private final int numNodes; Path(Node start, Node end, Goal goal, int numNodes) { this.numNodes = numNodes; @@ -95,6 +94,7 @@ public class Path { Minecraft.getMinecraft().world.setBlockState(path.get(i), originalStates[i]); } } + /** * Where are we in the path? This is an index in the movement list */ @@ -126,6 +126,7 @@ public class Path { double zdiff = z - (pos.getZ() + 0.5D); return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff); } + /** * How many ticks have I been more than MAX_DISTANCE_FROM_PATH away from the * path