mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 12:11:47 +01:00
55 lines
2.3 KiB
Diff
55 lines
2.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Wed, 15 Aug 2018 01:16:34 -0400
|
|
Subject: [PATCH] Ability to get Tile Entities from a chunk without snapshots
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
|
index f07a6b1d782426581c84ffa19447c1375c4cbc07..719730451635d418b3f5024c35620412add42b7f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
|
@@ -169,6 +169,13 @@ public class CraftChunk implements Chunk {
|
|
|
|
@Override
|
|
public BlockState[] getTileEntities() {
|
|
+ // Paper start
|
|
+ return getTileEntities(true);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BlockState[] getTileEntities(boolean useSnapshot) {
|
|
+ // Paper end
|
|
if (!this.isLoaded()) {
|
|
this.getWorld().getChunkAt(x, z); // Transient load for this tick
|
|
}
|
|
@@ -178,7 +185,29 @@ public class CraftChunk implements Chunk {
|
|
BlockState[] entities = new BlockState[chunk.blockEntities.size()];
|
|
|
|
for (BlockPos position : chunk.blockEntities.keySet()) {
|
|
- 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);
|
|
+ }
|
|
+
|
|
+ return entities;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Collection<BlockState> getTileEntities(Predicate<Block> blockPredicate, boolean useSnapshot) {
|
|
+ Preconditions.checkNotNull(blockPredicate, "blockPredicate");
|
|
+ if (!this.isLoaded()) {
|
|
+ this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
|
|
+ }
|
|
+ ChunkAccess chunk = this.getHandle(ChunkStatus.FULL);
|
|
+
|
|
+ java.util.List<BlockState> entities = new java.util.ArrayList<>();
|
|
+
|
|
+ for (BlockPos position : chunk.blockEntities.keySet()) {
|
|
+ Block block = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
|
|
+ if (blockPredicate.test(block)) {
|
|
+ entities.add(block.getState(useSnapshot));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
return entities;
|