77 lines
3.3 KiB
Diff
77 lines
3.3 KiB
Diff
--- a/net/minecraft/world/level/block/entity/TileEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/TileEntity.java
|
|
@@ -26,8 +26,18 @@
|
|
import net.minecraft.world.level.block.state.IBlockData;
|
|
import org.slf4j.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 = LogUtils.getLogger();
|
|
private final TileEntityTypes<?> type;
|
|
@Nullable
|
|
@@ -61,7 +71,16 @@
|
|
return this.level != null;
|
|
}
|
|
|
|
- protected void loadAdditional(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) {}
|
|
+ // CraftBukkit start - read container
|
|
+ protected void loadAdditional(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) {
|
|
+ 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 final void loadWithComponents(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) {
|
|
this.loadAdditional(nbttagcompound, holderlookup_a);
|
|
@@ -101,6 +120,11 @@
|
|
}).ifPresent((nbtbase) -> {
|
|
nbttagcompound.merge((NBTTagCompound) nbtbase);
|
|
});
|
|
+ // CraftBukkit start - store container
|
|
+ if (this.persistentDataContainer != null && !this.persistentDataContainer.isEmpty()) {
|
|
+ nbttagcompound.put("PublicBukkitValues", this.persistentDataContainer.toTagCompound());
|
|
+ }
|
|
+ // CraftBukkit end
|
|
return nbttagcompound;
|
|
}
|
|
|
|
@@ -264,7 +288,7 @@
|
|
set.add(DataComponents.BLOCK_ENTITY_DATA);
|
|
final PatchedDataComponentMap patcheddatacomponentmap = PatchedDataComponentMap.fromPatch(datacomponentmap, datacomponentpatch);
|
|
|
|
- this.applyImplicitComponents(new TileEntity.b(this) {
|
|
+ this.applyImplicitComponents(new TileEntity.b() { // CraftBukkit - decompile error
|
|
@Nullable
|
|
@Override
|
|
public <T> T get(DataComponentType<T> datacomponenttype) {
|
|
@@ -306,6 +330,15 @@
|
|
this.components = datacomponentmap;
|
|
}
|
|
|
|
+ // CraftBukkit start - add method
|
|
+ public InventoryHolder getOwner() {
|
|
+ if (level == null) return null;
|
|
+ org.bukkit.block.BlockState state = level.getWorld().getBlockAt(worldPosition.getX(), worldPosition.getY(), worldPosition.getZ()).getState();
|
|
+ if (state instanceof InventoryHolder) return (InventoryHolder) state;
|
|
+ return null;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
private static class a {
|
|
|
|
public static final Codec<DataComponentMap> COMPONENTS_CODEC = DataComponentMap.CODEC.optionalFieldOf("components", DataComponentMap.EMPTY).codec();
|