mojira.dev
MC-302190

Damage to recently damaged mobs calculates difference using unarmored values

In Minecraft, when damage is done to a mob when it’s recently been hurt, the mob only takes damage equal to the difference between the first and second damage value. If at or below zero, the damage instance will fail instead.
However, the problem with this mechanic is that the difference is calculated before armor is calculated, meaning that damaging a mob with non armor-piercing damage, then damaging a mob with armor-piercing damage causes some unexpected results.

To reproduce

Summon an armored mob.
Run /summon minecraft:zombie ~ ~ ~ {NoAI:1b,equipment:{head:{id:"netherite_helmet",count:1},chest:{id:"netherite_chestplate"},legs:{id:"netherite_leggings"},feet:{id:"netherite_boots"}},Tags:["armorpiercetest"]} Keep in mind that this mob will have 20 health at the start.

Damage that mob with a damage type that doesn’t pierce armor.
In a command block, input damage @n[tag=armorpiercetest] 10 player_attack

During the time where the mob is still red, damage them again with damage that does pierce armor, and would come out with a higher result than the first instance’s final result.

In a chain command block set to always active that is linked to the previous command block, input damage @n[tag=armorpiercetest] 15 generic_kill, then activate the first command block. Now, read the health of the mob, likely using /data get entity @n[tag=armorpiercetest] Health.

Expected result

The mob is damaged by the difference between the two final values, adding to be equivalent to the armor piercing damage’s value.

In our case, the mob’s final health should be 5, as it was at 20 health and took 15 armor piercing damage, which was higher than the final 2.0 damage that the arrow damage deals after the armor calculations are through.

Actual result

The mob is damaged by the difference between the two base damage values instead of the difference between the two final values.

Instead, the mob is left at 13 health, which is 20 - (2 + (15 - 10)). Having the second instance’s damage be below the first simply makes the command fail.

Notes

  1. Making the second damage instance’s value lower than the first damage instance’s value causes the command to fail outright.

  2. Fixing this would not likely impact any multiplayer experiences.

  3. May cause other bugs if fixed! Test damage thoroughly.

Comments 0

No comments.

WeirdPlop

(Unassigned)

Unconfirmed

(Unassigned)

1.21.8, 1.21.9 Pre-Release 2, 1.21.9 Release Candidate 1

Retrieved