Paper/Spigot-Server-Patches/0265-Ability-to-get-Tile-Entities-from-a-chunk-without-sn.patch

74 lines
2.7 KiB
Diff
Raw Normal View History

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 1a312a868f6a65e7d4a53406825e9efd96d98607..569c0dd3d22c6ae154d3184905f5c09f9cbee238 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
@@ -3,8 +3,10 @@ package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import java.lang.ref.WeakReference;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import java.util.function.Predicate;
import net.minecraft.server.BiomeStorage;
import net.minecraft.server.BlockPosition;
@@ -130,9 +132,16 @@ public class CraftChunk implements Chunk {
2019-05-06 04:58:04 +02:00
@Override
public BlockState[] getTileEntities() {
+ // Paper start
+ return getTileEntities(true);
+ }
+
2019-05-06 04:58:04 +02:00
+ @Override
+ public BlockState[] getTileEntities(boolean useSnapshot) {
if (!isLoaded()) {
getWorld().getChunkAt(x, z); // Transient load for this tick
}
+ // Paper end
int index = 0;
net.minecraft.server.Chunk chunk = getHandle();
@@ -144,11 +153,33 @@ public class CraftChunk implements Chunk {
}
BlockPosition position = (BlockPosition) obj;
- entities[index++] = worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState();
+ entities[index++] = worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState(useSnapshot); // Paper
+ }
+
+ return entities;
+ }
+
+ // Paper start
+ @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.server.Chunk chunk = getHandle();
+
+ List<BlockState> entities = new ArrayList<>();
+
+ for (BlockPosition position : chunk.tileEntities.keySet()) {
+ Block block = worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
+ if (blockPredicate.test(block)) {
+ entities.add(block.getState(useSnapshot));
+ }
}
return entities;
}
+ // Paper end
@Override
public boolean isLoaded() {