Jump to content

Recommended Posts

Posted

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!

Posted
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);
    			}
    		}
    	}
    }

Posted

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);
    			}
    		}
    	}
    }

Posted

You need to use j.getItemDamage(). That gets the damage/metadata of the itemstack

"Thinking that coding is the nerdy IT guy at work rebooting your computer is like thinking that music is what happens when the piano tuner comes round." - Ed Rex

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.