diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntity.patch index ec23bcb6de..e9e164dbf1 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntity.patch @@ -49,7 +49,18 @@ return nbttagcompound; } -@@ -265,7 +289,7 @@ +@@ -260,12 +284,18 @@ + } + + public final void applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) { ++ // CraftBukkit start ++ this.applyComponentsSet(datacomponentmap, datacomponentpatch); ++ } ++ ++ public final Set> applyComponentsSet(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) { ++ // CraftBukkit end + final Set> set = new HashSet(); + set.add(DataComponents.BLOCK_ENTITY_DATA); final PatchedDataComponentMap patcheddatacomponentmap = PatchedDataComponentMap.fromPatch(datacomponentmap, datacomponentpatch); @@ -58,7 +69,18 @@ @Nullable @Override public T get(DataComponentType datacomponenttype) { -@@ -317,6 +341,15 @@ +@@ -283,6 +313,10 @@ + DataComponentPatch datacomponentpatch1 = datacomponentpatch.forget(set::contains); + + this.components = datacomponentpatch1.split().added(); ++ // CraftBukkit start ++ set.remove(DataComponents.BLOCK_ENTITY_DATA); // Remove as never actually added by applyImplicitComponents ++ return set; ++ // CraftBukkit end + } + + protected void collectImplicitComponents(DataComponentMap.a datacomponentmap_a) {} +@@ -317,6 +351,15 @@ } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java index 687a93f4de..daf6387d9f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java @@ -1,8 +1,10 @@ package org.bukkit.craftbukkit.block; +import java.util.Set; import net.minecraft.core.IRegistryCustom; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponentType; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.PacketListenerPlayOut; @@ -60,9 +62,10 @@ public class CraftBlockEntityState extends CraftBlockState return snapshot; } - public void applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) { - snapshot.applyComponents(datacomponentmap, datacomponentpatch); + public Set> applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) { + Set> result = snapshot.applyComponentsSet(datacomponentmap, datacomponentpatch); load(snapshot); + return result; } public DataComponentMap collectComponents() { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java index 8420cf298e..812c970c7c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java @@ -4,8 +4,6 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; -import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; import net.minecraft.core.BlockPosition; @@ -137,32 +135,6 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta Material.VAULT ); - private static final class TrackedDataComponentMap implements DataComponentMap { - - private final Set> seen = new HashSet<>(); - private final DataComponentMap handle; - - public TrackedDataComponentMap(DataComponentMap map) { - this.handle = map; - } - - @Override - public T get(DataComponentType type) { - seen.add(type); - return handle.get(type); - } - - @Override - public Set> keySet() { - return handle.keySet(); - } - - @Override - public Iterator> iterator() { - return handle.iterator(); - } - } - static { // Add shulker boxes to the list of block state materials too BLOCK_STATE_MATERIALS.addAll(SHULKER_BOX_MATERIALS); @@ -198,6 +170,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta }); if (!tag.isEmpty()) { + CraftBlockEntityState blockEntityTag = this.blockEntityTag; if (blockEntityTag == null) { blockEntityTag = getBlockState(material, null); } @@ -205,14 +178,16 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta // Convert to map PatchedDataComponentMap map = new PatchedDataComponentMap(DataComponentMap.EMPTY); map.applyPatch(tag); - // Setup tracking - TrackedDataComponentMap track = new TrackedDataComponentMap(map); // Apply - blockEntityTag.applyComponents(track, tag); + Set> applied = blockEntityTag.applyComponents(map, tag); // Mark applied components as handled - for (DataComponentType seen : track.seen) { + for (DataComponentType seen : applied) { unhandledTags.clear(seen); } + // Only set blockEntityTag if something was applied + if (!applied.isEmpty()) { + this.blockEntityTag = blockEntityTag; + } } }