Solved Unique ItemStack Identification

Discussion in 'Plugin Development' started by Lionhard, Nov 17, 2016.

Thread Status:
Not open for further replies.
  1. Hello,

    I'm currently working in a way to store persistent data on ItemStacks. I've managed to make it work, BUT as soon as the durability of the ItemStack changes, the data get's lost. So I can't store the data on weapons and / or armors.

    So I was wondering if you guys know any way how to identify ItemStacks, even though they change durability and stuff. Right now I use the item's hashcode to identify them from each other, but as soon as the item takes damage, the hashcode changes too - making it a different item and my data is no longer connected to that item.

    I'd appreciate any help.

    best regards,
    Skrypt
     
  2. Online

    timtower Administrator Administrator Moderator

    @Lionhard Did you try to put an UUID in the lore?
     
    Lionhard likes this.
  3. @timtower I do not need to track who that item belongs to, rather just track which item is which :D for example I have a sword and I save another ItemStack into that ItemStack. Whatever the user does with the item (put it into a chest, drop it, pick it up) I need that this data I saved into it will persist. To do that, I need some way to uniquelly identify this itemstack no matter what.

    I already managed to keep track of each itemStack with custom data inside it, but this works only as long as the itemstack doesn't get damaged, because when it does, the HashCode of it changes - which fools my code and I no longer am able to find that item. So my data remains connected with the old HashCode, which can be any other item now (or none).
     
  4. Offline

    Zombie_Striker

    @Lionhard
    Again, did you try putting AN UUID in the lore? UUID are just identifiers, there not just for players. Generate a UUID for each item. When you need to figure out which item it is, look at the UUID.
     
    Lionhard likes this.
  5. @Zombie_Striker Oh, I didn't know that. :D That sounds cool, thanks, I'll try that. :D

    EDIT: Aww, that was simple. Thanks alot. :D
     
    Last edited: Nov 17, 2016
    timtower likes this.
  6. uuid in lore is visible to players.
    Does it anyway to hide it?
     
Thread Status:
Not open for further replies.

Share This Page