Update upstream & fix some chunk related issues (#2177)

* Updated Upstream (Bukkit/CraftBukkit)

Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories

CraftBukkit Changes:
4090d01f SPIGOT-5047: Correct slot types for 1.14 inventories
e8c08362 SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.
d445af3b SPIGOT-5067: Add item meta for 1.14 spawn eggs

* Bring Chunk load checks in-line with spigot

As of the last upstream merge spigot now checks ticket level status
when returning loaded chunks for a world from api. Now our checks
will respect that decision.

* Fix spawn ticket levels

Vanilla would keep the inner chunks of spawn available for ticking,
however my changes made all chunks non-ticking. Resolve by changing
ticket levels for spawn chunks inside the border to respect this
behavior.


* Make World#getChunkIfLoadedImmediately return only entity ticking chunks

Mojang appears to be using chunks with level > 33 (non-ticking chunks)
as cached chunks and not actually loaded chunks.

* Bring all loaded checks in line with spigot

Loaded chunks must be at least border  chunks, or level <= 33
This commit is contained in:
Spottedleaf
2019-06-13 19:27:40 -07:00
parent c180ef4b12
commit e8de107ca0
80 changed files with 262 additions and 168 deletions

View File

@@ -182,7 +182,7 @@ index 857b2f8868..bbf136614c 100644
}
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index dcf2d38df5..600217427b 100644
index dcf2d38df5..95356b82ff 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 {
@@ -192,10 +192,10 @@ index dcf2d38df5..600217427b 100644
+ // Paper start - "real" get chunk if loaded
+ // Note: Partially copied from the getChunkAt method below
+ @Nullable
+ public Chunk getChunkAtIfLoadedImmediately(int x, int z) {
+ public Chunk getChunkAtIfCachedImmediately(int x, int z) {
+ if (Thread.currentThread() != this.serverThread) {
+ return CompletableFuture.supplyAsync(() -> {
+ return this.getChunkAtIfLoadedImmediately(x, z);
+ return this.getChunkAtIfCachedImmediately(x, z);
+ }, this.serverThreadQueue).join();
+ }
+
@@ -217,6 +217,26 @@ index dcf2d38df5..600217427b 100644
+ return null;
+ }
+
+ return playerChunk.getFullChunkIfCached();
+ }
+
+ @Nullable
+ public Chunk getChunkAtIfLoadedImmediately(int x, int z) {
+ if (Thread.currentThread() != this.serverThread) {
+ return CompletableFuture.supplyAsync(() -> {
+ return this.getChunkAtIfLoadedImmediately(x, z);
+ }, this.serverThreadQueue).join();
+ }
+
+ long k = ChunkCoordIntPair.pair(x, z);
+
+ // Note: Bypass cache since we need to check ticket level
+
+ PlayerChunk playerChunk = this.getChunk(k);
+ if (playerChunk == null) {
+ return null;
+ }
+
+ return playerChunk.getFullChunk();
+ }
+ // Paper end
@@ -924,6 +944,25 @@ index 4e20cfba41..363ab5da12 100644
public int a(PacketDataSerializer packetdataserializer, Chunk chunk, int i) {
int j = 0;
ChunkSection[] achunksection = chunk.getSections();
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
index 67c8a5efc7..78dca8932f 100644
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
@@ -0,0 +0,0 @@ public class PlayerChunk {
return either == null ? null : (Chunk) either.left().orElse(null);
}
// CraftBukkit end
+ // Paper start - "real" get full chunk immediately
+ public Chunk getFullChunkIfCached() {
+ // Note: Copied from above without ticket level check
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> statusFuture = this.getStatusFutureUnchecked(ChunkStatus.FULL);
+ Either<IChunkAccess, PlayerChunk.Failure> either = (Either<IChunkAccess, PlayerChunk.Failure>) statusFuture.getNow(null);
+ return either == null ? null : (Chunk) either.left().orElse(null);
+ }
+ // Paper end
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> getStatusFutureUnchecked(ChunkStatus chunkstatus) {
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = (CompletableFuture) this.statusFutures.get(chunkstatus.c());
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 58f9946455..ae194b981f 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -1103,7 +1142,7 @@ index 91e50ccea1..a2b1aba49f 100644
return this.setTypeAndData(blockposition, fluid.getBlockData(), 3 | (flag ? 64 : 0));
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index 42f7bb0f7d..5d71addb0c 100644
index 2a9e2ab58a..4eb7438f25 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {