Jump to content

[1.10.2] Sync ItemStack Capability [Solved]


Tamaized

Recommended Posts

So how would one go about syncing the values of a capability attached to an ItemStack from server to client? I need these values to display the durability bar for the stack and for the addInformation method. The problem I'm having with packets is I don't know how to send this data to the specific stack unless there's a way to track the stack with an id or something that i'm unaware of.

Link to comment
Share on other sites

No idea why I didn't think of this before, I'm already using the onUpdate method in the Item to check if the capability is "dirty" or needs its data to be sent. onUpdate actually gives me the slot id the stack is in so I can just use that to update that specific slot on the client.

Link to comment
Share on other sites

No idea why I didn't think of this before, I'm already using the onUpdate method in the Item to check if the capability is "dirty" or needs its data to be sent. onUpdate actually gives me the slot id the stack is in so I can just use that to update that specific slot on the client.

 

Note that

Item#onUpdate

is called when the item is in any of the player's three inventory sections (main, armour, off hand) and the slot argument will be relative to the start of that inventory; e.g. slot 0 could be slot 0 of the main inventory, slot 0 of the armour inventory or slot 0 of the off hand inventory.

 

You need to search through each inventory section and check if the

ItemStack

in the specified slot is the same as the

ItemStack

argument.

 

I use this method to perform an operation for the specified inventory sections in

Item#onUpdate

. You can see the usages here, here and here.

  • Thanks 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.