
During block destruction, the type of the block may already have been set to AIR while the TileEntity has not yet been removed. Also, TileEntity#getOwner() skips the whole BlockState construction now if the block is of type AIR. This removes the previous workaround again of returning a dummy CraftBlockEntityState in this case.
68 lines
2.7 KiB
Diff
68 lines
2.7 KiB
Diff
--- a/net/minecraft/world/level/block/entity/TileEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/TileEntity.java
|
|
@@ -12,8 +12,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
|
|
@@ -41,7 +51,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
|
|
|
|
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
|
|
return this.c(nbttagcompound);
|
|
@@ -57,6 +76,11 @@
|
|
nbttagcompound.setInt("x", this.worldPosition.getX());
|
|
nbttagcompound.setInt("y", this.worldPosition.getY());
|
|
nbttagcompound.setInt("z", this.worldPosition.getZ());
|
|
+ // CraftBukkit start - store container
|
|
+ if (this.persistentDataContainer != null && !this.persistentDataContainer.isEmpty()) {
|
|
+ nbttagcompound.set("PublicBukkitValues", this.persistentDataContainer.toTagCompound());
|
|
+ }
|
|
+ // CraftBukkit end
|
|
return nbttagcompound;
|
|
}
|
|
}
|
|
@@ -164,4 +188,15 @@
|
|
public void b(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
|
|
}
|