Skip to content

Instantly share code, notes, and snippets.

@mattmess1221
Last active August 29, 2015 14:01
Show Gist options
  • Save mattmess1221/1156a396207c6b1feeb7 to your computer and use it in GitHub Desktop.
Save mattmess1221/1156a396207c6b1feeb7 to your computer and use it in GitHub Desktop.
Method to consume item with damage in Minecraft.
private void eatItemWithDamage(InventoryPlayer inventory, Item item, int damage){
for(int i = 0;i<inventory.getSizeInventory(); i++){
ItemStack itemstack = inventory.mainInventory[i];
if(itemstack == null)
continue;
if(itemstack.getItem() == item && itemstack.getItemDamage() == damage){
itemstack.stackSize--;
if(itemstack.stackSize <=0)
inventory.setInventorySlotContents(i, null);
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment