From ec460b7767339e06197c27d6a01276ced4835f3e Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 15 Sep 2024 16:49:32 +0800 Subject: [PATCH] docs: add javadocs for Chunk --- .../org/allaymc/api/world/chunk/Chunk.java | 135 +++++++++++++++++- 1 file changed, 133 insertions(+), 2 deletions(-) diff --git a/Allay-API/src/main/java/org/allaymc/api/world/chunk/Chunk.java b/Allay-API/src/main/java/org/allaymc/api/world/chunk/Chunk.java index 4a3a71d70..03897a79f 100644 --- a/Allay-API/src/main/java/org/allaymc/api/world/chunk/Chunk.java +++ b/Allay-API/src/main/java/org/allaymc/api/world/chunk/Chunk.java @@ -12,17 +12,36 @@ import java.util.stream.Collectors; /** - * Allay Project 2023/5/30 + * Chunk represents a 16x16 area in a world. + *
+ * All methods in this class are thread-safe. However, Frequent calls to methods in this class
+ * result in huge lock overhead. If you are sure that the instance won't be accessed by multiple threads,
+ * you can operate on unsafe chunk directly. To get the unsafe chunk, use {@link #toUnsafeChunk()}.
*
- * @author Cool_Loong
+ * @author Cool_Loong | daoge_cmd
*/
@ThreadSafe
public interface Chunk extends UnsafeChunk {
+ /**
+ * Check if the chunk is loaded.
+ *
+ * @return {@code true} if the chunk is loaded, {@code false} otherwise
+ */
boolean isLoaded();
+ /**
+ * Get the chunk loaders that load this chunk
+ *
+ * @return the chunk loaders
+ */
@UnmodifiableView
Set
+ * Chunk packet will be sent to all chunk loaders every tick.
+ *
+ * @param packet the packet to add
+ */
void addChunkPacket(BedrockPacket packet);
+ /**
+ * Add a chunk packet to the chunk.
+ *
+ * Chunk packet will be sent to chunk loaders that match the predicate every tick.
+ *
+ * @param packet the packet to add
+ * @param chunkLoaderPredicate the predicate to match chunk loaders
+ */
void addChunkPacket(BedrockPacket packet, Predicate
+ * This method will only add a lock once, so it is more efficient than calling other methods
+ * in this class frequently.
+ * If you are going to get a range of blocks in the chunk, using this method will be an ideal choice
+ * to avoid lock overhead.
+ *
+ * @param operate the operation to process the chunk
+ */
void batchProcess(UnsafeChunkOperate operate);
+ /**
+ * Get the unsafe chunk of this chunk.
+ *
+ * @return the unsafe chunk
+ */
UnsafeChunk toUnsafeChunk();
+ /**
+ * Spawn entities in this chunk to the specified player.
+ *
+ * @param player the player to spawn entities to
+ */
default void spawnEntitiesTo(EntityPlayer player) {
getEntities().values().forEach(player::spawnEntity);
}
+ /**
+ * Despawn entities in this chunk from the specified player.
+ *
+ * @param player the player to despawn entities from
+ */
default void despawnEntitiesFrom(EntityPlayer player) {
getEntities().values().forEach(player::despawnEntity);
}