Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7732

Issue with the "hurt()" method of EntityLiving

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • This server is running CraftBukkit version 4149-Spigot-e2c1eee-4e7d749 (MC: 1.20.6) (Implementing API version 1.20.6-R0.1-SNAPSHOT)
    • Yes

       
      The issue remains a damage modifier issue that has persisted for several years. The issue is that the hurt() method is wrong about whether an entity should be injured during the invulnerable time. The hurt() method is roughly as follows:

      f = originalDamage;
      /*
      damage modifications
      */
      if ( ! invulnerable )
      {   if ( f <= this.lastHurt ) return false;   this.actuallyHurt(damagesource, f - this.lastHurt);   this.lastHurt = f;   this.hurtEffect = false; }
      else
      {   this.lastHurt = f;   this.invulnerableTime = 20;   this.actuallyHurt(damagesource, f);   this.hurtDuration = 10;   this.hurtTime = this.hurtDuration; }

      In this section, you can see that f is the damage value. Vanilla changes the value of f directly after the damage modification. spigot's damageModifier correctly calculates the final damage value, but spigot does not change the value of f. As a result, during the invulnerable time, the behavior that was supposed to compare the original damage value to determine whether the actual damage was caused was incorrectly modified to compare the final damage value.
      The general way to do this is to change the return value of actuallyHurt(). Make it return an object of the DamageResult class. The DamageResult class should include information about the final damage value and whether actual harm was caused.
      But two questions remain:
      1. In order to minimize code changes and errors, can we pass an object of the DamageResult class to the actuallyHurt() method as a reference argument? This way we don't need to change the return value of the actuallyHurt() method.
      2. In which file or directory should the definition of the new DamageResult class be placed?
      Language barrier, please understand! You can point out content whose meaning is not clearly expressed.

            Unassigned Unassigned
            LoliColleen Kami Rori
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: