Jump to content

[1.6.2][SOLVED] Help with removing metadata items


ThePocketSoul

Recommended Posts

Hello! I'm having a problem with removing metadata items.

The problem isn't its not removing one of the item, it does, but it removes one of each of the metadata items if you have them in your inventory...

Code:

public void removeItem(EntityPlayer ep, ItemStack removeitem, int remove) {
    	IInventory inv = ep.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(i, remove);
    			}
    		}
    	}
    }

 

Thanks ahead of time!

Link to comment
Share on other sites

public void removeItem(EntityPlayer ep, ItemStack removeitem, int remove, int metadata) {
    	IInventory inv = ep.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() && j.getItemDamage() == metadata)
    			{
    				inv.decrStackSize(i, remove);
    			}
    		}
    	}
    }

Link to comment
Share on other sites

public void removeItem(EntityPlayer ep, ItemStack removeitem, int remove, int metadata) {
    	IInventory inv = ep.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() && j.getItem().getItemDamage() == metadata)
    			{
    				inv.decrStackSize(i, remove);
    			}
    		}
    	}
    }

Thanks but getItemDamage doesn't work...

i changed it to this and it worked

public void removeItem(EntityPlayer ep, ItemStack removeitem, int remove, int metadata) {
    	IInventory inv = ep.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() && j.getItem().getDamage(j) == metadata)
    			{
    				inv.decrStackSize(i, remove);
    			}
    		}
    	}
    }

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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