Jump to content

Recommended Posts

Posted

I have an Item for which I give a maxDamage. I want to make it a durable item where its health decreases everytime you right click it. For some reason the durability doesnt show up. Here is my class minus the imports

 

public class ApplePickingGlove extends CustomItem{
public ApplePickingGlove(){
	super();
	setUnlocalizedName("Apple Picking Glove");
	this.maxStackSize = 1;
	this.setMaxDamage(20);
	this.setNoRepair();
	}

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {

ItemStack itemstack = player.getCurrentEquippedItem();	
if (itemstack != null && itemstack.getItem() == CommonProxy.applePickingGlove){
	ItemStack item = new ItemStack(CommonProxy.applePickingGlove, 2, (itemstack.getItemDamage()+1));

	if (item.getItemDamage() >= item.getMaxDamage()){	
		item.stackSize --;
}


}

	return itemStack;
	}

Posted

See that parameter passed in called itemStack? Use that. That is the ItemStack of your item.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Posted

I tried

 

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {


if (itemStack != null && itemStack.getItem() == CommonProxy.applePickingGlove){
	itemStack = new ItemStack(CommonProxy.applePickingGlove, 2, (itemStack.getItemDamage()+1));

	if (itemStack.getItemDamage() >= itemStack.getMaxDamage()){	
		itemStack.stackSize --;
}


}

	return itemStack;
	}

 

and still no durability

Posted

And your still doing it wrong...

 

 

Try this:

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {	
if (itemStack != null && itemStack.getItem() == CommonProxy.applePickingGlove){
	if (itemStack.getItemDamage() >= itemStack.getMaxDamage()){	

	}	
}
return itemStack;
}

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Posted

This worked But is there another way

 

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {	
	if (itemStack != null && itemStack.getItem() == CommonProxy.applePickingGlove){
		itemStack.damageItem(1, player);

	}
	return itemStack;
}

Posted

The problem with that method is that I cannot change the amount that durability drops by. I want durability of the item to be affected differently depending on which block the item interacts with. Say drop durability by 5 if you right click cobblestone but drop it by 1 if you right click leaves.

Posted

The problem with that method is that I cannot change the amount that durability drops by. I want durability of the item to be affected differently depending on which block the item interacts with. Say drop durability by 5 if you right click cobblestone but drop it by 1 if you right click leaves.

 

What you want is to use onItemUse().

So

public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) {
     Block target = world.getBlock(x, y, z);
     if (target == Blocks.leaves) {
          itemStack.damageItem(1, player);
     else if (target == Blocks.cobblestone) 
          itemStack.damageItem(5, player);
}

Lead DivineRPG Developer

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.