Add API to get Tile Entities in a Chunk by Predicate

This commit is contained in:
Matthew Miller 2020-12-18 21:24:21 +10:00 committed by Mariell
parent 4643944343
commit 0bdfb01589
5 changed files with 80 additions and 24 deletions

View file

@ -5,33 +5,52 @@ Subject: [PATCH] Ability to get Tile Entities from a chunk without snapshots
diff --git a/src/main/java/org/bukkit/Chunk.java b/src/main/java/org/bukkit/Chunk.java
index fa576096e908f8fbdbef53e1bd91215ac9e73ed6..b4ef6297f78d1f0c216e718024a21e6aa07cd1c6 100644
index fa576096e908f8fbdbef53e1bd91215ac9e73ed6..98263d896f316983609432c45b85401a2692432d 100644
--- a/src/main/java/org/bukkit/Chunk.java
+++ b/src/main/java/org/bukkit/Chunk.java
@@ -103,13 +103,26 @@ public interface Chunk extends PersistentDataHolder {
@@ -1,6 +1,8 @@
package org.bukkit;
import java.util.Collection;
+import java.util.function.Predicate;
+
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
@@ -103,13 +105,36 @@ public interface Chunk extends PersistentDataHolder {
@NotNull
Entity[] getEntities();
+ // Paper start
+ /**
+ * Get a list of all tile entities in the chunk.
+ *
+ * @return The tile entities.
+ */
+ @NotNull
+ default BlockState[] getTileEntities() {
+ return getTileEntities(true);
+ }
+
/**
* Get a list of all tile entities in the chunk.
*
+ * @param useSnapshot Take snapshots or direct references
* @return The tile entities.
*/
@NotNull
- BlockState[] getTileEntities();
+ default BlockState[] getTileEntities() {
+ return getTileEntities(true);
+ }
+
+ /**
+ * Get a list of all tile entities in the chunk.
+ *
+ * @param useSnapshot Take snapshots or direct references
+ * @return The tile entities.
+ */
+ @NotNull
+ BlockState[] getTileEntities(boolean useSnapshot);
+
+ /**
+ * Get a list of all tile entities that match a given predicate in the chunk.
+ *
+ * @param blockPredicate The predicate of blocks to return tile entities for
+ * @param useSnapshot Take snapshots or direct references
+ * @return The tile entities.
+ */
+ @NotNull
+ Collection<BlockState> getTileEntities(@NotNull Predicate<Block> blockPredicate, boolean useSnapshot);
+ // Paper end
/**