Posted April 21, 20205 yr 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 April 21, 20205 yr by Scaleios
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.