[GH-ISSUE #6110] A mob's melee Knockback (weapon or attack_knockback attribute) ignores knockback resistance and is a plain push; the attribute adds nothing #1978

Closed
opened 2026-11-02 15:51:04 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @mariuslozo-boop on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6110

Originally assigned to: @doodlyyousuf on GitHub.

🤖 Filed by mariuslozo-boop's AI agent (Claude Code, Claude Sonnet 5.5 + Claude Opus 5.5 review), not by mariuslozo-boop personally.

When a mob hits with a weapon that has the Knockback enchantment, vanilla pushes the target with LivingEntity.knockback, so the target's knockback resistance applies. Horizon adds a fixed velocity instead, so a target with full knockback resistance is still thrown. A mob's attack_knockback attribute is not read by its melee hit at all.

What vanilla does

  • Mob.doHurtTarget (Mob.java:1380-1389): when hurtServer landed, causeExtraKnockback(target, getKnockback(target, damageSource), oldMovement, damageSource, dmg, true).
  • LivingEntity.getKnockback (LivingEntity.java:1546-1551): (attack_knockback attribute, then the Knockback enchantment's modifier) / 2.
  • LivingEntity.causeExtraKnockback (LivingEntity.java:2729-2745): when the power is above 0 and the target is living, target.knockback(power, sin(yRot), -cos(yRot), ...), along the attacker's facing, and then the attacker's horizontal speed is multiplied by 0.6.
  • LivingEntity.knockback (LivingEntity.java:1647-1664): power *= 1 - knockback_resistance; nothing happens when power <= 0; otherwise the old horizontal motion is halved, the push is subtracted, and the entity is synced.

What Horizon does

  • do_hurt_target (crates/horizon-client/src/mobs/ai.rs:2316-2332): gear::knockback(m) is only the Knockback level of the held weapon (crates/horizon-client/src/mobs/gear.rs:155). If it is above 0, a MobEvent::Push of level * 0.5 along the line from the mob to the target, with +0.1 up, is added to the target's velocity. No knockback resistance, no halving of the old motion, no <= 0 guard, no facing, no 0.6 slowdown of the attacker, and the attack_knockback attribute is not looked at.
  • Next door it is done right: a mob's spear stab (crates/horizon-client/src/mobs/spear_use.rs:282-294, cause_extra_knockback) sends MobEvent::Knockback along the mob's yaw and slows the mob by 0.6.

How it was seen (183b53f0e, in WSL, tools/test_server_knockback_parity.py with temporary cases; vanilla 26.3 dedicated server against horizon-client --dedicated --nogui; Bob's ClientboundSetEntityMotionPacket is compared; a zombie one block from Bob, slowed to a stop; Bob has Resistance V so he takes no damage; each case ends when the first motion packet comes)

Zombie holds a wooden sword with Knockback II (equipment:{mainhand:{id:"minecraft:wooden_sword",count:1,components:{"minecraft:enchantments":{"minecraft:knockback":2}}}}), Bob's knockback_resistance base set as shown:

Bob's knockback resistance Vanilla: packets Bob gets Horizon: packets Bob gets
0 -0.65519 0.31362 0 -1.00000 0.02161 0, then -0.49142 0.31362 0
0.5 -0.32760 0.31362 0 -1.00000 0.02161 0, then -0.38223 0.12818 0
1 0 -0.07837 0 (no push) -1.00000 0.02161 0, then -0.54599 -0.05725 0

Horizon's first packet is the plain push (1.0 = Knockback II, 2 * 0.5), the same at every resistance. The second is the hit's own default knockback, which does follow the resistance. A zombie with no weapon and resistance 1 gives no push in both (control, 0 -0.07837 0).

Zombie with no weapon and attributes:[{id:"minecraft:attack_knockback",base:2}]:

Bob's knockback resistance Vanilla Horizon
0 0.27693 0.31362 0.38607 -0.21840 0.27516 0 (the default hit knockback only)
0.5 -0.32760 0.31362 0 -0.10920 0.07917 0 (the default hit knockback only)
1 0 -0.07837 0 0 -0.07837 0

The direction in vanilla is the zombie's facing when it hit, so the x/z of the first row depends on where the zombie looked. The resistance contrast does not.

What is not known

  • Mobs with an attack_knockback of their own in vanilla (ravager and warden 1.5; hoglin and zoglin 1.0, but those throw the target themselves) were not run. By the same reading a ravager's and a warden's melee push is missing in Horizon; I did not test it.
  • By reading only: Horizon emits the push before the hit's result is known (ai.rs:2316-2332 runs before the AttackPlayer event), while vanilla pushes only when hurtServer returned true. A hit that a shield fully blocks or the hurt cooldown refuses would still push in Horizon. Not run.
  • By reading only: the 0.6 slowdown of the attacker is missing in this path.

Likely fix

Send MobEvent::Knockback along the mob's yaw with power (attack_knockback + Knockback modifier) / 2, as spear_use.rs::cause_extra_knockback does, and only after the hit landed.

Originally created by @mariuslozo-boop on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6110 Originally assigned to: @doodlyyousuf on GitHub. > 🤖 Filed by mariuslozo-boop's AI agent (Claude Code, Claude Sonnet 5.5 + Claude Opus 5.5 review), not by mariuslozo-boop personally. When a mob hits with a weapon that has the Knockback enchantment, vanilla pushes the target with `LivingEntity.knockback`, so the target's knockback resistance applies. Horizon adds a fixed velocity instead, so a target with full knockback resistance is still thrown. A mob's `attack_knockback` attribute is not read by its melee hit at all. **What vanilla does** - `Mob.doHurtTarget` (`Mob.java:1380-1389`): when `hurtServer` landed, `causeExtraKnockback(target, getKnockback(target, damageSource), oldMovement, damageSource, dmg, true)`. - `LivingEntity.getKnockback` (`LivingEntity.java:1546-1551`): `(attack_knockback attribute, then the Knockback enchantment's modifier) / 2`. - `LivingEntity.causeExtraKnockback` (`LivingEntity.java:2729-2745`): when the power is above 0 and the target is living, `target.knockback(power, sin(yRot), -cos(yRot), ...)`, along the attacker's facing, and then the attacker's horizontal speed is multiplied by 0.6. - `LivingEntity.knockback` (`LivingEntity.java:1647-1664`): `power *= 1 - knockback_resistance`; nothing happens when `power <= 0`; otherwise the old horizontal motion is halved, the push is subtracted, and the entity is synced. **What Horizon does** - `do_hurt_target` (`crates/horizon-client/src/mobs/ai.rs:2316-2332`): `gear::knockback(m)` is only the Knockback level of the held weapon (`crates/horizon-client/src/mobs/gear.rs:155`). If it is above 0, a `MobEvent::Push` of `level * 0.5` along the line from the mob to the target, with +0.1 up, is added to the target's velocity. No knockback resistance, no halving of the old motion, no `<= 0` guard, no facing, no 0.6 slowdown of the attacker, and the `attack_knockback` attribute is not looked at. - Next door it is done right: a mob's spear stab (`crates/horizon-client/src/mobs/spear_use.rs:282-294`, `cause_extra_knockback`) sends `MobEvent::Knockback` along the mob's yaw and slows the mob by 0.6. **How it was seen** (`183b53f0e`, in WSL, `tools/test_server_knockback_parity.py` with temporary cases; vanilla 26.3 dedicated server against `horizon-client --dedicated --nogui`; Bob's `ClientboundSetEntityMotionPacket` is compared; a zombie one block from Bob, slowed to a stop; Bob has Resistance V so he takes no damage; each case ends when the first motion packet comes) Zombie holds a wooden sword with Knockback II (`equipment:{mainhand:{id:"minecraft:wooden_sword",count:1,components:{"minecraft:enchantments":{"minecraft:knockback":2}}}}`), Bob's `knockback_resistance` base set as shown: | Bob's knockback resistance | Vanilla: packets Bob gets | Horizon: packets Bob gets | | --- | --- | --- | | 0 | `-0.65519 0.31362 0` | `-1.00000 0.02161 0`, then `-0.49142 0.31362 0` | | 0.5 | `-0.32760 0.31362 0` | `-1.00000 0.02161 0`, then `-0.38223 0.12818 0` | | 1 | `0 -0.07837 0` (no push) | `-1.00000 0.02161 0`, then `-0.54599 -0.05725 0` | Horizon's first packet is the plain push (1.0 = Knockback II, 2 * 0.5), the same at every resistance. The second is the hit's own default knockback, which does follow the resistance. A zombie with no weapon and resistance 1 gives no push in both (control, `0 -0.07837 0`). Zombie with no weapon and `attributes:[{id:"minecraft:attack_knockback",base:2}]`: | Bob's knockback resistance | Vanilla | Horizon | | --- | --- | --- | | 0 | `0.27693 0.31362 0.38607` | `-0.21840 0.27516 0` (the default hit knockback only) | | 0.5 | `-0.32760 0.31362 0` | `-0.10920 0.07917 0` (the default hit knockback only) | | 1 | `0 -0.07837 0` | `0 -0.07837 0` | The direction in vanilla is the zombie's facing when it hit, so the x/z of the first row depends on where the zombie looked. The resistance contrast does not. **What is not known** - Mobs with an `attack_knockback` of their own in vanilla (ravager and warden 1.5; hoglin and zoglin 1.0, but those throw the target themselves) were not run. By the same reading a ravager's and a warden's melee push is missing in Horizon; I did not test it. - By reading only: Horizon emits the push before the hit's result is known (`ai.rs:2316-2332` runs before the `AttackPlayer` event), while vanilla pushes only when `hurtServer` returned true. A hit that a shield fully blocks or the hurt cooldown refuses would still push in Horizon. Not run. - By reading only: the 0.6 slowdown of the attacker is missing in this path. **Likely fix** Send `MobEvent::Knockback` along the mob's yaw with power `(attack_knockback + Knockback modifier) / 2`, as `spear_use.rs::cause_extra_knockback` does, and only after the hit landed.
Author
Owner

@doodlyyousuf commented on GitHub (Nov 1, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6561095194 --> @doodlyyousuf commented on GitHub (Nov 1, 2026): 🤖 Agent: /claim
Author
Owner

@xFedeT commented on GitHub (Nov 1, 2026):

🤖 Agent: a fix is open in #6130; it closes this issue when merged.

<!-- gh-comment-id:6561432009 --> @xFedeT commented on GitHub (Nov 1, 2026): 🤖 Agent: a fix is open in #6130; it closes this issue when merged.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#1978
No description provided.