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.

[1.7.2] [Solved] Having trouble dealing durability damage to an item

Featured Replies

Posted

I am working on an update to my mod the Recipe Expansion Pack and I am having trouble making the plant book take durability when used (right clicked). I am writing my code inside of the "onItemUse" method. The issue is when I use it on wheat the first time the durability goes from 64/64 to 63/64 but then goes back up to 64/64 again when I use it the second time. This continues in a never ending loop each time I right click it resulting in the durability never going below 63.

 

Here is my code:

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
//Code to check stage of Wheat
if(par3World.getBlock(par4, par5, par6) == Blocks.wheat && par2EntityPlayer.worldObj.isRemote)
{
String text = "Wheat (Stage " + (par3World.getBlockMetadata(par4, par5, par6));
if((par3World.getBlockMetadata(par4, par5, par6) == 7))
{
text = text + " - \"Mature\"";
}
text = text + ")";

if(!text.equals(""))
{
par2EntityPlayer.addChatComponentMessage(new ChatComponentText(text));
if(!par2EntityPlayer.capabilities.isCreativeMode)
{
par1ItemStack.damageItem(1, par2EntityPlayer);
}
}
}
      }[/Code]

 

Any help with this would be greatly appreciated, as it seems very odd and has confused me for quite some time.

Creator of the Recipe Expansion Pack mod.

http://www.minecraftforum.net/topic/1983421-172-forge-recipe-expansion-pack-version-012/

Updated to 1.7.2!

  • Author

Actually I just realized the problem. So I figured I would just post this for future reference.

 

The issue is right here:

 

//Code to check stage of Wheat

if(par3World.getBlock(par4, par5, par6) == Blocks.wheat && par2EntityPlayer.worldObj.isRemote)

{

 

Apparently durability damage must be done client side so it should be this:

 

 

//Code to check stage of Wheat

if(par3World.getBlock(par4, par5, par6) == Blocks.wheat && !par2EntityPlayer.worldObj.isRemote)

{

Creator of the Recipe Expansion Pack mod.

http://www.minecraftforum.net/topic/1983421-172-forge-recipe-expansion-pack-version-012/

Updated to 1.7.2!

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.