From 0b65fda2e0fefa5bdba1d5495744911bcf32fe9d Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sun, 2 Apr 2023 13:10:32 +1000 Subject: [PATCH] #832: Allow getting chunks without generating them and optimize chunk data request for ungenerated chunks By: DerFrZocker --- paper-api/src/main/java/org/bukkit/Chunk.java | 13 ++++++++++++- paper-api/src/main/java/org/bukkit/World.java | 11 +++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/paper-api/src/main/java/org/bukkit/Chunk.java b/paper-api/src/main/java/org/bukkit/Chunk.java index a33379e6df..94db3cfa41 100644 --- a/paper-api/src/main/java/org/bukkit/Chunk.java +++ b/paper-api/src/main/java/org/bukkit/Chunk.java @@ -11,7 +11,11 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; /** - * Represents a chunk of blocks + * Represents a chunk of blocks. + * + * If the chunk is not yet fully generated and data is requested from the chunk, + * then the chunk will only be generated as far as it needs to provide the + * requested data. */ public interface Chunk extends PersistentDataHolder { @@ -94,6 +98,13 @@ public interface Chunk extends PersistentDataHolder { @NotNull BlockState[] getTileEntities(); + /** + * Checks if the chunk is fully generated. + * + * @return True if it is fully generated. + */ + boolean isGenerated(); + /** * Checks if the chunk is loaded. * diff --git a/paper-api/src/main/java/org/bukkit/World.java b/paper-api/src/main/java/org/bukkit/World.java index 456b8d9376..a4cb298c43 100644 --- a/paper-api/src/main/java/org/bukkit/World.java +++ b/paper-api/src/main/java/org/bukkit/World.java @@ -164,6 +164,17 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient @NotNull public Chunk getChunkAt(int x, int z); + /** + * Gets the {@link Chunk} at the given coordinates + * + * @param x X-coordinate of the chunk + * @param z Z-coordinate of the chunk + * @param generate Whether the chunk should be fully generated or not + * @return Chunk at the given coordinates + */ + @NotNull + public Chunk getChunkAt(int x, int z, boolean generate); + /** * Gets the {@link Chunk} at the given {@link Location} *