Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2]Sync item Nbt and meta to client?


Recommended Posts

I have some problem whit item nbt.

I created a item with some nbt data, but when i add tooltip and durability bar to the item , the tooltip and durability bar didn't update at all

public double getDurabilityForDisplay(ItemStack stack) {
    return (getDurable(stack) / getMaxDurable(stack));
public boolean showDurabilityBar(ItemStack stack) {
    return true;
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    tooltip.add(I18n.format("tooltip.test") + ": " + getDurable(stack));


These code are written in my item class


this ItemStack was created by my machine, I use custom recipe handler class and add nbt tag before apply output(all these code run in server side, i use !world.isRemote to ensure all checkCanCraft , costInputItem and applyOutPut run in server)


I think maybe nbt data didn't sync to client, and tried log NBT data in showDurabilityBar method

when i use 


console show me right nbt data string like "{"ma_data":{"Durable":1000.0}}"

but when i use 

MOD.logger.info(getTagCompound().getCompoundTag("ma_data").getDouble("Durable"));//this line show me 0.0d in console
MOD.logger.info(getTagCompound().getCompoundTag("ma_data").getTag("Durable"));// this line show me null in console

I am sure of the item has correct nbt(At least in server side)


What am I doing wrong?


Edited by tt36999
Link to comment
Share on other sites

I usually send a packet explicitly to force the update to the client. This is because the order you do things to create the packet then add the NBT might miss the automatic update packets. For example, I think if you create an Item and add the NBT and then put it in a slot you will probably be automatically updated, but if you take an item already in a slot and add the NBT then probably not.


You can use a vanilla packet, but the packet you use depends on where the item is currently residing. For example, if it is in a GUI then I think you would send an SPacketWindowItems packet. If it is is some of the player's equipment (worn armor or something in either hand) then you would send an SPacketEntityEquipment packet and if it is in the hotbar then use SPacketHeldItemChanged.


Now, I think it is supposed to automatically update in most/many cases but personally I've found sending an explicit packet solves these sorts of things sometimes.


Other than that, I would say just trace the execution including any packets sent, looking at the payload involved to see if the information you're expecting is there.

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.