Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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.

  • Author

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

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.

  • Author

Still no durability shows up when I hit f3 + H and on each right click the durability is not decreasd by 1

  • Author

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

That is how you are supposed to do it...

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

  • Author

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.