DAE BlockPos bad?

This commit is contained in:
Leijurv 2018-10-03 07:57:24 -07:00
parent 1ee44024b2
commit 36bdaa99ec
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
4 changed files with 16 additions and 23 deletions

View File

@ -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);

View File

@ -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<HashSet<Long>> favoredPositions;
public AStarPathFinder(BlockPos start, Goal goal, Optional<HashSet<Long>> favoredPositions) {
super(start, goal);
public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Optional<HashSet<Long>> favoredPositions) {
super(startX, startY, startZ, goal);
this.favoredPositions = favoredPositions;
}
@Override
protected Optional<IPath> 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();

View File

@ -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<AbstractNodeCostSearch> getCurrentlyRunning() {
return Optional.ofNullable(currentlyRunning);
}

View File

@ -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();
/**