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've been using player.inventory.consumeInventoryItem() but it doesn't update the stack properly, whats the best way to consume an item from the player's inventory?

The proud(ish) developer of Ancients

What about the stack doesn't update, the current number in the stack? This can be an issue depending on where you called consumeInventoryItem() from, or if you have multiple stacks of the same item in your inventory you may not notice if it was taken from the other stack.

 

That being said, there have been times when I've had to manually check if the stack size is 0 and then set the slot contents to null, because the vanilla system somehow doesn't always update appropriately.

  • Author

It doesn't visually update, I have to right click the stack to make it update, also it's getting called in my item's right click method.

The proud(ish) developer of Ancients

  • Author

I don't have my code right now but this is what I think I have

public void onItemRightClicked(ItemStack itemstack, World world, EntityPlayer player){

NBTTagCompound nbt = itemstack.stackTagCompound;

if(nbt!=null){
if(player.isSneaking){

if(player.inventory.hasItem(gammacraft.Uran235)){
player.inventory.consumeInventoryItem(gammacraft.Uran235);
nbt.setInteger("Energy",nbt.getInteger("Energy")+1);
itemstack.stackTagCompound=nbt;
}
}else{
player.addChatMessage(new ChatComponentText("Energy: "+nbt.getInteger("Energy"));
}
}
}

 

it removes the item "Uran235" from the players inventory if they are sneaking and increments the Energy tag.

The proud(ish) developer of Ancients

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.