[SPIGOT-4347] Allow adding/removal/reading of FixedMetaData Values on itemstacks Created: 06/Sep/18  Updated: 03/Dec/18  Resolved: 03/Dec/18

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Shane Martin Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: Meta, itemstack
Environment:

general plugin development


Version: This server is running CraftBukkit version git-Spigot-0ede7d0-c88ae6b (MC: 1.13.1) (Implementing API version 1.13.1-R0.1-SNAPSHOT)
Plugin: none specifically
Guidelines Read: Yes

 Description   

Blocks and Items (entities) can have FixedMetaDataValues attached to them via their object methods, however simply creating an itemstack does not allow metadatavalues to be set, it would be extremely helpful if this was an option!



 Comments   
Comment by md_5 [ 03/Dec/18 ]

An arbitrary stack data API was added that fulfills this purpose

Comment by md_5 [ 06/Sep/18 ]

display names / lores aren't applied to every stack and are supported by the server. A stack uuid isn't, and metadata isn't persisted for entities/blocks across reboots.....

Comment by Shane Martin [ 06/Sep/18 ]

but.....    Display names/ lores and nbt data hacked in via reflection, completely does persist across reboots.  The server must uniquely identify these items somehow, maybe it's just stored on the entity, ie the player whose holding it, or in an item frame which is also an entity.    Whatever storage method is used for the existing NBT should be completely fine if we just have the ability to add / remove / check for the presence of these tags, in the same way we check for the presence of them on a renamed item.

Comment by md_5 [ 06/Sep/18 ]

And metadata does not persist through reboots, etc..... I think this ticket misunderstands what the metadata API ultimately is (Map<String,Object) other plugins can access).

The server does not have a unique way of identifying items, and putting a UUID NBT tag on every item would be horrendous (performance etc)

Comment by Shane Martin [ 06/Sep/18 ]

I will agree that their unique identifier isn't their display name, however the server must have some way of uniquely identifying items that DO have display name or lore set, same as they do damaged items.   This data also persists if you were to drop the item turning it into an entity, then pick it back up the name/lore/durability/enchants are always preserved.  

 

There's a way to do this via NMS / Reflection which I don't pretend to be a NMS expert by any means.  But its done here in this plugin as a NBTItem:

https://github.com/tr7zw/Item-NBT-API/blob/master/item-nbt-api/src/main/java/de/tr7zw/itemnbtapi/NBTItem.java

the nbt tags are written to an itemstack and do persist through reboots, logouts etc.

http://prntscr.com/krd99q  <-  Note 2 nbt tags vs the normal 1 nbt tag when an item is renamed/lore is added.

http://prntscr.com/krd9sb  <- this is a dump of the data for that item, the 2nd nbt tag in the previous screenshot above is Rifles : "1", the first nbt tag contains all the display name/lore data.

This extra NBT data was added using the plugin item-NBT-API mentioned above.

 

Comment by md_5 [ 06/Sep/18 ]

Metadata in Bukkit is essentially a Map<String, Object> that can be shared by plugins, where String is a unique identifier for the Metadatable.
For entities this is their UUID, for blocks this is their world+location, for itemstacks this is...... certainly not their display name.

Comment by Shane Martin [ 06/Sep/18 ]

well i mean when you have an itemstack, with a custom display name or lore, that itemstack is unique right?  unless there is another itemstack whose data matches exactly they won't stack on top of each other.   You can spawn an item entity in the world and set its fixedmetadata,   but you can not set it once this item(entity) becomes an item stack.   However if one were able to set metadata or a custom NBT tag it would allow for a lot more flexibility identifying an item.    Something as simple as ItemStack.NBTaddString("sometag", "somevalue"); would work, the ability to add integers or booleans would be awesome as well.

 

I know it can be done via NMS but that really does not help out those who would like to be able to keep it within the spigot API.

Comment by md_5 [ 06/Sep/18 ]

Sorry what are you asking?

There's no unique way to identify an item stack in the server.

Generated at Tue Apr 08 02:45:53 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.