diff --git a/Spigot-Server-Patches/Anti-Xray.patch b/Spigot-Server-Patches/Anti-Xray.patch index bbb9e39cf..bb5c3155e 100644 --- a/Spigot-Server-Patches/Anti-Xray.patch +++ b/Spigot-Server-Patches/Anti-Xray.patch @@ -1418,7 +1418,7 @@ index 22a262bb60..40ec398eef 100644 if (flag) { packetdataserializer.writeBytes(chunksection.getSkyLightArray().asBytes()); diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java -index f8d8a44a88..e7d465fb8a 100644 +index 84896d6f6b..2a889dc20a 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 { diff --git a/Spigot-Server-Patches/Async-Chunk-Loading-and-Generation.patch b/Spigot-Server-Patches/Async-Chunk-Loading-and-Generation.patch index 24e93d336..9564e1bf6 100644 --- a/Spigot-Server-Patches/Async-Chunk-Loading-and-Generation.patch +++ b/Spigot-Server-Patches/Async-Chunk-Loading-and-Generation.patch @@ -1215,7 +1215,7 @@ index 0000000000..47d9ecdbf1 + +} diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java -index e7d465fb8a..61de438fdf 100644 +index 2a889dc20a..242691d89d 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 { @@ -1265,8 +1265,8 @@ index e7d465fb8a..61de438fdf 100644 + } + // Paper end // Paper start - delay chunk unloads - public final void markChunkUsed() { - if (chunk != null && chunk.scheduledForUnload != null) { + private void markChunkUsed() { + if (chunk == null) { @@ -0,0 +0,0 @@ public class PlayerChunk { ChunkProviderServer chunkproviderserver = playerchunkmap.getWorld().getChunkProviderServer(); @@ -1279,8 +1279,8 @@ index e7d465fb8a..61de438fdf 100644 } @@ -0,0 +0,0 @@ public class PlayerChunk { - if (this.c.isEmpty()) { - this.i = this.playerChunkMap.getWorld().getTime(); + chunkHasPlayers = false; // Paper - delay chunk unloads + markChunkUsed(); // Paper - delay chunk unloads } + checkHighPriority(entityplayer); // Paper diff --git a/Spigot-Server-Patches/Configurable-Max-Chunk-Gens-per-Tick.patch b/Spigot-Server-Patches/Configurable-Max-Chunk-Gens-per-Tick.patch index 257c4ff7c..4ec9196e1 100644 --- a/Spigot-Server-Patches/Configurable-Max-Chunk-Gens-per-Tick.patch +++ b/Spigot-Server-Patches/Configurable-Max-Chunk-Gens-per-Tick.patch @@ -33,7 +33,7 @@ index af69342e6c..ca7efc9175 100644 + } } diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java -index 3f4a8f21c0..f8d8a44a88 100644 +index abf5a7554d..84896d6f6b 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 { diff --git a/Spigot-Server-Patches/Delay-Chunk-Unloads-based-on-Player-Movement.patch b/Spigot-Server-Patches/Delay-Chunk-Unloads-based-on-Player-Movement.patch index eca650a45..e08efe584 100644 --- a/Spigot-Server-Patches/Delay-Chunk-Unloads-based-on-Player-Movement.patch +++ b/Spigot-Server-Patches/Delay-Chunk-Unloads-based-on-Player-Movement.patch @@ -16,6 +16,9 @@ before it actually unloads, which is maintained separately from ChunkGC. This allows servers with smaller worlds who do less long distance exploring to stop wasting cpu cycles on saving/unloading/reloading chunks repeatedly. +This also makes the Chunk GC System useless, by auto scheduling unload as soon as +a spare chunk is added to the server thats outside of view distance. + diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java index ff1a2046f6..0cd15c17e8 100644 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java @@ -51,6 +54,26 @@ index 41d3aaa80b..824727ec66 100644 public final int locX; public final int locZ; private boolean l; public boolean needsGapCheck() { return l; } // Paper - OBFHELPER +diff --git a/src/main/java/net/minecraft/server/ChunkMap.java b/src/main/java/net/minecraft/server/ChunkMap.java +index df967ff07d..a3dc90fd2b 100644 +--- a/src/main/java/net/minecraft/server/ChunkMap.java ++++ b/src/main/java/net/minecraft/server/ChunkMap.java +@@ -0,0 +0,0 @@ public class ChunkMap extends Long2ObjectOpenHashMap { + } + } + } ++ // Paper start - if this is a spare chunk (not part of any players view distance), go ahead and queue it for unload. ++ if (!((WorldServer)chunk.world).getPlayerChunkMap().isChunkInUse(chunk.locX, chunk.locZ)) { ++ if (chunk.world.paperConfig.delayChunkUnloadsBy > 0) { ++ chunk.scheduledForUnload = System.currentTimeMillis(); ++ } else { ++ ((WorldServer) chunk.world).getChunkProviderServer().unload(chunk); ++ } ++ } ++ // Paper end + chunk.world.timings.syncChunkLoadPostTimer.stopTiming(); // Paper + // CraftBukkit end + diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java index 2d10f4aa37..719d5deb2c 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -76,7 +99,7 @@ index 2d10f4aa37..719d5deb2c 100644 this.chunkScheduler.a(booleansupplier); } diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java -index ac0e90eeca..3f4a8f21c0 100644 +index ac0e90eeca..abf5a7554d 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 { @@ -87,11 +110,17 @@ index ac0e90eeca..3f4a8f21c0 100644 } }; + // Paper start - delay chunk unloads -+ public final void markChunkUsed() { -+ if (chunk != null && chunk.scheduledForUnload != null) { ++ private void markChunkUsed() { ++ if (chunk == null) { ++ return; ++ } ++ if (!chunkHasPlayers) { + chunk.scheduledForUnload = null; ++ } else if (chunk.scheduledForUnload == null) { ++ chunk.scheduledForUnload = System.currentTimeMillis(); + } + } ++ private boolean chunkHasPlayers = true; + // Paper end // CraftBukkit end @@ -104,6 +133,24 @@ index ac0e90eeca..3f4a8f21c0 100644 } public ChunkCoordIntPair a() { +@@ -0,0 +0,0 @@ public class PlayerChunk { + } else { + if (this.c.isEmpty()) { + this.i = this.playerChunkMap.getWorld().getTime(); ++ chunkHasPlayers = false; // Paper - delay chunk unloads ++ markChunkUsed(); // Paper - delay chunk unloads + } + + this.c.add(entityplayer); +@@ -0,0 +0,0 @@ public class PlayerChunk { + + this.c.remove(entityplayer); + if (this.c.isEmpty()) { ++ chunkHasPlayers = true; // Paper - delay chunk unloads ++ markChunkUsed(); // Paper - delay chunk unloads + this.playerChunkMap.b(this); + } + @@ -0,0 +0,0 @@ public class PlayerChunk { return true; } else { diff --git a/Spigot-Server-Patches/Fix-Sending-Chunks-to-Client.patch b/Spigot-Server-Patches/Fix-Sending-Chunks-to-Client.patch index 96b1b7b03..aef1379d8 100644 --- a/Spigot-Server-Patches/Fix-Sending-Chunks-to-Client.patch +++ b/Spigot-Server-Patches/Fix-Sending-Chunks-to-Client.patch @@ -41,7 +41,7 @@ index 895eb60854..350479dc68 100644 } diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java -index 61de438fdf..fca88c3018 100644 +index 242691d89d..86f0fb3c2a 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 {