Skip to content
This repository was archived by the owner on Dec 29, 2023. It is now read-only.

Commit fed8bbb

Browse files
committed
Backport World#isChunkGenerated
1 parent 809a149 commit fed8bbb

3 files changed

+111
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
From 69935bebe7e9f1c6ea28dcf5aafa90b22676e495 Mon Sep 17 00:00:00 2001
2+
From: Peridot <[email protected]>
3+
Date: Sat, 5 Nov 2022 21:53:26 +0100
4+
Subject: [PATCH] Backport World#isChunkGenerated
5+
6+
7+
@@ -496,6 +496,26 @@ public class Location implements Cloneable, ConfigurationSerializable {
8+
}
9+
10+
// Paper start
11+
+ /**
12+
+ * Check if a {@link Chunk} has been loaded at this location.
13+
+ *
14+
+ * @return true if the chunk has been loaded at this location
15+
+ */
16+
+ public boolean isChunkLoaded() {
17+
+ Preconditions.checkNotNull(world, "Location has no world!");
18+
+ return world.isChunkLoaded(locToBlock(x) >> 4, locToBlock(z) >> 4);
19+
+ }
20+
+
21+
+ /**
22+
+ * Checks if a {@link Chunk} has been generated at this location.
23+
+ *
24+
+ * @return true if a chunk has been generated at this location
25+
+ */
26+
+ public boolean isGenerated() {
27+
+ Preconditions.checkNotNull(world, "Location has no world!");
28+
+ return world.isChunkGenerated(locToBlock(x) >> 4, locToBlock(z) >> 4);
29+
+ }
30+
+
31+
/**
32+
* Sets the position of this Location and returns itself
33+
*
34+
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
35+
index f36906eb..74a52dd1 100644
36+
--- a/src/main/java/org/bukkit/World.java
37+
+++ b/src/main/java/org/bukkit/World.java
38+
@@ -631,6 +631,17 @@ public interface World extends PluginMessageRecipient, Metadatable {
39+
*/
40+
public boolean isChunkLoaded(int x, int z);
41+
42+
+ // Titanium start - Backport #isChunkGenerated
43+
+ /**
44+
+ * Checks if the {@link Chunk} at the specified coordinates is generated
45+
+ *
46+
+ * @param x X-coordinate of the chunk
47+
+ * @param z Z-coordinate of the chunk
48+
+ * @return true if the chunk is generated, otherwise false
49+
+ */
50+
+ public boolean isChunkGenerated(int x, int z);
51+
+ // Titanium end
52+
+
53+
/**
54+
* Checks if the {@link Chunk} at the specified coordinates is loaded and
55+
* in use by one or more players
56+
--
57+
2.38.1.windows.1
58+

patches/server/0083-Implement-Paper-0378-Performance-improvement-for-Chu.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ From b84a3455d052204bc3d438c9de04872e11d81d08 Mon Sep 17 00:00:00 2001
22
From: wea_ondara <[email protected]>
33
Date: Sat, 4 Jun 2022 13:02:23 +0200
44
Subject: [PATCH] Implement [Paper-0378] Performance improvement for
5-
Chunk.getEntities Add
5+
Chunk.getEntities by wea_oandra
66

77

88
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
From 0c6ee54229dc9e060ed5c44b6c4169b898996066 Mon Sep 17 00:00:00 2001
2+
From: Peridot <[email protected]>
3+
Date: Sat, 5 Nov 2022 21:53:17 +0100
4+
Subject: [PATCH] Backport World#isChunkGenerated
5+
6+
7+
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
8+
index 32b584440..3f648ff36 100644
9+
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
10+
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
11+
@@ -41,6 +41,11 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
12+
return region != null && region.chunkExists(i & 31, j & 31); // PaperSpigot
13+
}
14+
// CraftBukkit end
15+
+ // Titanium start
16+
+ public boolean chunkExists(int i, int j) {
17+
+ return this.chunkExists(null, i, j);
18+
+ }
19+
+ // Titanium end
20+
21+
// CraftBukkit start - Add async variant, provide compatibility
22+
public Chunk a(World world, int i, int j) throws IOException {
23+
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
24+
index be4a5fc3c..fac98d03f 100644
25+
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
26+
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
27+
@@ -149,6 +149,22 @@ public class CraftWorld implements World {
28+
return world.chunkProviderServer.isChunkLoaded(x, z);
29+
}
30+
31+
+ // Titanium start - Backport World#isChunkGenerated
32+
+ @Override
33+
+ public boolean isChunkGenerated(int x, int z) {
34+
+ if (isChunkLoaded(x, z)) {
35+
+ return true;
36+
+ }
37+
+
38+
+ // Titanium start - add instanceof check
39+
+ if (!(world.chunkProviderServer.chunkLoader instanceof ChunkRegionLoader)) {
40+
+ return false;
41+
+ }
42+
+ // Titanium end
43+
+ return ((ChunkRegionLoader) world.chunkProviderServer.chunkLoader).chunkExists(x, z);
44+
+ }
45+
+ // Titanium end
46+
+
47+
public Chunk[] getLoadedChunks() {
48+
Object[] chunks = world.chunkProviderServer.chunks.values().toArray();
49+
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
50+
--
51+
2.38.1.windows.1
52+

0 commit comments

Comments
 (0)