2021-06-11 12:02:28 +00:00
|
|
|
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
|
2022-09-20 01:39:46 +00:00
|
|
|
index bda9c6720fe0a91a4c6763795e4d6e01e6dd2747..dfdcc01c7cb2864d9b5f572c0cafedf16063edd8 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
2021-11-23 15:04:41 +00:00
|
|
|
@@ -4,8 +4,10 @@ import com.google.common.base.Preconditions;
|
2021-06-11 12:02:28 +00:00
|
|
|
import com.google.common.base.Predicates;
|
2021-11-23 15:04:41 +00:00
|
|
|
import com.mojang.serialization.Codec;
|
2021-06-11 12:02:28 +00:00
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
+import java.util.List;
|
2021-09-01 12:03:36 +00:00
|
|
|
import java.util.Objects;
|
2021-11-05 14:08:24 +00:00
|
|
|
import java.util.concurrent.locks.LockSupport;
|
|
|
|
import java.util.function.BooleanSupplier;
|
2022-06-07 21:45:11 +00:00
|
|
|
@@ -177,6 +179,13 @@ public class CraftChunk implements Chunk {
|
2021-06-11 12:02:28 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState[] getTileEntities() {
|
|
|
|
+ // Paper start
|
|
|
|
+ return getTileEntities(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public BlockState[] getTileEntities(boolean useSnapshot) {
|
|
|
|
+ // Paper end
|
2021-06-12 23:45:00 +00:00
|
|
|
if (!this.isLoaded()) {
|
|
|
|
this.getWorld().getChunkAt(x, z); // Transient load for this tick
|
|
|
|
}
|
2022-06-07 21:45:11 +00:00
|
|
|
@@ -191,7 +200,29 @@ public class CraftChunk implements Chunk {
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockPos position = (BlockPos) obj;
|
2021-06-12 23:45:00 +00: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 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return entities;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Collection<BlockState> getTileEntities(Predicate<Block> blockPredicate, boolean useSnapshot) {
|
|
|
|
+ Preconditions.checkNotNull(blockPredicate, "blockPredicate");
|
|
|
|
+ if (!isLoaded()) {
|
|
|
|
+ getWorld().getChunkAt(x, z); // Transient load for this tick
|
|
|
|
+ }
|
|
|
|
+ net.minecraft.world.level.chunk.LevelChunk chunk = getHandle();
|
|
|
|
+
|
|
|
|
+ List<BlockState> entities = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (BlockPos position : chunk.blockEntities.keySet()) {
|
|
|
|
+ Block block = worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
|
|
|
|
+ if (blockPredicate.test(block)) {
|
|
|
|
+ entities.add(block.getState(useSnapshot));
|
|
|
|
+ }
|
2021-06-12 23:45:00 +00:00
|
|
|
+ // Paper end
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return entities;
|