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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user