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 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 { try {
IPathFinder pf = new AStarPathFinder(start, goal, favoredPositions); IPathFinder pf = new AStarPathFinder(start.getX(), start.getY(), start.getZ(), goal, favoredPositions);
return pf.calculate(timeout); return pf.calculate(timeout);
} catch (Exception e) { } catch (Exception e) {
logDebug("Pathing exception: " + e); logDebug("Pathing exception: " + e);

View File

@ -27,7 +27,6 @@ import baritone.pathing.path.IPath;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.Helper; import baritone.utils.Helper;
import baritone.utils.pathing.MoveResult; import baritone.utils.pathing.MoveResult;
import net.minecraft.util.math.BlockPos;
import java.util.HashSet; import java.util.HashSet;
import java.util.Optional; import java.util.Optional;
@ -41,14 +40,14 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
private final Optional<HashSet<Long>> favoredPositions; private final Optional<HashSet<Long>> favoredPositions;
public AStarPathFinder(BlockPos start, Goal goal, Optional<HashSet<Long>> favoredPositions) { public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Optional<HashSet<Long>> favoredPositions) {
super(start, goal); super(startX, startY, startZ, goal);
this.favoredPositions = favoredPositions; this.favoredPositions = favoredPositions;
} }
@Override @Override
protected Optional<IPath> calculate0(long timeout) { 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.cost = 0;
startNode.combinedCost = startNode.estimatedCostToGoal; startNode.combinedCost = startNode.estimatedCostToGoal;
BinaryHeapOpenSet openSet = new BinaryHeapOpenSet(); BinaryHeapOpenSet openSet = new BinaryHeapOpenSet();

View File

@ -20,9 +20,7 @@ package baritone.pathing.calc;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.Goal;
import baritone.pathing.path.IPath; import baritone.pathing.path.IPath;
import baritone.utils.pathing.BetterBlockPos;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.util.math.BlockPos;
import java.util.Optional; import java.util.Optional;
@ -38,7 +36,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
*/ */
private static AbstractNodeCostSearch currentlyRunning = null; 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; protected final Goal goal;
@ -69,8 +69,10 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
*/ */
protected final static double MIN_DIST_PATH = 5; protected final static double MIN_DIST_PATH = 5;
AbstractNodeCostSearch(BlockPos start, Goal goal) { AbstractNodeCostSearch(int startX, int startY, int startZ, Goal goal) {
this.start = new BetterBlockPos(start.getX(), start.getY(), start.getZ()); this.startX = startX;
this.startY = startY;
this.startZ = startZ;
this.goal = goal; this.goal = goal;
this.map = new Long2ObjectOpenHashMap<>(Baritone.settings().pathingMapDefaultSize.value, Baritone.settings().pathingMapLoadFactor.get()); 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 * @return The distance, squared
*/ */
protected double getDistFromStartSq(PathNode n) { protected double getDistFromStartSq(PathNode n) {
int xDiff = n.x - start.x; int xDiff = n.x - startX;
int yDiff = n.y - start.y; int yDiff = n.y - startY;
int zDiff = n.z - start.z; int zDiff = n.z - startZ;
return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff; 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, * for the node mapped to the specified pos. If no node is found,
* a new node is created. * 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) { 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() { * public int hashCode() {
* return (this.getY() + this.getZ() * 31) * 31 + this.getX(); * return (this.getY() + this.getZ() * 31) * 31 + this.getX();
@ -220,11 +222,6 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
return goal; return goal;
} }
@Override
public final BlockPos getStart() {
return start;
}
public static Optional<AbstractNodeCostSearch> getCurrentlyRunning() { public static Optional<AbstractNodeCostSearch> getCurrentlyRunning() {
return Optional.ofNullable(currentlyRunning); return Optional.ofNullable(currentlyRunning);
} }

View File

@ -19,7 +19,6 @@ package baritone.pathing.calc;
import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.Goal;
import baritone.pathing.path.IPath; import baritone.pathing.path.IPath;
import net.minecraft.util.math.BlockPos;
import java.util.Optional; import java.util.Optional;
@ -30,8 +29,6 @@ import java.util.Optional;
*/ */
public interface IPathFinder { public interface IPathFinder {
BlockPos getStart();
Goal getGoal(); Goal getGoal();
/** /**