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
|
2022-12-07 20:22:28 +01:00
|
|
|
index d137aa95f670aab516e9e08272f33b2125b282c6..f838a921a08981bac0d0c0a68e334ba06d11cb18 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
|
2022-12-07 20:22:28 +01:00
|
|
|
@@ -421,6 +421,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 {
|
|
|
|
+ // Paper start - optimise for loaded chunks
|
|
|
|
+ LevelChunk ifLoaded = this.getChunkAtIfLoadedMainThread(x, z);
|
|
|
|
+ if (ifLoaded != null) {
|
|
|
|
+ return ifLoaded;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
ProfilerFiller gameprofilerfiller = this.level.getProfiler();
|
|
|
|
|
|
|
|
gameprofilerfiller.incrementCounter("getChunk");
|
2022-12-07 20:22:28 +01:00
|
|
|
@@ -464,39 +470,7 @@ public class ServerChunkCache extends ChunkSource {
|
2022-09-26 10:02:51 +02:00
|
|
|
if (!io.papermc.paper.util.TickThread.isTickThread()) { // Paper - rewrite chunk system
|
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 {
|
|
|
|
- Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = (Either) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
|
|
|
|
-
|
|
|
|
- if (either == null) {
|
|
|
|
- return null;
|
|
|
|
- } else {
|
|
|
|
- ChunkAccess ichunkaccess1 = (ChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error
|
|
|
|
-
|
|
|
|
- if (ichunkaccess1 != null) {
|
|
|
|
- this.storeInCache(k, ichunkaccess1, ChunkStatus.FULL);
|
|
|
|
- if (ichunkaccess1 instanceof LevelChunk) {
|
|
|
|
- return (LevelChunk) ichunkaccess1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
+ return this.getChunkAtIfLoadedMainThread(chunkX, chunkZ); // Paper - optimise for loaded chunks
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|