mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
afe633df08
* convert API tests to mockito * convert server tests to mockito * add co-author
67 lines
2.6 KiB
Diff
67 lines
2.6 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 e4a533ace96829414844607a013831dba7a1e73e..832c6d92daaa96210a9c7edbd357ca824a60a4a5 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
|
@@ -4,8 +4,10 @@ import com.google.common.base.Preconditions;
|
|
import com.google.common.base.Predicates;
|
|
import com.mojang.serialization.Codec;
|
|
import java.lang.ref.WeakReference;
|
|
+import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
+import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.concurrent.locks.LockSupport;
|
|
import java.util.function.BooleanSupplier;
|
|
@@ -134,6 +136,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
|
|
}
|
|
@@ -148,7 +157,29 @@ public class CraftChunk implements Chunk {
|
|
}
|
|
|
|
BlockPos position = (BlockPos) obj;
|
|
- 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 (!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));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
return entities;
|