[1.8.8] Getting/Saving ItemStack's NBT Tag

Status
This thread has been locked.

Anndrew

Premium
Feedback score
1
Posts
1
Reactions
23
Resources
0
Hey everyone,

I am looking to see if any is able to help me get a ItemStacks NBT Tag (if they have one) and save it to a new version of the same item. I have a feature in one of my plugins to save the Items in an inventory but once the inventory is saved all of the item nbt tags get removed. Thanks!

Message me on Discord if your able to help - Anndrew#3417
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Pxlr

Feedback score
0
Posts
5
Reactions
0
Resources
0
Code:
// get tag
net.minecraft.server.v1_16_R2.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound nbt = stack.getTag();
String nbt = nbt.getString(key);

// set tag
net.minecraft.server.v1_16_R2.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tag = stack.getTag() != null ? stack.getTag() : new NBTTagCompound();
tag.setString(key, value);
stack.setTag(tag);
item = CraftItemStack.asCraftMirror(stack);
 

Anndrew

Premium
Feedback score
1
Posts
1
Reactions
23
Resources
0
Still looking for someone to help me with this. I have a separate class for serializing the inventory and I am trying to add the NBT Tag code to that.

Discord - Anndrew#3417
 

Dery

Feedback score
0
Posts
15
Reactions
0
Resources
3
Still looking for someone to help me with this. I have a separate class for serializing the inventory and I am trying to add the NBT Tag code to that.

Discord - Anndrew#3417
Do you really need a developer to do this? Pxlr already sent the code, just put it in your current class and voilà
 
Status
This thread has been locked.
Top