Jump to content

[1.12.1] Questions about how itemstacks sync client and server


Recommended Posts

Posted

So I've been playing around with items that are fluid handlers and while I can get the functionality to work I've been having trouble with the models and also with the client not retaining the fluid levels after a save / load. It seems clear to me that it is a client-server sync issue, but I'm not entirely sure how to fix it for a couple reasons.

 

First of all, if I change NBT data (or in this case the item fluid handler adjusts NBT) on the server, what is the expected mechanism for the client to get that info? For me it often appears to work but i think that is because the code is also running simultaneously on the client, but problems with save/load lead me to believe that the server side isn't really managing things.

 

So I thought maybe I should send a custom packet, or initiate a vanilla sync packet, but realized there doesn't really seem to be a UUID to reference for ItemStacks. So it seems to me that for example if I am showing an itemstack in the player inventory (on client) there isn't really any specific way to reference the server version of the same thing, except for the fact that it is in the same slot. Due to that, it seems (and I can see this when I trace the code) that there is actually a lot of "replacement copies" of itemstacks going on. For example, it seems that each time I open the player inventory it actually constructs new versions of the itemstacks and so forth. And it seems that each time a player uses an ItemStack in his hand, the server creates a new ItemStack. This sort of makes sense, but also makes it difficult for me to understand how to sync them properly. In fact is isn't really clear which direction I should be syncing -- from server to client or client to server. Right-clicking presumably sends a message to the server at some point, and when server gets the message I think it creates a new copy of the ItemStack to work with. This is very different than Entity syncing where there is only one instance and you reference it by UUID.

 

Question 1) For an ItemStack in player's hand, if you want it to change state (i.e. NBT data changes) on right-clicking on something, how does that work in terms of syncing between client and server? Is there no syncing (because code runs on both sides)? Or does it run on client and some packet is sent to server saying "update what's in my hand"? Or does it run on server and there is some packet sent to client saying "update what's in your hand"?

 

Question 2)  What vanilla packets are involved in syncing ItemStack information? How are ItemStacks references across client and server? Is there a UUID or are they simply re-created when the packets are received?

 

Question 3) When you save then load, how are ItemStacks in the player inventory supposed to get synced to the saved NBT data?

 

Question 4) The Item class itself has a getShareData() mechanism that seems to be related to NBT, but it's not clear to me when that gets called. I don't see it happening much in my console logs.

 

Basically I want an ItemStack state to change when used using right-click and want that state to persist after saving then loading. I have the right-click working but not the saving / loading.

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

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.