aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0234-Ability-to-get-block-entities-from-a-chunk-without-s.patch
blob: 7c3bd3c439b680746ee5a99f07e25f97478226f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 block 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 1d4587a97e86251982a9df832949a7093b216862..fc335e4e80553e8c6c915e7813e9610ac10649c2 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
@@ -173,6 +173,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(this.x, this.z); // Transient load for this tick
         }
@@ -182,7 +189,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<? super 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;