Jump to content

Inventory Synchronization


jakj

Recommended Posts

I am trying to use the functions that SlotCrafting/ItemBucket use, namely addItemStackToInventory (in InventoryPlayer) and dropPlayerItem (in EntityPlayer). I'm trying to do so from the right-click handler of an Item, passing the EntityPlayer provided in that call.

 

On both the integrated and dedicated servers, addItemStackToInventory will add the items to the inventory in appearance, but when thrown or selected will revert the inventory to its previous state, and dropPlayerItem seems to do nothing at all. The uses of these functions in SlotCrafting and ItemBucket work just fine, though.

 

What I'm trying to do is, on right-clicking of the item on particular blocks, decrement the stack size of the item and add a new item to the inventory based on what block was clicked.

 

Where/how is the client/server inventory synchronization occurring, and how can I manually invoke it?

Link to comment
Share on other sites

I've considered a packet solution, but it got needlessly complicated very quickly, in that I have to send a packet that says "Current player used item X in hotbar slot Y on block Z" and the server has to 1) check for and consume one of the item in that hotbar slot if present, 2) try to find the item elsewhere in the inventory if it's changed in between sending the packet, 3) fail the operation (and somehow notify the client of this failure, which by the time it's happened could involve altered client state) if the item is not in the server inventory, then generate the new item in the server-side inventory, then send a packet back to the client about where the item (should have) ended up.

 

It's nuts. I had a look at Forestry which recently came out for 1.3, and his code for un-crating an item on right-click doesn't do any of this, but then again, I can't seem to actually make a crated item to test with, so maybe that hasn't been updated yet.

 

There has to be some better way than this around-the-world journey.

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.