From 36bdaa99ecf5be60bdd99898bf767443053142d3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 3 Oct 2018 07:57:24 -0700 Subject: [PATCH] DAE BlockPos bad? --- .../baritone/behavior/PathingBehavior.java | 2 +- .../pathing/calc/AStarPathFinder.java | 7 +++-- .../pathing/calc/AbstractNodeCostSearch.java | 27 +++++++++---------- .../baritone/pathing/calc/IPathFinder.java | 3 --- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 14b8db26..15748432 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -359,7 +359,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, favoredPositions = previous.map(IPath::positions).map(Collection::stream).map(x -> x.map(BetterBlockPos::longHash)).map(x -> x.collect(Collectors.toList())).map(HashSet::new); // <-- okay this is EPIC } try { - IPathFinder pf = new AStarPathFinder(start, goal, favoredPositions); + IPathFinder pf = new AStarPathFinder(start.getX(), start.getY(), start.getZ(), goal, favoredPositions); return pf.calculate(timeout); } catch (Exception e) { logDebug("Pathing exception: " + e); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index c1d4cab8..aca23d0d 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -27,7 +27,6 @@ import baritone.pathing.path.IPath; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.pathing.MoveResult; -import net.minecraft.util.math.BlockPos; import java.util.HashSet; import java.util.Optional; @@ -41,14 +40,14 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel private final Optional> favoredPositions; - public AStarPathFinder(BlockPos start, Goal goal, Optional> favoredPositions) { - super(start, goal); + public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Optional> favoredPositions) { + super(startX, startY, startZ, goal); this.favoredPositions = favoredPositions; } @Override protected Optional calculate0(long timeout) { - startNode = getNodeAtPosition(start.x, start.y, start.z, posHash(start.x, start.y, start.z)); + startNode = getNodeAtPosition(startX, startY, startZ, posHash(startX, startY, startZ)); startNode.cost = 0; startNode.combinedCost = startNode.estimatedCostToGoal; BinaryHeapOpenSet openSet = new BinaryHeapOpenSet(); diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 49e726b0..68a523fa 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -20,9 +20,7 @@ package baritone.pathing.calc; import baritone.Baritone; import baritone.api.pathing.goals.Goal; import baritone.pathing.path.IPath; -import baritone.utils.pathing.BetterBlockPos; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import net.minecraft.util.math.BlockPos; import java.util.Optional; @@ -38,7 +36,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { */ private static AbstractNodeCostSearch currentlyRunning = null; - protected final BetterBlockPos start; + protected final int startX; + protected final int startY; + protected final int startZ; protected final Goal goal; @@ -69,8 +69,10 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { */ protected final static double MIN_DIST_PATH = 5; - AbstractNodeCostSearch(BlockPos start, Goal goal) { - this.start = new BetterBlockPos(start.getX(), start.getY(), start.getZ()); + AbstractNodeCostSearch(int startX, int startY, int startZ, Goal goal) { + this.startX = startX; + this.startY = startY; + this.startZ = startZ; this.goal = goal; this.map = new Long2ObjectOpenHashMap<>(Baritone.settings().pathingMapDefaultSize.value, Baritone.settings().pathingMapLoadFactor.get()); } @@ -115,14 +117,14 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { * @return The distance, squared */ protected double getDistFromStartSq(PathNode n) { - int xDiff = n.x - start.x; - int yDiff = n.y - start.y; - int zDiff = n.z - start.z; + int xDiff = n.x - startX; + int yDiff = n.y - startY; + int zDiff = n.z - startZ; return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff; } /** - * Attempts to search the {@link BlockPos} to {@link PathNode} map + * Attempts to search the block position hashCode long to {@link PathNode} map * for the node mapped to the specified pos. If no node is found, * a new node is created. * @@ -140,7 +142,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { public static long posHash(int x, int y, int z) { /* - * This is the hashcode implementation of Vec3i, the superclass of BlockPos + * This is the hashcode implementation of Vec3i (the superclass of the class which I shall not name) * * public int hashCode() { * return (this.getY() + this.getZ() * 31) * 31 + this.getX(); @@ -220,11 +222,6 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { return goal; } - @Override - public final BlockPos getStart() { - return start; - } - public static Optional getCurrentlyRunning() { return Optional.ofNullable(currentlyRunning); } diff --git a/src/main/java/baritone/pathing/calc/IPathFinder.java b/src/main/java/baritone/pathing/calc/IPathFinder.java index 6ed2b3a7..e6f3be06 100644 --- a/src/main/java/baritone/pathing/calc/IPathFinder.java +++ b/src/main/java/baritone/pathing/calc/IPathFinder.java @@ -19,7 +19,6 @@ package baritone.pathing.calc; import baritone.api.pathing.goals.Goal; import baritone.pathing.path.IPath; -import net.minecraft.util.math.BlockPos; import java.util.Optional; @@ -30,8 +29,6 @@ import java.util.Optional; */ public interface IPathFinder { - BlockPos getStart(); - Goal getGoal(); /**