Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-248961

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

XMLWordPrintable

    • Confirmed
    • Advancements
    • Low
    • Platform

      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.

            Dat12 [Mojang] etanaratsastaja
            ChenCMD Chen
            Votes:
            9 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: