--- a/net/minecraft/world/level/block/entity/TileEntity.java +++ b/net/minecraft/world/level/block/entity/TileEntity.java @@ -15,8 +15,18 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +// 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 type; @Nullable @@ -48,7 +58,16 @@ return this.level != null; } - public void load(NBTTagCompound nbttagcompound) {} + // CraftBukkit start - read container + public void load(NBTTagCompound nbttagcompound) { + this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); + + net.minecraft.nbt.NBTBase persistentDataTag = nbttagcompound.get("PublicBukkitValues"); + if (persistentDataTag instanceof NBTTagCompound) { + this.persistentDataContainer.putAll((NBTTagCompound) persistentDataTag); + } + } + // CraftBukkit end protected void saveAdditional(NBTTagCompound nbttagcompound) {} @@ -70,6 +89,11 @@ NBTTagCompound nbttagcompound = new NBTTagCompound(); this.saveAdditional(nbttagcompound); + // CraftBukkit start - store container + if (this.persistentDataContainer != null && !this.persistentDataContainer.isEmpty()) { + nbttagcompound.put("PublicBukkitValues", this.persistentDataContainer.toTagCompound()); + } + // CraftBukkit end return nbttagcompound; } @@ -202,4 +226,15 @@ public void setBlockState(IBlockData iblockdata) { this.blockState = iblockdata; } + + // CraftBukkit start - add method + public InventoryHolder getOwner() { + if (level == null) return null; + org.bukkit.block.Block block = level.getWorld().getBlockAt(worldPosition.getX(), worldPosition.getY(), worldPosition.getZ()); + if (block.getType() == org.bukkit.Material.AIR) return null; + org.bukkit.block.BlockState state = block.getState(); + if (state instanceof InventoryHolder) return (InventoryHolder) state; + return null; + } + // CraftBukkit end }