I'm looking to add a NBT Tag to a item, but I can't find any mehtod in JavaDocs. In google the most that I found is this code: Code (Java): // This is the Bukkit ItemStack (org.bukkit.inventory.ItemStack) ItemStack item = new ItemStack(Material.DIAMOND); // Just an example item // This is the NMS ItemStack net.minecraft.server.v1_14_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // Get the NBT tag NBTTagCompound tag = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound(); // I don't remember this method, just look through the methods and see which one is kinda like this tag.setString("key", "value"); // Set the NBT tag to the modified version nmsItem.setTag(tag); // Get the Bukkit ItemStack after modification item = CraftItemStack.asBukkitCopy(nmsItem);
This is only for custom data. If the OP want to edit vanilla tags which are unsupported by the API, he need to use NMS or an API to edit NBT tags
unrelated question : does adding that persistent data container to an item change the actual item's nbt? e.g. will items with different data containers still stack?
Well... if you want To use NBT you will have to use NMS. The only other option is the mentioned PersistentDataHolder or you take some API. There is no Bukkit or Spigot-Method that can provide NBT...
Ehh ? Why did you say NMS is dangerous ?! NMS is obfuscated and changes every version but it's not a nuclear bomb... Spigot uses indrectly NMS. Checks its source code
What nbt tag do you want to modify? Ever thought of creating a PR to add support for that? Most if not all things are covered through the Spigot-API.
Or including compiled code for different versions, or generating glue code at runtime. But stick to using an API like nbt-api because the version differences are too large to make it worth writing your own wrappers/glue code for.