2021-06-11 14:02:28 +02:00
|
|
|
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/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
2024-06-13 17:45:43 +02:00
|
|
|
index fe0521ad6f0601ebdf7a616c0500479ecb34cabb..fa2df210b05529d228c5ee208f125dcf5288dfec 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
2024-04-24 08:05:14 +02:00
|
|
|
@@ -252,6 +252,12 @@ public class ServerChunkCache extends ChunkSource {
|
2021-06-11 14:02:28 +02:00
|
|
|
return this.getChunk(x, z, leastStatus, create);
|
|
|
|
}, this.mainThreadProcessor).join();
|
|
|
|
} else {
|
2024-01-21 12:53:04 +01:00
|
|
|
+ // Paper start - Perf: Optimise getChunkAt calls for loaded chunks
|
2021-06-11 14:02:28 +02:00
|
|
|
+ LevelChunk ifLoaded = this.getChunkAtIfLoadedMainThread(x, z);
|
|
|
|
+ if (ifLoaded != null) {
|
|
|
|
+ return ifLoaded;
|
|
|
|
+ }
|
2024-01-21 12:53:04 +01:00
|
|
|
+ // Paper end - Perf: Optimise getChunkAt calls for loaded chunks
|
2021-06-11 14:02:28 +02:00
|
|
|
ProfilerFiller gameprofilerfiller = this.level.getProfiler();
|
|
|
|
|
|
|
|
gameprofilerfiller.incrementCounter("getChunk");
|
2024-04-24 08:05:14 +02:00
|
|
|
@@ -295,39 +301,7 @@ public class ServerChunkCache extends ChunkSource {
|
2024-01-24 13:07:40 +01:00
|
|
|
if (Thread.currentThread() != this.mainThread) {
|
2021-06-11 14:02:28 +02:00
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
- this.level.getProfiler().incrementCounter("getChunkNow");
|
|
|
|
- long k = ChunkPos.asLong(chunkX, chunkZ);
|
|
|
|
-
|
|
|
|
- for (int l = 0; l < 4; ++l) {
|
|
|
|
- if (k == this.lastChunkPos[l] && this.lastChunkStatus[l] == ChunkStatus.FULL) {
|
|
|
|
- ChunkAccess ichunkaccess = this.lastChunk[l];
|
|
|
|
-
|
|
|
|
- return ichunkaccess instanceof LevelChunk ? (LevelChunk) ichunkaccess : null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ChunkHolder playerchunk = this.getVisibleChunkIfPresent(k);
|
|
|
|
-
|
|
|
|
- if (playerchunk == null) {
|
|
|
|
- return null;
|
|
|
|
- } else {
|
2024-04-24 08:05:14 +02:00
|
|
|
- ChunkResult<ChunkAccess> chunkresult = (ChunkResult) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
|
2021-06-11 14:02:28 +02:00
|
|
|
-
|
2024-04-24 08:05:14 +02:00
|
|
|
- if (chunkresult == null) {
|
2021-06-11 14:02:28 +02:00
|
|
|
- return null;
|
|
|
|
- } else {
|
2024-04-24 08:05:14 +02:00
|
|
|
- ChunkAccess ichunkaccess1 = (ChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error
|
2021-06-11 14:02:28 +02:00
|
|
|
-
|
|
|
|
- if (ichunkaccess1 != null) {
|
|
|
|
- this.storeInCache(k, ichunkaccess1, ChunkStatus.FULL);
|
|
|
|
- if (ichunkaccess1 instanceof LevelChunk) {
|
|
|
|
- return (LevelChunk) ichunkaccess1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- }
|
2024-01-21 12:53:04 +01:00
|
|
|
+ return this.getChunkAtIfLoadedMainThread(chunkX, chunkZ); // Paper - Perf: Optimise getChunkAt calls for loaded chunks
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|