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

need to stop my tools from breaking when they hit 0 durability

I have read through so many classes and can't find anywhere where tools are told to break at 0 durability.

i would appreciate help locating the class  or method that deals with this or if you happen to have a code snippet that may help i would be greatly appreciative.

 

thanks for reading.

make it like my mod (Tools Works backworks!) You start at the last use and ends at the first! Works pretty fine.

 

Or use this

 

      public boolean onBlockDestroyed(ItemStack var1, int par2, int par3, int par4, int par5, EntityLiving par6)

    {

          if(par1.getItemDamage() < par1.getMaxDamage())

          {

                par1.damageItem(1, par6);

          }

      }

 

its only give damage if the damage is smaler than the max Damage. hope it helps..

  • Author

thanks for the help so far...

 

Ok so i have got to this -

 


public boolean hitEntity(ItemStack itemStack, EntityLiving entity, EntityLiving entityLiving) {
	this.iDmg = itemStack.getItemDamage();
	if (iDmg == toolMaterial.getMaxUses()) {
		itemStack.damageItem(0, entityLiving);

	}else{
		itemStack.damageItem(1, entityLiving);			
	}
	return true;
}

Works as expected

public int getDamageVsEntity(Entity entity) {
	if(iDmg == toolMaterial.getMaxUses()){
		return this.weaponDamage = 1;
	}else{
		return this.weaponDamage = 9;
	}
}

Also works as expexted

But when i set return this.weaponDamage = 1; to 0  it stops doing damage as expected. but the weapon damage stay at 0 after switching to a undamaged weapon.

has anyone got any sort of solution for this

 

thanks for any help

any help is great appreciated.

You can't save the item's damage in it's class, that why there is the ItemStack parameter. Instead in getDamageVsEntity get the itemstack the player is holding and it's damage.

No 5 row long documentation = account on the help forums

why dont you use this?

int damage = 0;

 

public int getDamageVsEntity(Entity par1)

{

    return damage;

}

 

public void onUpdate(ItemStack par1, World par2, Entity par3, int par4, boolean par5)

{

    if(par5)//if the player hold it in the hand

    {

            if(par1.getItemDamage() == par1.getMaxDamage())

            {

                damage = 1;

            }

            else

            {

                damage = 9;

            }

      }

}

 

than every tick he hold it in his and its updating the damage. I hope its helping.

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.