Jump to content

Recommended Posts

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

Posted

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.

Posted

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

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