1.15.2 NBT Tags and how do I add them to items?

Discussion in 'Spigot Plugin Development' started by OwlCube, Jan 21, 2020.

  1. Dear Spigot Plugin Dev. Community;
    I am making a small Pigeon Mail plugin so that players can send a private message at a time to each-other, and I want to make it a little more special than doing a /privatemessage <receiver> <message> type of thing. I am planning on having a carrot on a stick item look like a pigeon and when the player left-clicks on the item, an inventory GUI or something similar to be shown to put in a name-tagged paper, so the server knows to whom the message is for, and a book and quill for the message itself.

    My main question is how I add the NBT tags that are used in creation of datapacks?
    Please include code or add a link to a recent thread that talks about a current, 1.15.1, version of minecraft.
  2. I assume you are talking about the new custom model data? There is a API method for that ItemMeta#setCustomModelData
  3. No he is talking about NBT Tags for items which are separate. Using this new API method may be better for him though.
  4. TeamBergerhealer


    With NMS, the NMS Itemstack has a private 'tag' NBT Compound field which with reflection can be get and set. For your use case, it is probably easier to use the createTag()/getTag() public methods to obtain this compound of an item. You can modify this compound and store persistent metadata in the item.

    Be aware that this data should not be large, because the full metadata is transferred between server and client, which is particularly a problem in creative mode. If large data is stored in the world (itemframes, chests) it may also cause corruption and a vector for exploits.

    If you don't need to store data, such as messages, in the item itself, then using the new CustomModelData value is sufficient to give your item an unique icon, and to identify it as unique to your mod.

    If you are certain you need to store custom data in the item, and the bukkit api provided methods are insufficient, I can give a short code sample of how to do it with NMS. It's better to use the bukkit api when possible.
    #5 TeamBergerhealer, Jan 22, 2020
    Last edited: Jan 22, 2020
  5. I know this thead is kinda old now, but @TeamBergerhealer could you give a little example to help me out :D
  6. TeamBergerhealer


    @Lukas0816HD what exactly do you need a code example of? The ItemMeta API in Bukkit has gotten better, but I'm not familiar with that API so I might be giving bad advice as a result of it
    • Winner Winner x 1
    • Friendly Friendly x 1