Posted October 27, 201410 yr 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
October 27, 201410 yr 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. http://i.imgur.com/NdrFdld.png[/img]
October 27, 201410 yr 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
October 27, 201410 yr If that's the case, you should be able to use --stack.stackSize without any problems. Show us your code. http://i.imgur.com/NdrFdld.png[/img]
October 27, 201410 yr 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.