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'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?

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

 

 

  • Author

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.

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

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.