From 7c9097159c180a26dc75b5b9772da1819916859e Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 9 May 2020 14:58:08 -0400 Subject: [PATCH] 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. --- .../Do-not-load-chunks-for-Pathfinding.patch | 13 -------- Spigot-Server-Patches/MC-Utils.patch | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Spigot-Server-Patches/Do-not-load-chunks-for-Pathfinding.patch b/Spigot-Server-Patches/Do-not-load-chunks-for-Pathfinding.patch index d13737d9f..c619ab046 100644 --- a/Spigot-Server-Patches/Do-not-load-chunks-for-Pathfinding.patch +++ b/Spigot-Server-Patches/Do-not-load-chunks-for-Pathfinding.patch @@ -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 diff --git a/Spigot-Server-Patches/MC-Utils.patch b/Spigot-Server-Patches/MC-Utils.patch index b70f776a5..45222799d 100644 --- a/Spigot-Server-Patches/MC-Utils.patch +++ b/Spigot-Server-Patches/MC-Utils.patch @@ -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