[SPIGOT-7732] Issue with the "hurt()" method of EntityLiving Created: 07/Jun/24  Updated: 25/Dec/24  Resolved: 22/Jun/24

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Kami Rori Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None

Version: This server is running CraftBukkit version 4149-Spigot-e2c1eee-4e7d749 (MC: 1.20.6) (Implementing API version 1.20.6-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

 
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.


Generated at Sat Dec 13 13:43:26 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.