Paper/Spigot-Server-Patches/0404-Optimise-getChunkAt-calls-for-loaded-chunks.patch
Shane Freeder 0ea3083817
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear 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:
1e843b72 #510: Add NamespacedKey#fromString() to fetch from user input
a4d18241 #581: Add methods to modify despawn delay for wandering villagers

CraftBukkit Changes:
0cd8f19f #802: Add methods to modify despawn delay for wandering villagers
d5c5d998 SPIGOT-6362: ConcurrentModificationException: null --> Server Crash
8c7d69fe SPIGOT-5228: Entities that are removed during chunk unloads are not properly removed from the chunk.
2021-02-16 17:13:49 +00:00

67 Zeilen
2.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sat, 25 Jan 2020 17:04:35 -0800
Subject: [PATCH] Optimise getChunkAt calls for loaded chunks
bypass the need to get a player chunk, then get the either,
then unwrap it...
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 1eb201695cd118616fb404a0c7ed8cedee77db89..e0296920a794157d89bb314b162de706d69a5459 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -447,6 +447,12 @@ public class ChunkProviderServer extends IChunkProvider {
return this.getChunkAt(i, j, chunkstatus, flag);
}, this.serverThreadQueue).join();
} else {
+ // Paper start - optimise for loaded chunks
+ Chunk ifLoaded = this.getChunkAtIfLoadedMainThread(i, j);
+ if (ifLoaded != null) {
+ return ifLoaded;
+ }
+ // Paper end
GameProfilerFiller gameprofilerfiller = this.world.getMethodProfiler();
gameprofilerfiller.c("getChunk");
@@ -497,39 +503,7 @@ public class ChunkProviderServer extends IChunkProvider {
if (Thread.currentThread() != this.serverThread) {
return null;
} else {
- this.world.getMethodProfiler().c("getChunkNow");
- long k = ChunkCoordIntPair.pair(i, j);
-
- for (int l = 0; l < 4; ++l) {
- if (k == this.cachePos[l] && this.cacheStatus[l] == ChunkStatus.FULL) {
- IChunkAccess ichunkaccess = this.cacheChunk[l];
-
- return ichunkaccess instanceof Chunk ? (Chunk) ichunkaccess : null;
- }
- }
-
- PlayerChunk playerchunk = this.getChunk(k);
-
- if (playerchunk == null) {
- return null;
- } else {
- Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.b(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
-
- if (either == null) {
- return null;
- } else {
- IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error
-
- if (ichunkaccess1 != null) {
- this.a(k, ichunkaccess1, ChunkStatus.FULL);
- if (ichunkaccess1 instanceof Chunk) {
- return (Chunk) ichunkaccess1;
- }
- }
-
- return null;
- }
- }
+ return this.getChunkAtIfLoadedMainThread(i, j); // Paper - optimise for loaded chunks
}
}