3x faster cache check
This commit is contained in:
@@ -77,6 +77,10 @@ public final class CachedRegion implements IBlockTypeAccess {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final boolean isCached(int x, int z) {
|
||||
return chunks[x >> 4][z >> 4] != null;
|
||||
}
|
||||
|
||||
public final LinkedList<BlockPos> getLocationsOf(String block) {
|
||||
LinkedList<BlockPos> res = new LinkedList<>();
|
||||
for (int chunkX = 0; chunkX < 32; chunkX++) {
|
||||
|
||||
@@ -59,7 +59,8 @@ public final class CachedWorld implements IBlockTypeAccess {
|
||||
if (!Files.exists(directory)) {
|
||||
try {
|
||||
Files.createDirectories(directory);
|
||||
} catch (IOException ignored) {}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
this.directory = directory.toString();
|
||||
System.out.println("Cached world directory: " + directory);
|
||||
@@ -102,6 +103,17 @@ public final class CachedWorld implements IBlockTypeAccess {
|
||||
return region.getBlock(x & 511, y, z & 511);
|
||||
}
|
||||
|
||||
public final boolean isCached(BlockPos pos) {
|
||||
int x = pos.getX();
|
||||
int z = pos.getZ();
|
||||
CachedRegion region = getRegion(x >> 9, z >> 9);
|
||||
if (region == null) {
|
||||
return false;
|
||||
}
|
||||
return region.isCached(x & 511, z & 511);
|
||||
}
|
||||
|
||||
|
||||
public final LinkedList<BlockPos> getLocationsOf(String block, int minimum, int maxRegionDistanceSq) {
|
||||
LinkedList<BlockPos> res = new LinkedList<>();
|
||||
int playerRegionX = playerFeet().getX() >> 9;
|
||||
|
||||
@@ -135,7 +135,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
long s=System.nanoTime();
|
||||
boolean isPositionCached = false;
|
||||
if (world != null) {
|
||||
if (world.getBlock(dest) != null) {
|
||||
if (world.isCached(dest)){
|
||||
isPositionCached = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user