2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Wed, 15 Aug 2018 01:16:34 -0400
|
2024-01-21 17:39:05 +01:00
|
|
|
Subject: [PATCH] Ability to get block entities from a chunk without snapshots
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
2024-06-13 16:45:27 +02:00
|
|
|
index 110bdba382c361228c52c1c1f807fef25f127ab5..01596f87ee078fceeb3f2f29bbb2500e63e9efb8 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
2024-06-13 16:45:27 +02:00
|
|
|
@@ -174,6 +174,13 @@ public class CraftChunk implements Chunk {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState[] getTileEntities() {
|
|
|
|
+ // Paper start
|
|
|
|
+ return getTileEntities(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public BlockState[] getTileEntities(boolean useSnapshot) {
|
|
|
|
+ // Paper end
|
2021-06-13 01:45:00 +02:00
|
|
|
if (!this.isLoaded()) {
|
2023-10-27 01:34:58 +02:00
|
|
|
this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
|
2021-06-13 01:45:00 +02:00
|
|
|
}
|
2024-06-13 16:45:27 +02:00
|
|
|
@@ -183,7 +190,29 @@ public class CraftChunk implements Chunk {
|
2023-04-07 20:39:13 +02:00
|
|
|
BlockState[] entities = new BlockState[chunk.blockEntities.size()];
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2023-04-07 20:39:13 +02:00
|
|
|
for (BlockPos position : chunk.blockEntities.keySet()) {
|
2021-06-13 01:45:00 +02:00
|
|
|
- entities[index++] = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState();
|
|
|
|
+ // Paper start
|
|
|
|
+ entities[index++] = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState(useSnapshot);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return entities;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2023-11-26 00:03:02 +01:00
|
|
|
+ public Collection<BlockState> getTileEntities(Predicate<? super Block> blockPredicate, boolean useSnapshot) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ Preconditions.checkNotNull(blockPredicate, "blockPredicate");
|
2023-04-07 20:39:13 +02:00
|
|
|
+ if (!this.isLoaded()) {
|
|
|
|
+ this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2023-04-07 20:39:13 +02:00
|
|
|
+ ChunkAccess chunk = this.getHandle(ChunkStatus.FULL);
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
2023-04-07 20:39:13 +02:00
|
|
|
+ java.util.List<BlockState> entities = new java.util.ArrayList<>();
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
+ for (BlockPos position : chunk.blockEntities.keySet()) {
|
2023-04-07 20:39:13 +02:00
|
|
|
+ Block block = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (blockPredicate.test(block)) {
|
|
|
|
+ entities.add(block.getState(useSnapshot));
|
|
|
|
+ }
|
2021-06-13 01:45:00 +02:00
|
|
|
+ // Paper end
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return entities;
|