Fix ChunkCache .getXIfLoaded to use the local chunks in the cache

It was calling back out to world for it, we already have them.

Also use the nocache method for building the chunk cache too.
This commit is contained in:
Aikar 2020-05-09 14:58:08 -04:00
parent 2c648ff35f
commit 7c9097159c
2 changed files with 29 additions and 15 deletions

View file

@ -4,19 +4,6 @@ Date: Thu, 31 Mar 2016 19:17:58 -0400
Subject: [PATCH] Do not load chunks for Pathfinding
diff --git a/src/main/java/net/minecraft/server/ChunkCache.java b/src/main/java/net/minecraft/server/ChunkCache.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ChunkCache.java
+++ b/src/main/java/net/minecraft/server/ChunkCache.java
@@ -0,0 +0,0 @@ public class ChunkCache implements IBlockAccess, ICollisionAccess {
for (k = this.a; k <= i; ++k) {
for (l = this.b; l <= j; ++l) {
- this.c[k - this.a][l - this.b] = ichunkprovider.a(k, l);
+ this.c[k - this.a][l - this.b] = world.getChunkIfLoadedImmediately(k, l); // Paper
}
}
diff --git a/src/main/java/net/minecraft/server/NavigationAbstract.java b/src/main/java/net/minecraft/server/NavigationAbstract.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/NavigationAbstract.java

View file

@ -2683,19 +2683,46 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public ChunkCache(World world, BlockPosition blockposition, BlockPosition blockposition1) {
this.e = world;
@@ -0,0 +0,0 @@ public class ChunkCache implements IBlockAccess, ICollisionAccess {
for (k = this.a; k <= i; ++k) {
for (l = this.b; l <= j; ++l) {
- this.c[k - this.a][l - this.b] = ichunkprovider.a(k, l);
+ this.c[k - this.a][l - this.b] = ((WorldServer)world).getChunkProvider().getChunkAtIfLoadedMainThreadNoCache(k, l); // Paper
}
}
@@ -0,0 +0,0 @@ public class ChunkCache implements IBlockAccess, ICollisionAccess {
int k = i - this.a;
int l = j - this.b;
- if (k >= 0 && k < this.c.length && l >= 0 && l < this.c[k].length) {
+ if (k >= 0 && k < this.c.length && l >= 0 && l < this.c[k].length) { // Paper - if this changes, update getChunkIfLoaded below
IChunkAccess ichunkaccess = this.c[k][l];
return (IChunkAccess) (ichunkaccess != null ? ichunkaccess : new ChunkEmpty(this.e, new ChunkCoordIntPair(i, j)));
@@ -0,0 +0,0 @@ public class ChunkCache implements IBlockAccess, ICollisionAccess {
return this.a(i, j);
}
+ // Paper start - if loaded util
+ private IChunkAccess getChunkIfLoaded(int x, int z) {
+ int k = x - this.a;
+ int l = z - this.b;
+
+ if (k >= 0 && k < this.c.length && l >= 0 && l < this.c[k].length) {
+ return this.c[k][l];
+ }
+ return null;
+ }
+ @Override
+ public Fluid getFluidIfLoaded(BlockPosition blockposition) {
+ IChunkAccess chunk = getWorld().getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ IChunkAccess chunk = getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ return chunk == null ? null : chunk.getFluid(blockposition);
+ }
+
+ @Override
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
+ IChunkAccess chunk = getWorld().getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ IChunkAccess chunk = getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ return chunk == null ? null : chunk.getType(blockposition);
+ }
+ // Paper end