NBT data lost when retrieving ItemStack from inventory?

Discussion in 'Plugin Development' started by HamOmlet, Nov 10, 2012.

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

    HamOmlet

    Here's my current situation: I'm grabbing an ItemStack from a specific slot in a player's inventory, but the ItemStack that is returned isn't the same ItemStack that is being held in a variable. The tags are being shown correctly when in the inventory, so I'm stumped as to why the returned ItemStack is different.
     
  2. Offline

    Karl Marx

    The Bukkit ItemStack class is just a wrapper for the internal minecraft ItemStack item. Whenever you call a function that returns an ItemStack, it is almost certainly generating a new wrapper object, so using == to compare the two objects will likely always fail. Instead, you can use .equals(), which should work as expected.

    As for the tag issue, Bukkit currently doesn't support them for most items (hence the lack of any API.) Therefore, using any Bukkit methods to manipulate NBT-tagged items will likely lose the tags. If you must preserve the tags for your plugin, you'll have to access them through the NMS classes directly. If you don't know what that means or how to go about it, you should probably just wait for official support. There are plenty of bugs still anyways, so odds are whatever you're trying to do won't work, no matter how hard to try.
     
  3. Offline

    HamOmlet

    Thanks for the reply! I was under the impression that the returned ItemStack would reference the same location in memory, so I figured the '==' operator would do the trick; thanks for the explanation. In my case with the NBT tags, I was foolishly attempting to having stackable ItemStacks with different tags, which doesn't work. I've since gone down another route to accomplish what I need.
     
Thread Status:
Not open for further replies.

Share This Page