diff --git a/Spigot-Server-Patches/MC-Utils.patch b/Spigot-Server-Patches/MC-Utils.patch index 9ccdeb754b..b979f707c7 100644 --- a/Spigot-Server-Patches/MC-Utils.patch +++ b/Spigot-Server-Patches/MC-Utils.patch @@ -2681,7 +2681,32 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/server/ChunkCoordIntPair.java +++ b/src/main/java/net/minecraft/server/ChunkCoordIntPair.java @@ -0,0 +0,0 @@ public class ChunkCoordIntPair { - return pair(this.x, this.z); + public static final long a = pair(1875016, 1875016); + public final int x; + public final int z; ++ public final long longKey; // Paper + + public ChunkCoordIntPair(int i, int j) { + this.x = i; + this.z = j; ++ this.longKey = pair(this.x, this.z); // Paper + } + + public ChunkCoordIntPair(BlockPosition blockposition) { + this.x = blockposition.getX() >> 4; + this.z = blockposition.getZ() >> 4; ++ this.longKey = pair(this.x, this.z); // Paper + } + + public ChunkCoordIntPair(long i) { + this.x = (int) i; + this.z = (int) (i >> 32); ++ this.longKey = pair(this.x, this.z); // Paper + } + + public long pair() { +- return pair(this.x, this.z); ++ return longKey; // Paper } - public static long pair(int i, int j) { diff --git a/Spigot-Server-Patches/Unload-leaked-Cached-Chunks.patch b/Spigot-Server-Patches/Unload-leaked-Cached-Chunks.patch index 1e28999020..5ae744cc9c 100644 --- a/Spigot-Server-Patches/Unload-leaked-Cached-Chunks.patch +++ b/Spigot-Server-Patches/Unload-leaked-Cached-Chunks.patch @@ -30,39 +30,60 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 if (isUrgent) { future.thenAccept(either -> this.chunkMapDistance.clearUrgent(chunkcoordintpair)); @@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider { + this.world.timings.countNaturalMobs.stopTiming(); // Paper - timings + this.world.getMethodProfiler().exit(); + // Paper - replaced by above ++ final long time = world.getTime(); // Paper + final int[] chunksTicked = {0}; this.playerChunkMap.forEachVisibleChunk((playerchunk) -> { // Paper - safe iterator incase chunk loads, also no wrapping + Optional optional = ((Either) playerchunk.b().getNow(PlayerChunk.UNLOADED_CHUNK)).left(); + +@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider { + this.world.timings.chunkTicks.stopTiming(); // Spigot // Paper if (chunksTicked[0]++ % 10 == 0) this.world.getMinecraftServer().midTickLoadChunks(); // Paper } - } -+ // Paper start - remove inaccessible chunks leaked -+ else if (playerchunk.getTicketLevel() == playerchunk.oldTicketLevel && -+ playerChunkMap.unloadQueue.size() < 100 && -+ (playerchunk.lastActivity == 0 || world.getTime() - playerchunk.lastActivity > 20*180) && -+ PlayerChunk.getChunkState(playerchunk.getTicketLevel()) == PlayerChunk.State.INACCESSIBLE -+ ) { -+ ChunkStatus chunkHolderStatus = playerchunk.getChunkHolderStatus(); -+ ChunkStatus desiredStatus = PlayerChunk.getChunkStatus(playerchunk.getTicketLevel()); -+ if (chunkHolderStatus != null && !chunkHolderStatus.isAtLeastStatus(desiredStatus)) { -+ return; -+ } -+ if (playerchunk.lastActivity == 0) { -+ playerchunk.lastActivity = world.getTime(); -+ return; -+ } -+ playerchunk.lastActivity = world.getTime(); -+ Chunk chunk = playerchunk.getChunk(); -+ if ((chunk != null && chunk.isAnyNeighborsLoaded()) || !playerchunk.neighborPriorities.isEmpty()) { -+ return; -+ } -+ long key = playerchunk.location.pair(); -+ ArraySetSorted> tickets = playerChunkMap.chunkDistanceManager.tickets.get(key); -+ if (tickets == null || tickets.isEmpty()) { -+ playerChunkMap.unloadQueue.add(key); -+ } -+ // Paper end -+ } +- } ++ } else { checkInactiveChunk(playerchunk, time); } // Paper - check inaccessible chunks }); this.world.getMethodProfiler().enter("customSpawners"); if (flag1) { +@@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider { + this.playerChunkMap.g(); + } + ++ // Paper start - remove inaccessible chunks leaked ++ private void checkInactiveChunk(PlayerChunk playerchunk, long time) { ++ int ticketLevel = playerchunk.getTicketLevel(); ++ if (ticketLevel > 33 && ticketLevel == playerchunk.oldTicketLevel && ++ (playerchunk.lastActivity == 0 || time - playerchunk.lastActivity > 20*180) && ++ playerchunk.location.pair() % 20 == 0 && playerChunkMap.unloadQueue.size() < 100 && ++ PlayerChunk.getChunkState(ticketLevel) == PlayerChunk.State.INACCESSIBLE ++ ) { ++ ChunkStatus chunkHolderStatus = playerchunk.getChunkHolderStatus(); ++ ChunkStatus desiredStatus = PlayerChunk.getChunkStatus(ticketLevel); ++ if (chunkHolderStatus != null && !chunkHolderStatus.isAtLeastStatus(desiredStatus)) { ++ return; ++ } ++ if (playerchunk.lastActivity == 0) { ++ playerchunk.lastActivity = time; ++ return; ++ } ++ playerchunk.lastActivity = time; ++ Chunk chunk = playerchunk.getChunk(); ++ if ((chunk != null && chunk.isAnyNeighborsLoaded()) || !playerchunk.neighborPriorities.isEmpty()) { ++ return; ++ } ++ long key = playerchunk.location.pair(); ++ ArraySetSorted> tickets = playerChunkMap.chunkDistanceManager.tickets.get(key); ++ if (tickets == null || tickets.isEmpty()) { ++ playerChunkMap.unloadQueue.add(key); ++ } ++ } ++ } ++ // Paper end ++ + @Override + public String getName() { + return "ServerChunkCache: " + this.h(); diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/PlayerChunk.java