chunk check optimization

This commit is contained in:
Leijurv 2018-08-29 11:29:26 -07:00
parent 8d1570a11b
commit fb04ec6ff4
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 14 additions and 11 deletions

View File

@ -113,6 +113,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
continue; continue;
} }
BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest();
if (dest.x >> 4 != currentNodePos.x >> 4 || dest.z >> 4 != currentNodePos.z >> 4) {
// only need to check if the destination is a loaded chunk if it's in a different chunk than the start of the movement
boolean isPositionCached = false; boolean isPositionCached = false;
if (world != null) { if (world != null) {
if (world.isCached(dest)) { if (world.isCached(dest)) {
@ -123,6 +125,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
numEmptyChunk++; numEmptyChunk++;
continue; continue;
} }
}
//long costStart = System.nanoTime(); //long costStart = System.nanoTime();
// TODO cache cost // TODO cache cost
double actionCost = movementToGetToNeighbor.getCost(calcContext); double actionCost = movementToGetToNeighbor.getCost(calcContext);

View File

@ -27,9 +27,9 @@ import net.minecraft.util.math.Vec3i;
* @author leijurv * @author leijurv
*/ */
public class BetterBlockPos extends BlockPos { public class BetterBlockPos extends BlockPos {
private final int x; public final int x;
private final int y; public final int y;
private final int z; public final int z;
private final int hashCode; private final int hashCode;
public BetterBlockPos(int x, int y, int z) { public BetterBlockPos(int x, int y, int z) {