Peek the unload queue for chunk generation checks (#2332)

This commit is contained in:
Spottedleaf 2019-07-23 20:41:26 -07:00 committed by Zach
parent 4ac69cec8d
commit c6987e1a02
2 changed files with 56 additions and 38 deletions

View File

@ -1,4 +1,4 @@
From a5e4705a4175deaaf735ad7d7400376cfb27339e Mon Sep 17 00:00:00 2001 From 9108082620a7a637b10036ca535b3811d24048bf Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com> From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sat, 15 Jun 2019 08:54:33 -0700 Date: Sat, 15 Jun 2019 08:54:33 -0700
Subject: [PATCH] Fix World#isChunkGenerated calls Subject: [PATCH] Fix World#isChunkGenerated calls
@ -8,7 +8,7 @@ This patch also adds a chunk status cache on region files (note that
its only purpose is to cache the status on DISK) its only purpose is to cache the status on DISK)
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 220cd197f..775b5f7fe 100644 index 220cd197fa..775b5f7fe3 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -28,7 +28,7 @@ public class ChunkProviderServer extends IChunkProvider { @@ -28,7 +28,7 @@ public class ChunkProviderServer extends IChunkProvider {
@ -58,7 +58,7 @@ index 220cd197f..775b5f7fe 100644
@Nullable @Nullable
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
index e778c2e85..73f93e494 100644 index e778c2e857..73f93e4948 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java --- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java +++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -410,6 +410,17 @@ public class ChunkRegionLoader { @@ -410,6 +410,17 @@ public class ChunkRegionLoader {
@ -80,7 +80,7 @@ index e778c2e85..73f93e494 100644
if (nbttagcompound != null) { if (nbttagcompound != null) {
ChunkStatus chunkstatus = ChunkStatus.a(nbttagcompound.getCompound("Level").getString("Status")); ChunkStatus chunkstatus = ChunkStatus.a(nbttagcompound.getCompound("Level").getString("Status"));
diff --git a/src/main/java/net/minecraft/server/ChunkStatus.java b/src/main/java/net/minecraft/server/ChunkStatus.java diff --git a/src/main/java/net/minecraft/server/ChunkStatus.java b/src/main/java/net/minecraft/server/ChunkStatus.java
index dd1822d6f..e324989b4 100644 index dd1822d6ff..e324989b46 100644
--- a/src/main/java/net/minecraft/server/ChunkStatus.java --- a/src/main/java/net/minecraft/server/ChunkStatus.java
+++ b/src/main/java/net/minecraft/server/ChunkStatus.java +++ b/src/main/java/net/minecraft/server/ChunkStatus.java
@@ -176,6 +176,7 @@ public class ChunkStatus { @@ -176,6 +176,7 @@ public class ChunkStatus {
@ -110,7 +110,7 @@ index dd1822d6f..e324989b4 100644
return (ChunkStatus) IRegistry.CHUNK_STATUS.get(MinecraftKey.a(s)); return (ChunkStatus) IRegistry.CHUNK_STATUS.get(MinecraftKey.a(s));
} }
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
index 14a176d61..98590e233 100644 index 14a176d61d..98590e233a 100644
--- a/src/main/java/net/minecraft/server/PlayerChunk.java --- a/src/main/java/net/minecraft/server/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java +++ b/src/main/java/net/minecraft/server/PlayerChunk.java
@@ -70,6 +70,19 @@ public class PlayerChunk { @@ -70,6 +70,19 @@ public class PlayerChunk {
@ -134,10 +134,10 @@ index 14a176d61..98590e233 100644
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> getStatusFutureUnchecked(ChunkStatus chunkstatus) { public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> getStatusFutureUnchecked(ChunkStatus chunkstatus) {
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 17eee15b2..2032361f8 100644 index 17eee15b2d..8dd934319d 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -878,11 +878,56 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { @@ -878,11 +878,61 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
} }
@Nullable @Nullable
@ -191,13 +191,18 @@ index 17eee15b2..2032361f8 100644
+ RegionFile regionFile = this.getRegionFile(chunkPos, false); + RegionFile regionFile = this.getRegionFile(chunkPos, false);
+ +
+ regionFile.setStatus(chunkPos.x, chunkPos.z, ChunkRegionLoader.getStatus(compound)); + regionFile.setStatus(chunkPos.x, chunkPos.z, ChunkRegionLoader.getStatus(compound));
+ }
+
+ public IChunkAccess getUnloadingChunk(int chunkX, int chunkZ) {
+ PlayerChunk chunkHolder = this.pendingUnload.get(ChunkCoordIntPair.pair(chunkX, chunkZ));
+ return chunkHolder == null ? null : chunkHolder.getAvailableChunkNow();
} }
+ // Paper end + // Paper end
boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair) { boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair) {
// Spigot start // Spigot start
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
index b0ec9edf6..41f1e15cb 100644 index b0ec9edf67..41f1e15cb0 100644
--- a/src/main/java/net/minecraft/server/RegionFile.java --- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java +++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -31,6 +31,30 @@ public class RegionFile implements AutoCloseable { @@ -31,6 +31,30 @@ public class RegionFile implements AutoCloseable {
@ -256,7 +261,7 @@ index b0ec9edf6..41f1e15cb 100644
} }
diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java
index 6f34d8aea..d2b328945 100644 index 6f34d8aea0..d2b3289450 100644
--- a/src/main/java/net/minecraft/server/RegionFileCache.java --- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java +++ b/src/main/java/net/minecraft/server/RegionFileCache.java
@@ -47,6 +47,12 @@ public abstract class RegionFileCache implements AutoCloseable { @@ -47,6 +47,12 @@ public abstract class RegionFileCache implements AutoCloseable {
@ -289,10 +294,10 @@ index 6f34d8aea..d2b328945 100644
printOversizedLog("ChunkTooLarge even after reduction. Trying in overzealous mode.", regionfile.file, chunkX, chunkZ); printOversizedLog("ChunkTooLarge even after reduction. Trying in overzealous mode.", regionfile.file, chunkX, chunkZ);
// Eek, major fail. We have retry logic, so reduce threshholds and fall back // Eek, major fail. We have retry logic, so reduce threshholds and fall back
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index acf151a25..a734a87c4 100644 index acf151a253..a2b6c3c94a 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -393,8 +393,19 @@ public class CraftWorld implements World { @@ -393,8 +393,22 @@ public class CraftWorld implements World {
@Override @Override
public boolean isChunkGenerated(int x, int z) { public boolean isChunkGenerated(int x, int z) {
@ -303,6 +308,9 @@ index acf151a25..a734a87c4 100644
+ }, world.getChunkProvider().serverThreadQueue).join(); + }, world.getChunkProvider().serverThreadQueue).join();
+ } + }
+ IChunkAccess chunk = world.getChunkProvider().getChunkAtImmediately(x, z); + IChunkAccess chunk = world.getChunkProvider().getChunkAtImmediately(x, z);
+ if (chunk == null) {
+ chunk = world.getChunkProvider().playerChunkMap.getUnloadingChunk(x, z);
+ }
+ if (chunk != null) { + if (chunk != null) {
+ return chunk instanceof ProtoChunkExtension || chunk instanceof net.minecraft.server.Chunk; + return chunk instanceof ProtoChunkExtension || chunk instanceof net.minecraft.server.Chunk;
+ } + }
@ -313,7 +321,7 @@ index acf151a25..a734a87c4 100644
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@@ -506,20 +517,45 @@ public class CraftWorld implements World { @@ -506,20 +520,49 @@ public class CraftWorld implements World {
@Override @Override
public boolean loadChunk(int x, int z, boolean generate) { public boolean loadChunk(int x, int z, boolean generate) {
org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot
@ -325,7 +333,16 @@ index acf151a25..a734a87c4 100644
- if (chunk instanceof ProtoChunkExtension) { - if (chunk instanceof ProtoChunkExtension) {
- // We then cycle through again to get the full chunk immediately, rather than after the ticket addition - // We then cycle through again to get the full chunk immediately, rather than after the ticket addition
- chunk = world.getChunkProvider().getChunkAt(x, z, ChunkStatus.FULL, true); - chunk = world.getChunkProvider().getChunkAt(x, z, ChunkStatus.FULL, true);
- }
+ if (!generate) {
- if (chunk instanceof net.minecraft.server.Chunk) {
- world.getChunkProvider().addTicket(TicketType.PLUGIN, new ChunkCoordIntPair(x, z), 1, Unit.INSTANCE);
- return true;
+ IChunkAccess immediate = world.getChunkProvider().getChunkAtImmediately(x, z); + IChunkAccess immediate = world.getChunkProvider().getChunkAtImmediately(x, z);
+ if (immediate == null) {
+ immediate = world.getChunkProvider().playerChunkMap.getUnloadingChunk(x, z);
+ }
+ if (immediate != null) { + if (immediate != null) {
+ if (!(immediate instanceof ProtoChunkExtension) && !(immediate instanceof net.minecraft.server.Chunk)) { + if (!(immediate instanceof ProtoChunkExtension) && !(immediate instanceof net.minecraft.server.Chunk)) {
+ return false; // not full status + return false; // not full status
@ -333,12 +350,8 @@ index acf151a25..a734a87c4 100644
+ world.getChunkProvider().addTicket(TicketType.PLUGIN, chunkPos, 1, Unit.INSTANCE); + world.getChunkProvider().addTicket(TicketType.PLUGIN, chunkPos, 1, Unit.INSTANCE);
+ world.getChunkAt(x, z); // make sure we're at ticket level 32 or lower + world.getChunkAt(x, z); // make sure we're at ticket level 32 or lower
+ return true; + return true;
} + }
+
- if (chunk instanceof net.minecraft.server.Chunk) {
- world.getChunkProvider().addTicket(TicketType.PLUGIN, new ChunkCoordIntPair(x, z), 1, Unit.INSTANCE);
- return true;
+ if (!generate) {
+ net.minecraft.server.RegionFile file; + net.minecraft.server.RegionFile file;
+ try { + try {
+ file = world.getChunkProvider().playerChunkMap.getRegionFile(chunkPos, false); + file = world.getChunkProvider().playerChunkMap.getRegionFile(chunkPos, false);
@ -368,7 +381,7 @@ index acf151a25..a734a87c4 100644
} }
@Override @Override
@@ -2251,21 +2287,40 @@ public class CraftWorld implements World { @@ -2251,21 +2294,44 @@ public class CraftWorld implements World {
// Paper start // Paper start
private Chunk getChunkAtGen(int x, int z, boolean gen) { private Chunk getChunkAtGen(int x, int z, boolean gen) {
@ -382,17 +395,20 @@ index acf151a25..a734a87c4 100644
- if (chunk instanceof ProtoChunkExtension) { - if (chunk instanceof ProtoChunkExtension) {
- // We then cycle through again to get the full chunk immediately, rather than after the ticket addition - // We then cycle through again to get the full chunk immediately, rather than after the ticket addition
- chunk = world.getChunkProvider().getChunkAt(x, z, ChunkStatus.FULL, true); - chunk = world.getChunkProvider().getChunkAt(x, z, ChunkStatus.FULL, true);
- }
+ if (!gen) {
+
+ IChunkAccess immediate = world.getChunkProvider().getChunkAtImmediately(x, z); + IChunkAccess immediate = world.getChunkProvider().getChunkAtImmediately(x, z);
+ if (immediate == null) {
+ immediate = world.getChunkProvider().playerChunkMap.getUnloadingChunk(x, z);
+ }
+ if (immediate != null) { + if (immediate != null) {
+ if (!(immediate instanceof ProtoChunkExtension) && !(immediate instanceof net.minecraft.server.Chunk)) { + if (!(immediate instanceof ProtoChunkExtension) && !(immediate instanceof net.minecraft.server.Chunk)) {
+ return null; // not full status + return null; // not full status
+ } + }
+ return world.getChunkAt(x, z).bukkitChunk; // make sure we're at ticket level 32 or lower + return world.getChunkAt(x, z).bukkitChunk; // make sure we're at ticket level 33 or lower
} + }
+
- if (chunk instanceof net.minecraft.server.Chunk) {
- return ((net.minecraft.server.Chunk)chunk).bukkitChunk;
+ if (!gen) {
+ net.minecraft.server.RegionFile file; + net.minecraft.server.RegionFile file;
+ try { + try {
+ file = world.getChunkProvider().playerChunkMap.getRegionFile(chunkPos, false); + file = world.getChunkProvider().playerChunkMap.getRegionFile(chunkPos, false);
@ -409,7 +425,9 @@ index acf151a25..a734a87c4 100644
+ if (!(chunk instanceof ProtoChunkExtension) && !(chunk instanceof net.minecraft.server.Chunk)) { + if (!(chunk instanceof ProtoChunkExtension) && !(chunk instanceof net.minecraft.server.Chunk)) {
+ return null; + return null;
+ } + }
+
- if (chunk instanceof net.minecraft.server.Chunk) {
- return ((net.minecraft.server.Chunk)chunk).bukkitChunk;
+ // fall through to load + // fall through to load
+ // we load at empty so we don't double-load chunk data in this case + // we load at empty so we don't double-load chunk data in this case
} }

View File

@ -1,4 +1,4 @@
From 48964ee44dba83311bac3ea611cb999c4e3baa30 Mon Sep 17 00:00:00 2001 From 82e48d04c1fc9edf9bf5bc8f1a36f1fd941c2924 Mon Sep 17 00:00:00 2001
From: stonar96 <minecraft.stonar96@gmail.com> From: stonar96 <minecraft.stonar96@gmail.com>
Date: Mon, 20 Aug 2018 03:03:58 +0200 Date: Mon, 20 Aug 2018 03:03:58 +0200
Subject: [PATCH] Anti-Xray Subject: [PATCH] Anti-Xray
@ -1573,7 +1573,7 @@ index 98590e233a..af934ef8bc 100644
this.a(new PacketPlayOutMultiBlockChange(this.dirtyCount, this.dirtyBlocks, chunk), false); this.a(new PacketPlayOutMultiBlockChange(this.dirtyCount, this.dirtyBlocks, chunk), false);
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 36ce789127..e698e1c931 100644 index 58e31380ab..8aa610bae0 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -526,7 +526,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { @@ -526,7 +526,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@ -1585,7 +1585,7 @@ index 36ce789127..e698e1c931 100644
}, this.executor); }, this.executor);
} }
@@ -1223,7 +1223,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { @@ -1228,7 +1228,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
private void a(EntityPlayer entityplayer, Packet<?>[] apacket, Chunk chunk) { private void a(EntityPlayer entityplayer, Packet<?>[] apacket, Chunk chunk) {
if (apacket[0] == null) { if (apacket[0] == null) {
@ -1595,7 +1595,7 @@ index 36ce789127..e698e1c931 100644
} }
diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java
index f953bd7ceb..596b87bc06 100644 index 1c79890e3f..e5e9de542b 100644
--- a/src/main/java/net/minecraft/server/PlayerInteractManager.java --- a/src/main/java/net/minecraft/server/PlayerInteractManager.java
+++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java +++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java
@@ -253,6 +253,8 @@ public class PlayerInteractManager { @@ -253,6 +253,8 @@ public class PlayerInteractManager {