Jump to content

[1.10] RemoveItem not working correctly


Egietje

Recommended Posts

I have a removeItem() method that if it is called it will remove as much from the item you're holding as the stacks of that item you have in your inventory

Here's my code:

public void removeItem(EntityPlayer playerIn, ItemStack removeitem) {
	IInventory inv = playerIn.inventory;
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		if (inv.getStackInSlot(i) != null) {
			ItemStack j = inv.getStackInSlot(i);
			if (j.getItem() != null && j.getItem() == removeitem.getItem()) {
				inv.decrStackSize(playerIn.inventory.currentItem, 1);
			}
		}
	}
}

Link to comment
Share on other sites

I think I remember your piece of code and it was something like:

for (index : all)
{
    player.inventory.decrStackSize(index, 1);
}

 

Learn what loop is, you are not supposed to loop through inventory. (because then indeed you will remove 1 from each stack).

 

Just call: (current item is item held)

player.inventory.decrStackSize(player.inventory.currentItem, 1);

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

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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