Mojira Archive
MC-248961

takenDamage for achievement criteria is calculated wrongly when the player has equipped a helmet

When a player takes damage from a DamageSource of ANVIL, FALLING_BLOCK, or FALLING_STALACTITE, if the player is wearing head gear, there will be a difference between the actual damage taken by the player and the damage seen in Advancement criteria.

 

Code analysis

net.minecraft.world.entity.LivingEntity
public abstract class LivingEntity extends Entity {
    ...

    public boolean hurt(DamageSource damageSource, float f) {
        ...

        if ((float)this.invulnerableTime > 10.0f) {
            ...

            this.actuallyHurt(damageSource, f - this.lastHurt);
            ...

        } else {
            ...

            this.actuallyHurt(damageSource, f);
            ...

        }
        if (damageSource.isDamageHelmet() && !this.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) {
            ...

            f *= 0.75f;
        }
        ...

        if (this instanceof ServerPlayer) {
            CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayer)this, damageSource, f2, f, bl2);
         ...

        }
    }
}

The difference occurs because the variable f is multiplied by 0.75f after LivingEntity#actuallyHurt.

Fixed

Chen

[Mojang] etanaratsastaja

2022-03-10, 08:45 AM

2023-12-08, 09:48 AM

2023-12-08, 09:48 AM

9

4

Confirmed

Low

Platform

Advancements

advancement, entity_hurt_player

1.18.2, 1.20.1, 1.20.2

23w51a