PaperMC/paper-server/nms-patches/TileEntity.patch
CraftBukkit/Spigot 0632e375cf SPIGOT-6194: Read correct nbt compound into chunk pdc
Previously spigots chunk pdc loading logic would read the entire chunk
nbt compound into the persistent data container of the chunk instead of
just reading the "BukkitValues".

Furthermore this commit also now correctly checks if the nbt compounds
of entities, tile entities and chunks actually have a value for the
"BukkitValues" key, as the previous 'getCompound' call would always
return an instance, the null check was useless. This commit now uses
'get', which returns null if no key exists and then runs an instanceof
check to both validate a non-null instance and an NBTTagCompound
instance.

By: Bjarne Koll <lynxplay101@gmail.com>
2020-10-18 07:01:15 +11:00

62 lines
2.6 KiB
Diff

--- a/net/minecraft/server/TileEntity.java
+++ b/net/minecraft/server/TileEntity.java
@@ -4,9 +4,18 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Supplier;
+// CraftBukkit start
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
public abstract class TileEntity {
+ // CraftBukkit start - data containers
+ private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
+ public CraftPersistentDataContainer persistentDataContainer;
+ // CraftBukkit end
private static final Logger LOGGER = LogManager.getLogger();
private final TileEntityTypes<?> tileType;
@Nullable
@@ -38,6 +47,14 @@
public void load(IBlockData iblockdata, NBTTagCompound nbttagcompound) {
this.position = new BlockPosition(nbttagcompound.getInt("x"), nbttagcompound.getInt("y"), nbttagcompound.getInt("z"));
+ // CraftBukkit start - read container
+ this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
+
+ NBTBase persistentDataTag = nbttagcompound.get("PublicBukkitValues");
+ if (persistentDataTag instanceof NBTTagCompound) {
+ this.persistentDataContainer.putAll((NBTTagCompound) persistentDataTag);
+ }
+ // CraftBukkit end
}
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
@@ -54,6 +71,11 @@
nbttagcompound.setInt("x", this.position.getX());
nbttagcompound.setInt("y", this.position.getY());
nbttagcompound.setInt("z", this.position.getZ());
+ // CraftBukkit start - store container
+ if (this.persistentDataContainer != null && !this.persistentDataContainer.isEmpty()) {
+ nbttagcompound.set("PublicBukkitValues", this.persistentDataContainer.toTagCompound());
+ }
+ // CraftBukkit end
return nbttagcompound;
}
}
@@ -169,4 +191,13 @@
}, this::getPosition});
}
}
+
+ // CraftBukkit start - add method
+ public InventoryHolder getOwner() {
+ if (world == null) return null;
+ org.bukkit.block.BlockState state = world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState();
+ if (state instanceof InventoryHolder) return (InventoryHolder) state;
+ return null;
+ }
+ // CraftBukkit end
}