Paper/patches/server/0242-Ability-to-get-Tile-Entities-from-a-chunk-without-sn.patch
Nassim Jahnke 928bcc8d3a
Updated Upstream (Bukkit/CraftBukkit) (#8430)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
09943450 Update SnakeYAML version
5515734f SPIGOT-7162: Incorrect description for Entity#getVehicle javadoc
6f82b381 PR-788: Add getHand() to all relevant events

CraftBukkit Changes:
aaf484f6f SPIGOT-7163: CraftMerchantRecipe doesn't copy demand and specialPrice from BukkitMerchantRecipe
5329dd6fd PR-1107: Add getHand() to all relevant events
93061706e SPIGOT-7045: Ocelots never spawn with babies with spawn reason OCELOT_BABY
2022-10-02 09:56:36 +02:00

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 fd50cc4cfc976a9dee82d4f6ad457bba18065614..1827fdc551095ab411d6b43b94106273f53386c8 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;
@@ -133,6 +135,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
}
@@ -147,7 +156,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;