Solved Custom NBT tags, post 'safeguard'

Discussion in 'Plugin Development' started by Malikk, Dec 21, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Malikk

    Hey Everybody,

    Before the recent cb/bukkit 'safeguard' updates I had been writing my own NBT tags and everything was peachy. Now that I can't access the CraftItemStack's constructor OR getHandle() to get my nms ItemStack does anyone know how I can write my own NBT tags?

    I realize that there is (limited) api for NBT tags, such as setting the name and lore, but this does not suffice in my situation. I need to be able to accomplish what I used to be able to do, like
    Code:
    NBTTagCompound tag = itemStack.tag.getCompound("malikk'sTag");
    
    which I can longer do.

    Thanks in advance,
    Malikk
     
  2. Offline

    fireblast709

    CraftBukkit.asNMSCopy(original).getTag()?
     
    Malikk likes this.
  3. Offline

    Malikk

    Not sure how I missed that.

    I've got a lot of rewrite to do, but that'll work just fine. Thanks

    fireblast709

    Looks like
    Code:
    CraftItemStack.asBukkitCopy(itemStack);
    
    Removes my tags.

    Any other ways to do this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  4. Offline

    fireblast709

    CraftItemStack.asCraftMirror(NMS itemstack)
     
    Malikk likes this.
  5. Offline

    Malikk

    Okay, it's working. Not sure I understand why, but w/e

    Thanks.
     
  6. Offline

    CorrieKay

    I can explain. Basically, with the bukkit copy method, shown here, it creates a copy of the item based on the items information, then returns the new item. Your tags would be lost in the process, but with the craft mirror method, it adds the item stack as the handle in the constructor, as opposed to making a copy. Therefore, your tags would be preserved.
     
  7. Offline

    fireblast709

    Also, as CraftItemStack extends ItemStack, it would be possible to use this in regular bukkit code
     
  8. Offline

    CorrieKay

    org.bukkit.inventory.ItemStack doesnt have these methods.

    edit: it has the ItemMeta methods, if thats what you mean :p
     
  9. Offline

    fireblast709

    Sorry if I was not clear, I ment that you could use CraftItemStack in player.getInventory().addItem(CraftItemStackhere), for example ;D
     
  10. Offline

    CorrieKay

    Oh right, yes :p
     
Thread Status:
Not open for further replies.

Share This Page