diff --git a/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTItem.java b/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTItem.java index ca0dd7b21..ab5242d72 100644 --- a/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTItem.java +++ b/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTItem.java @@ -12,6 +12,7 @@ import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT; import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; import de.tr7zw.changeme.nbtapi.iface.ReadableNBT; +import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper; import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod; @@ -210,10 +211,18 @@ public void mergeNBT(ItemStack item) { * * @param item ItemStack that should get the new NBT data */ + @Deprecated public void mergeCustomNBT(ItemStack item) { if (item == null || item.getType() == Material.AIR) { throw new NullPointerException("ItemStack can't be null/Air!"); } + if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { + // 1.20.5+ doesn't have any vanilla tags + NBT.modify(item, nbt -> { + nbt.mergeCompound(this); + }); + return; + } ItemMeta meta = item.getItemMeta(); NBTReflectionUtil.getUnhandledNBTTags(meta) .putAll(NBTReflectionUtil.getUnhandledNBTTags(bukkitItem.getItemMeta())); @@ -225,7 +234,12 @@ public void mergeCustomNBT(ItemStack item) { * * @return true when custom tags are present */ + @Deprecated public boolean hasCustomNbtData() { + if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { + // 1.20.5+ doesn't have any vanilla tags + return hasNBTData(); + } finalizeChanges(); ItemMeta meta = bukkitItem.getItemMeta(); return !NBTReflectionUtil.getUnhandledNBTTags(meta).isEmpty(); @@ -234,8 +248,14 @@ public boolean hasCustomNbtData() { /** * Remove all custom (non-vanilla) NBT tags from the NBTItem. */ + @Deprecated public void clearCustomNBT() { finalizeChanges(); + if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { + // 1.20.5+ doesn't have any vanilla tags + setCompound(null); + return; + } ItemMeta meta = bukkitItem.getItemMeta(); NBTReflectionUtil.getUnhandledNBTTags(meta).clear(); bukkitItem.setItemMeta(meta); @@ -280,6 +300,9 @@ public void modifyMeta(BiConsumer handler) { bukkitItem.setItemMeta(meta); updateCachedCompound(); if (directApply) { + if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { + throw new NbtApiException("Direct apply mode meta changes don't work anymore in 1.20.5+. Please switch to the modern NBT.modify sytnax!"); + } applyNBT(originalSrcStack); } } diff --git a/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTReflectionUtil.java b/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTReflectionUtil.java index 0a03d3b58..14564f2ee 100644 --- a/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTReflectionUtil.java +++ b/item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTReflectionUtil.java @@ -246,6 +246,7 @@ public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) { * @return Map containing unhandled (custom) NBT tags */ @SuppressWarnings("unchecked") + @Deprecated public static Map getUnhandledNBTTags(ItemMeta meta) { try { return (Map) field_unhandledTags.get(meta); diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/DirectApplyMetaTest.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/DirectApplyMetaTest.java index cf742219d..5e9f3510a 100644 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/DirectApplyMetaTest.java +++ b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/DirectApplyMetaTest.java @@ -4,22 +4,27 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import de.tr7zw.changeme.nbtapi.NBT; import de.tr7zw.changeme.nbtapi.NBTItem; import de.tr7zw.changeme.nbtapi.NbtApiException; import de.tr7zw.changeme.nbtapi.iface.ReadableNBT; +import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; import de.tr7zw.nbtapi.plugin.tests.Test; public class DirectApplyMetaTest implements Test { @Override public void test() throws Exception { + if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { + return; // skip + } ItemStack baseItem = new ItemStack(Material.STONE); NBTItem nbti = new NBTItem(baseItem, true); nbti.setString("SomeKey", "SomeValue"); nbti.modifyMeta(this::modifyMeta); if (!new NBTItem(baseItem).hasTag("SomeKey") || !"SomeValue".equals(baseItem.getItemMeta().getDisplayName())) { - throw new NbtApiException("The item was not modified correctly!"); + throw new NbtApiException("The item was not modified correctly! " + NBT.itemStackToNBT(baseItem)); } } diff --git a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/ItemMergingTest.java b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/ItemMergingTest.java index 0b6e06a86..1c6aa1df2 100644 --- a/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/ItemMergingTest.java +++ b/item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/ItemMergingTest.java @@ -6,12 +6,16 @@ import de.tr7zw.changeme.nbtapi.NBTItem; import de.tr7zw.changeme.nbtapi.NbtApiException; +import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; import de.tr7zw.nbtapi.plugin.tests.Test; public class ItemMergingTest implements Test { @Override public void test() throws Exception { + if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { + return; // skip, there is no vanilla nbt + } ItemStack item = new ItemStack(Material.WRITTEN_BOOK); BookMeta bookMeta = (BookMeta) item.getItemMeta(); bookMeta.setAuthor("Author");