Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.10.2] Inventory syncing


Dijkstra
 Share

Recommended Posts

I have method that is called on only the server side that result

player.inventory.addItemStackToInventory(item)

be called if all conditions are meet, but because it is only called on the server side the client does not update util you click in the slot it put in. If there away to invoke this update, right after

player.inventory.addItemStackToInventory(item)

is called.

Link to comment
Share on other sites

Call

Container#detectAndSendChanges

on

EntityPlayer#inventoryContainer

to sync the player's inventory to their client.

 

If you make a large amount of changes to an inventory, consider calling

EntityPlayerMP#sendContainerToPlayer

instead. This sends a single packet with the whole inventory instead of sending an individual packet for each slot that changed.

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

So i am guessing

player.inventory.addItemStackToInventory(item)
player.inventory.detectAndSendChanges()

 

not being at my development environment although it end yo being something more like this 

if (player.inventory.addItemStackToInventory(item)) {
    player.inventory.detectAndSendChanges()
}
else{
    playerMP.worldObj.spawnEntityInWorld(new EntityItem(playerMP.worldObj, playerMP.posX, playerMP.posY, playerMP.posZ, item));
                        }

Link to comment
Share on other sites

Call

Container#detectAndSendChanges

on

EntityPlayer#inventoryContainer

to sync the player's inventory to their client.

 

EntityPlayer#inventory

is an

InventoryPlayer

, not a

Container

.

 

Use

ItemHandlerHelper.giveItemToPlayer

to give an item to a player or drop it at their feet if there wasn't room for it in their inventory.

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

So got this and it works

if (player.inventory.addItemStackToInventory(rewrad)){
                            player.inventoryContainer.detectAndSendChanges();
                        }
                        else{
                            playerMP.worldObj.spawnEntityInWorld(new EntityItem(playerMP.worldObj, playerMP.posX, playerMP.posY, playerMP.posZ, rewrad));
                        }

 

but will look into ItemHandlerHelper.giveItemToPlayer when i get an chance.

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.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.