1.17.1, 21w43a, 1.18.1, 22w06a, 22w15a, 1.19 Pre-release 4, 1.19
The attribute minecraft:generic.attack_knockback doesn't seem to be working in a consistent way when using shields. If a mob has X value of attack knockback above 0, the knockback applied to a player blocking isn't proportional to the attribute value.
Wardens, Ravagers, Hoglins & Zoglins support the attack_knockback attribute and have X value by default, but there are some mobs that manage to work with this attribute (i.e. zombies, spiders, etc) althought there are exceptions (
MC-180199). Here are the inconsistencies i noticed:
1.- If a mob with AK (attack_knockback) has said attribute value above 0, the knockback works fine on attacks, but if they are blocked by a shield the knockback isn't affected by this value. Wardens fall in this category.
: An endermite with an AK of 5 applies a lot of knockback to the player but if the player is blocking it would be as if the mob still had an AK value of 0, the player doesn't move at all.
2.- Ravager knockback applied to the shield isn't tied to AK attribute, seems to be hardcoded, but normal attacks work fine.
: If a ravager has an AK of 0 the player will still receive knockback if they're blocking, and if the value is 5 the knockback wouldn't be any different either.
3.- Hoglins & Zoglins are exempt from this. Regardless of the AK value, the knockback applied to the shield is proportional, blocking or not. However, it also depends on whether or not the player is touching the ground (if they are, the knockback is massively reduced).
: A zoglin with an AK of 0 will not apply knockback to you, but if it has a value of 5 it'll launch you very high up in the air, blocking or not.
The attack_knockback attribute would act the same way on other mobs as how it works on Hoglins and Zoglins when attacks are blocked, fixing the inconsistency.
How to reproduce
There's a lot of steps to demonstrate this, so i'll only focus on the first point. You can take into account all the logic of other points above and test by yourself. Make use of /attribute and /summon.
- Summon a husk with an attack_knockback of 5, switch to survival.
- The husk attacks you applying high knockback to you.
- If you are blocking with a shield, the husk doesn't apply any knockback.