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
When summoning a mob with a weapon:
/summon husk ~ ~1 ~ {HandItems:[{Count:1,id:wooden_sword,tag:{Enchantments:[{id:fire_aspect,lvl:2}]}},{}]}
Get a shield
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
relates to 2
Attachments
Comments 15
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]
1.15.2 and 20w06a are affected. Also, this bug relates to MC-93892 and MC-106179.