What I expected to happen was...
When I attack a player with a knockback resistance armor piece, they take less knockback on a scale.
What actually happened was...:
When I attacked a player, say with 50% knockback resistance, they would take 50% less knockback (so far correct), but also have a 50% chance to not take knockback (which I don't believe is intended).
Steps to Reproduce:
Have a player wear a chestplate with knockback resistance on it. I used
/replaceitem entity @p armor.chest leather_chestplate{AttributeModifiers:[{AttributeName:"generic.knockback_resistance",Name:"generic.knockback_resistance",Amount:0.5,Operation:0,UUID:[I;42853,1689024593,-201178,-1559272105]}]}
Have another player hit the player wearing the chestplate several times (the problem is more easily seen when using an item with knockback on it)
Some of the time the player with the chestplate will take half (assuming 50% knockback resistance, which shows as 5 in the description and is 0.5 in the command) the amount of knockback, while other times they will take no knockback.
Linked issues
relates to 2
Comments 11
Looks like this is caused by LivingEntity.markHurt()
, which is as follows:
this.hurtMarked = this.random.nextDouble() >= this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
LivingEntity.knockback
was already updated in 20w06a to remove the randomness. markHurt
has no context passed in at the moment. It might just be fine to remove the override.
Still a huge issue for pvp that should be fixed for the current versions, not just the combat tests. PvP exists before the combat tests.
I noticed this only seems to be happening with players, i tested it with mobs using the /attribute command and it indeed works correctly (scaled instead of probability), while in players it is both.
The new netherite armor is affected by this, because you can have only one piece equipped and with 10% of probability you wouldn't take knockback at all.