diff --git a/paper-server/nms-patches/net/minecraft/core/component/DataComponentPatch.patch b/paper-server/nms-patches/net/minecraft/core/component/DataComponentPatch.patch index 339e9743ff..e7c58e44a1 100644 --- a/paper-server/nms-patches/net/minecraft/core/component/DataComponentPatch.patch +++ b/paper-server/nms-patches/net/minecraft/core/component/DataComponentPatch.patch @@ -18,7 +18,7 @@ } }; private static final String REMOVED_PREFIX = "!"; -@@ -270,6 +270,38 @@ +@@ -270,6 +270,42 @@ a() {} @@ -31,6 +31,10 @@ + this.map.remove(type); + } + ++ public boolean isSet(DataComponentType type) { ++ return map.containsKey(type); ++ } ++ + public boolean isEmpty() { + return this.map.isEmpty(); + } 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 812c970c7c..c6a9678d6d 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 @@ -212,7 +212,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta tag.put(BLOCK_ENTITY_TAG, CustomData.of(blockEntityTag.getSnapshotNBTWithoutComponents())); for (TypedDataComponent component : blockEntityTag.collectComponents()) { - tag.builder.set(component); + tag.putIfAbsent(component); } } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index ab57700d37..bbca839ea8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -45,6 +45,7 @@ import net.minecraft.core.IRegistryCustom; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponentType; import net.minecraft.core.component.DataComponents; +import net.minecraft.core.component.TypedDataComponent; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.DynamicOpsNBT; import net.minecraft.nbt.NBTBase; @@ -173,13 +174,20 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { static final class Applicator { - final DataComponentPatch.a builder = DataComponentPatch.builder(); + private final DataComponentPatch.a builder = DataComponentPatch.builder(); Applicator put(ItemMetaKeyType key, T value) { builder.set(key.TYPE, value); return this; } + Applicator putIfAbsent(TypedDataComponent component) { + if (!builder.isSet(component.type())) { + builder.set(component); + } + return this; + } + DataComponentPatch build() { return builder.build(); }