mojira.dev
MC-158245

Fire Aspect enchantment from mobs can set you on fire even when blocking with a shield

The bug

In combat, using a shield against a mob that has an enchanted sword with the fire aspect enchantment still sets the player on fire. However, the damage from the mob itself is fully blocked while the effect of the enchantment can still damage the player via fire damage.

How to reproduce

  1. When summoning a mob with a weapon:

    /summon husk ~ ~1 ~ {HandItems:[{Count:1,id:wooden_sword,tag:{Enchantments:[{id:fire_aspect,lvl:2}]}},{}]}
  2. Get a shield

  3. Go to survival mode hold right-click, and let the mob attack you
    → ❌ The player catches on fire.

Code analysis

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 15

1.15.2 and 20w06a are affected. Also, this bug relates to MC-93892 and MC-106179.

1.16.2 Pre-release 2 is affected.

Cannot confirm fixed. Can still reproduce in 20w51a.

Still happens in 20w51a but only for mobs and not players.

5 more comments

Can confirm in 1.17.1.

Can confirm in 1.18.1.

Can confirm in 1.18.2.

Can confirm in 1.19.2.

Code Analysis \ Fix \ MCP-Reborn

Here inside doHurtTarget(), the game checks to see if the attacking entitiy's fireAspect level is greater than zero before lighting a target on fire. This check does not account for if the target is blocking. A simple fix would be to check if the entity is a living entity, and if it is, check if the entity is not blocking before lighting the target on fire.

The method currently:

Class: net\minecraft\world\entity\Mob.java - Method: doHurtTarget()
public boolean doHurtTarget(Entity entity) {
         float attackDamage = (float)this.getAttributeValue(Attributes.ATTACK_DAMAGE);
         float attackKnockback = (float)this.getAttributeValue(Attributes.ATTACK_KNOCKBACK);
         if (entity instanceof LivingEntity) {
            attackDamage += EnchantmentHelper.getDamageBonus(this.getMainHandItem(), ((LivingEntity)entity).getMobType());
            attackKnockback += (float)EnchantmentHelper.getKnockbackBonus(this);
         }
         int fireAspect = EnchantmentHelper.getFireAspect(this);
         if (fireAspect > 0) {
            entity.setSecondsOnFire(fireAspect * 4);
         }
         boolean flag = entity.hurt(this.damageSources().mobAttack(this), attackDamage);
         if (flag) {
            if (attackKnockback > 0.0F && entity instanceof LivingEntity) {
               ((LivingEntity)entity).knockback((double)(attackKnockback * 0.5F), (double)Mth.sin(this.getYRot() * ((float)Math.PI / 180F)), (double)(-Mth.cos(this.getYRot() * ((float)Math.PI / 180F))));
               this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
            }
            if (entity instanceof Player player) {
               this.maybeDisableShield(player, this.getMainHandItem(), player.isUsingItem() ? player.getUseItem() : ItemStack.EMPTY);
            }
            this.doEnchantDamageEffects(this, entity);
            this.setLastHurtMob(entity);
         }
         return flag;
      }

The Fix:

. . .
         int fireAspect = EnchantmentHelper.getFireAspect(this);
         if (fireAspect > 0) {
Fix Start
            if (entity instanceof LivingEntity livingEntity && !livingEntity.isBlocking()) {
               livingEntity.setSecondsOnFire(fireAspect * 4);
            }
Fix End
         }
. . .

This fix provides the following behavior (the husk has a fire aspect sword):

[media]

DrownedZombie

slicedlime

Confirmed

Combat

1.14.4, 19w34a, 1.15.2, 20w06a, 20w10a, ..., 1.19.2, 1.19.4, 23w17a, 1.20 Release Candidate 1, 1.20

24w18a

Retrieved