diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch index 9885ca1eac..6741456537 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch @@ -103,7 +103,7 @@ Item item = this.getItem(); - EnumInteractionResult enuminteractionresult = item.useOn(itemactioncontext); + // CraftBukkit start - handle all block place event logic here -+ PatchedDataComponentMap oldData = this.getComponentsClone(); ++ DataComponentPatch oldData = this.getComponentsPatch(); + int oldCount = this.getCount(); + WorldServer world = (WorldServer) itemactioncontext.getLevel(); + @@ -120,10 +120,10 @@ + } finally { + world.captureBlockStates = false; + } -+ PatchedDataComponentMap newData = this.getComponentsClone(); ++ DataComponentPatch newData = this.getComponentsPatch(); + int newCount = this.getCount(); + this.setCount(oldCount); -+ this.setComponentsClone(oldData); ++ this.restorePatch(oldData); + if (enuminteractionresult.consumesAction() && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) { + world.captureTreeGeneration = false; + Location location = CraftLocation.toBukkit(blockposition, world.getWorld()); @@ -145,7 +145,7 @@ + if (!fertilizeEvent.isCancelled()) { + // Change the stack to its new contents if it hasn't been tampered with. + if (this.getCount() == oldCount && Objects.equals(this.components, oldData)) { -+ this.applyComponents(newData); ++ this.restorePatch(newData); + this.setCount(newCount); + } + for (CraftBlockState blockstate : blocks) { @@ -192,7 +192,7 @@ + } else { + // Change the stack to its new contents if it hasn't been tampered with. + if (this.getCount() == oldCount && Objects.equals(this.components, oldData)) { -+ this.applyComponents(newData); ++ this.restorePatch(newData); + this.setCount(newCount); + } + @@ -325,25 +325,20 @@ this.shrink(1); if (entityliving instanceof EntityHuman) { -@@ -669,6 +909,17 @@ +@@ -669,6 +909,12 @@ return this.getItem().useOnRelease(this); } + // CraftBukkit start -+ @Nullable -+ private PatchedDataComponentMap getComponentsClone() { -+ return this.components.isEmpty() ? null : this.components.copy(); -+ } -+ -+ private void setComponentsClone(@Nullable PatchedDataComponentMap patchedDataComponentMap) { -+ this.applyComponents(patchedDataComponentMap == null ? null : patchedDataComponentMap.copy()); ++ public void restorePatch(DataComponentPatch datacomponentpatch) { ++ this.components.restorePatch(datacomponentpatch); + } + // CraftBukkit end + @Nullable public T set(DataComponentType datacomponenttype, @Nullable T t0) { return this.components.set(datacomponenttype, t0); -@@ -728,7 +979,7 @@ +@@ -728,7 +974,7 @@ } private void addToTooltip(DataComponentType datacomponenttype, Item.b item_b, Consumer consumer, TooltipFlag tooltipflag) { @@ -352,7 +347,7 @@ if (t0 != null) { t0.addToTooltip(item_b, consumer, tooltipflag); -@@ -955,6 +1206,13 @@ +@@ -955,6 +1201,13 @@ } @@ -366,7 +361,7 @@ public IChatBaseComponent getDisplayName() { IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.empty().append(this.getHoverName()); -@@ -1017,7 +1275,7 @@ +@@ -1017,7 +1270,7 @@ } public void consume(int i, @Nullable EntityLiving entityliving) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index e4f28b9dfd..306397e55e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -4,7 +4,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import java.util.Map; import net.minecraft.core.Holder; -import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponents; import net.minecraft.world.item.Item; import net.minecraft.world.item.enchantment.EnchantmentManager; @@ -616,7 +616,7 @@ public final class CraftItemStack extends ItemStack { return false; } if (CraftItemFactory.instance().equals(itemMeta, null)) { - item.applyComponents(DataComponentMap.EMPTY); + item.restorePatch(DataComponentPatch.EMPTY); return true; } if (!CraftItemFactory.instance().isApplicable(itemMeta, getType(item))) { @@ -636,7 +636,7 @@ public final class CraftItemStack extends ItemStack { CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator(); ((CraftMetaItem) itemMeta).applyToItem(tag); - item.applyComponents(tag.build()); + item.restorePatch(tag.build()); } // SpigotCraft#463 this is required now by the Vanilla client, so mimic ItemStack constructor in ensuring it if (item.getItem() != null && item.getMaxDamage() > 0) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java index 0e0511a8f5..075c01a830 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java @@ -308,8 +308,12 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta { if (this.pages != null) { hash = 61 * hash + 17 * this.pages.hashCode(); } - hash = 61 * hash + 17 * Boolean.hashCode(resolved); - hash = 61 * hash + 19 * Integer.hashCode(generation); + if (this.resolved) { + hash = 61 * hash + 17 * Boolean.hashCode(this.resolved); + } + if (hasGeneration()) { + hash = 61 * hash + 19 * Integer.hashCode(this.generation); + } return original != hash ? CraftMetaBook.class.hashCode() ^ hash : hash; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java index 2c7488d088..9b2bde33d5 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java @@ -18,7 +18,8 @@ public class CraftMetaColorableArmor extends CraftMetaArmor implements Colorable Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, - Material.LEATHER_BOOTS + Material.LEATHER_BOOTS, + Material.WOLF_ARMOR ); private Color color = DEFAULT_LEATHER_COLOR; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java index 069a4e9646..387adabd8c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java @@ -169,7 +169,9 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { hash = 73 * hash + lodestoneY; hash = 73 * hash + lodestoneZ; } - hash = 73 * hash + (isLodestoneTracked() ? 1231 : 1237); + if (hasLodestoneTracked()) { + hash = 73 * hash + (isLodestoneTracked() ? 1231 : 1237); + } return original != hash ? CraftMetaCompass.class.hashCode() ^ hash : hash; } @@ -205,7 +207,9 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { builder.put(LODESTONE_POS_Y.BUKKIT, lodestoneY); builder.put(LODESTONE_POS_Z.BUKKIT, lodestoneZ); } - builder.put(LODESTONE_TRACKED.BUKKIT, tracked); + if (hasLodestoneTracked()) { + builder.put(LODESTONE_TRACKED.BUKKIT, tracked); + } return builder; }