From fb04ec6ff4e84950d0e8169665a910f3202b4f1f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 29 Aug 2018 11:29:26 -0700 Subject: [PATCH] chunk check optimization --- .../pathing/calc/AStarPathFinder.java | 19 +++++++++++-------- .../utils/pathing/BetterBlockPos.java | 6 +++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index c708d3e9..8d0a6989 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -113,15 +113,18 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { continue; } BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); - boolean isPositionCached = false; - if (world != null) { - if (world.isCached(dest)) { - isPositionCached = true; + 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; + if (world != null) { + if (world.isCached(dest)) { + isPositionCached = true; + } + } + if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) { + numEmptyChunk++; + continue; } - } - if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) { - numEmptyChunk++; - continue; } //long costStart = System.nanoTime(); // TODO cache cost diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 93512984..8518f668 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -27,9 +27,9 @@ import net.minecraft.util.math.Vec3i; * @author leijurv */ public class BetterBlockPos extends BlockPos { - private final int x; - private final int y; - private final int z; + public final int x; + public final int y; + public final int z; private final int hashCode; public BetterBlockPos(int x, int y, int z) {