Paper/patches/server/0250-Ability-to-get-Tile-Entities-from-a-chunk-without-sn.patch
Nassim Jahnke ca708a0944
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#6539)
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:
ed7bba95 SPIGOT-6547: Chunk#getEntities() doesn't return all entities immediately after chunk load
d99a585c SPIGOT-6719: Add getTileEntities() to LimitedRegion

CraftBukkit Changes:
422cec08 Rebuild patch
15f27fc7 SPIGOT-6547: Chunk#getEntities() doesn't return all entities immediately after chunk load
cbd747af SPIGOT-6719: Add getTileEntities() to LimitedRegion

Spigot Changes:
6c1c1b26 Rebuild patches
2021-09-01 14:03: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 026992056716c11606bd334dd0be178b7e8fb020..7690252c08785906e721ba09834c1a64e32b2880 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.Objects;
import java.util.function.Predicate;
import net.minecraft.core.BlockPos;
@@ -149,6 +151,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
}
@@ -163,7 +172,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;