Jump to content

Get rid of the protection enchanting calculation


zerozhou

Recommended Posts

I'm handling with my own damage source with new mob and items.

But when I hurt the entity, it always calculate the protection enchanting in the DamageEntity().

I don't want the protection enchanting being active with my new damage source. Is there any way to do this?

Link to comment
Share on other sites

Hi

 

Yes there is.

 

The code from EntityLivingBase:

    protected void damageEntity(DamageSource par1DamageSource, float par2)
    {
        if (!this.isEntityInvulnerable())
        {
            par2 = ForgeHooks.onLivingHurt(this, par1DamageSource, par2);
            if (par2 <= 0) return;
            par2 = this.applyArmorCalculations(par1DamageSource, par2);
            par2 = this.applyPotionDamageCalculations(par1DamageSource, par2);
            float f1 = par2;
            par2 = Math.max(par2 - this.getAbsorbtion(), 0.0F);
            this.func_110149_m(this.getAbsorbtion() - (f1 - par2));

            if (par2 != 0.0F)
            {
                float f2 = this.getHealth();
                this.setEntityHealth(f2 - par2);
                this.func_110142_aN().func_94547_a(par1DamageSource, f2, par2);
                this.func_110149_m(this.getAbsorbtion() - par2);
            }
        }
    }

 

If you use the Forge LivingHurtEvent (http://www.minecraftforum.net/topic/1419836-forge-4x-events-howto/), you can move the damage calculations into your own class and not perform the armour and potiondamagecalculations.

 

-TGG

 

 

Link to comment
Share on other sites

I've set my own damagesource to unblockable to skip the armor calculation.

But as I see the code, applyPotionDamageCalculations() is the function that calculate the effect of potion and enchanting.

i = EnchantmentHelper.getEnchantmentModifierDamage(this.getLastActiveItems(), par1DamageSource);

is the calculator of the enchanting. And yes I find I can set isDamageAllowedInCreativeMode in the damagesource to do this. But this require me to handle the hurt event to cancel the damage to the player in gamemode 1. Is this the idea you are talking about? As it looks a little strange.

 

:)  It seems to be sloved. I'll try it later.

Link to comment
Share on other sites

Hi

 

Sort of - I mean for example

 

  @ForgeSubscribe
  public void myLivingHurt(LivingHurtEvent event)
  {
    DamageSource damageSource = event.source;
    float amount = event.ammount;
    EntityLivingBase entityLivingBase = event.entityLiving;
    float damage = amount;
// par2 = ForgeHooks.onLivingHurt(this, par1DamageSource, par2);
// if (par2 <= 0) return;
// par2 = this.applyArmorCalculations(par1DamageSource, par2);
// par2 = this.applyPotionDamageCalculations(par1DamageSource, par2);
    float f1 = damage;
    damage = Math.max(damage - entityLivingBase.getAbsorbtion(), 0.0F);
    entityLivingBase.func_110149_m(entityLivingBase.getAbsorbtion() - (f1 - damage));

    if (damage != 0.0F)
    {
      float f2 = entityLivingBase.getHealth();
      entityLivingBase.setEntityHealth(f2 - damage);
      entityLivingBase.func_110142_aN().func_94547_a(par1DamageSource, f2, damage);
      entityLivingBase.func_110149_m(this.getAbsorbtion() - damage);
    }
    return -1;
  }

 

-TGG

Link to comment
Share on other sites

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.