Jump to content

[1.15.2] Desync Between Client & Server


Scaleios

Recommended Posts

I am attempting to remove items from a player's inventory, organize them, and replace them. Questions at the bottom.

My old system was done completely client side as follows:
GuiKeyPress event -> Remove items on client using the invwrapper -> sort the array, and place it back one by one into inventory

 

That worked fine for a while, but then I noticed an issue where there would seem to be some sort of desync. The inventory would appear sorted, but trying to click on any item in it would result in the inventory reverting to the state it was before I executed my code. That is what I assumed was the desync.

 

In response to that, I switched to  sending a network packet with the inventory instead to the server, and handle everything there. That solved the desync issue I had, but now I am having problems with the inventory being completely cleared if the items are already in a sorted order. I tried a mix of clearing the inventory on client, then repopulating it on server, handling everything on server, handling everything on client, and just replacing without removing but there was always some sort of desync.

 

To confirm, the packets reach the handler properly and all the data is as expected on the other end. The second desync issue essentially arises from trying to set an itemstack into the same  index it was/already is in.

 

The replacement was done by using ServerPlayerEntity/ClientPlayerEntity -> "inventory.removeStackFromSlot" & "replaceItemInInventory", along with using InvWrapper on each, along with the extract/insert methods. Additionally I used "PlayerEntity.addItemStackToInventory", which interestingly when called on one item would shift its index by one each successive call.

 

I am using a simple simplempl implementation if that matters.

 

Questions:
Why is this desync happening, and is it avoidable?
Is there a better way to sync the client and server up without requiring packets, and if there isn't, what is the best method of approaching this? 

Edited by Scaleios
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.