Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

Send packet from server to client with ItemStack and slotID and on client put ItemStack in that slot.

1.7.10 is no longer supported by forge, you are on your own.

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.

  • Author

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));
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  }

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.

  • Author

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.

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.