Jump to content

Recommended Posts

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.

Posted

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

Posted

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.

Posted

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

Posted

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

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