Improve chunk loaded checks

This commit is contained in:
Spottedleaf
2019-06-10 17:29:30 -07:00
parent 0616199cad
commit 522cb2b4d1
19 changed files with 94 additions and 55 deletions

View File

@@ -181,6 +181,49 @@ index 857b2f8868..bbf136614c 100644
return (long) i & 4294967295L | ((long) j & 4294967295L) << 32;
}
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index dcf2d38df5..ea73e4baba 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider {
return this.playerChunkMap.c();
}
+ // Paper start - "real" get chunk if loaded
+ // Note: Partially copied from the getChunkAt method below
+ @Nullable
+ public Chunk getChunkAtIfLoadedImmediately(int x, int z) {
+ if (Thread.currentThread() != this.serverThread) {
+ return CompletableFuture.supplyAsync(() -> {
+ return this.getChunkAtIfLoadedImmediately(x, z);
+ }).join();
+ }
+
+ long k = ChunkCoordIntPair.pair(x, z);
+
+ IChunkAccess ichunkaccess;
+
+ for (int l = 0; l < 4; ++l) {
+ if (k == this.cachePos[l] && ChunkStatus.FULL == this.cacheStatus[l]) {
+ ichunkaccess = this.cacheChunk[l];
+ if (ichunkaccess instanceof Chunk) { // CraftBukkit - the chunk can become accessible in the meantime TODO for non-null chunks it might also make sense to check that the chunk's state hasn't changed in the meantime
+ return (Chunk)ichunkaccess;
+ }
+ }
+ }
+
+ PlayerChunk playerChunk = this.getChunk(k);
+ if (playerChunk == null) {
+ return null;
+ }
+
+ return playerChunk.getFullChunk();
+ }
+ // Paper end
+
@Nullable
@Override
public IChunkAccess getChunkAt(int i, int j, ChunkStatus chunkstatus, boolean flag) {
diff --git a/src/main/java/net/minecraft/server/DataBits.java b/src/main/java/net/minecraft/server/DataBits.java
index 8bda055159..409dc837c6 100644
--- a/src/main/java/net/minecraft/server/DataBits.java
@@ -899,7 +942,7 @@ index 58f9946455..ae194b981f 100644
private volatile int chatThrottle;
private static final AtomicIntegerFieldUpdater chatSpamField = AtomicIntegerFieldUpdater.newUpdater(PlayerConnection.class, "chatThrottle");
diff --git a/src/main/java/net/minecraft/server/PlayerInventory.java b/src/main/java/net/minecraft/server/PlayerInventory.java
index a5dba62caf..a088658ae0 100644
index 2fe3d5d4c2..4aee712a6f 100644
--- a/src/main/java/net/minecraft/server/PlayerInventory.java
+++ b/src/main/java/net/minecraft/server/PlayerInventory.java
@@ -0,0 +0,0 @@ public class PlayerInventory implements IInventory, INamableTileEntity {
@@ -1003,7 +1046,7 @@ index b3799ab564..5fae5a1233 100644
public static long getTimeMillis() {
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 91e50ccea1..69c704a429 100644
index 91e50ccea1..a2b1aba49f 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -0,0 +0,0 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
@@ -1014,11 +1057,7 @@ index 91e50ccea1..69c704a429 100644
+ @Nullable
+ @Override
+ public IChunkAccess getChunkIfLoadedImmediately(int x, int z) {
+ if (!((ChunkProviderServer)this.chunkProvider).isLoaded(x, z)) {
+ return null;
+ }
+
+ return this.chunkProvider.getChunkAt(x, z, ChunkStatus.FULL, true);
+ return ((ChunkProviderServer)this.chunkProvider).getChunkAtIfLoadedImmediately(x, z);
+ }
+
+ @Override