aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0321-Optimise-getChunkAt-calls-for-loaded-chunks.patch
blob: a96e5d47696ec08f7ef2c7ad2360b4fa5558a5a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
index bc81649b09c39188697b8851abedafca0dde9d99..d41c0e4474d057c7b13427bfd896c50f24232615 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -252,6 +252,12 @@ public class ServerChunkCache extends ChunkSource {
                 return this.getChunk(x, z, leastStatus, create);
             }, this.mainThreadProcessor).join();
         } else {
+            // Paper start - Perf: Optimise getChunkAt calls for loaded chunks
+            LevelChunk ifLoaded = this.getChunkAtIfLoadedMainThread(x, z);
+            if (ifLoaded != null) {
+                return ifLoaded;
+            }
+            // Paper end - Perf: Optimise getChunkAt calls for loaded chunks
             ProfilerFiller gameprofilerfiller = this.level.getProfiler();
 
             gameprofilerfiller.incrementCounter("getChunk");
@@ -295,39 +301,7 @@ public class ServerChunkCache extends ChunkSource {
         if (Thread.currentThread() != this.mainThread) {
             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 {
-                ChunkResult<ChunkAccess> chunkresult = (ChunkResult) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
-
-                if (chunkresult == null) {
-                    return null;
-                } else {
-                    ChunkAccess ichunkaccess1 = (ChunkAccess) chunkresult.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 - Perf: Optimise getChunkAt calls for loaded chunks
         }
     }