Tamaized Posted October 24, 2016 Share Posted October 24, 2016 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. Quote Link to comment Share on other sites More sharing options...
Tamaized Posted October 24, 2016 Author Share Posted October 24, 2016 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. Quote Link to comment Share on other sites More sharing options...
Choonster Posted October 25, 2016 Share Posted October 25, 2016 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. 1 Quote 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 More sharing options...
Tamaized Posted October 25, 2016 Author Share Posted October 25, 2016 Yea I figured out fairly quick that the offhand and first slot of the hotbar were both slot 0, I did not however know about the armor bit. Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.