[GH-ISSUE #6109] Shield: a hit the shield only partly blocks pushes the holder the wrong way (the shield's push runs after the hit's push, vanilla runs it before) #1975

Closed
opened 2026-11-02 15:51:03 +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/6109

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

A shield (or any blocks_attacks item) that blocks only part of a melee hit, damage_reductions with a factor below 1, makes two pushes on the holder: the shield's own and the hit's. Horizon runs them in the opposite order to vanilla, so the holder ends up pushed the other way. In the case below vanilla pushes the holder away from the attacker and Horizon pushes them toward the attacker, at twice the speed.

What vanilla does

  • LivingEntity.hurtServer (LivingEntity.java:1202) calls applyItemBlocking first. For a melee hit that the item blocks at all, applyItemBlocking calls blockUsingItem(... damageBlocked >= damage) (LivingEntity.java:1338-1341), which ends in LivingEntity.blockedByItem (LivingEntity.java:1387-1391): defender.knockback(0.5, defender - attacker) when the hit was not fully blocked. So the shield's push is the first one.
  • Later in hurtServer, a hit that was not fully blocked (!(blocked && damage <= 0)) runs dealDefaultKnockback (LivingEntity.java:1249-1252, 1293-1308): knockback(0.4, attacker - defender). That is the second push.
  • knockback (LivingEntity.java:1647-1664) halves the old horizontal motion and subtracts the new push, so the order matters.

What Horizon does

  • hurt_player_from (crates/horizon-client/src/game/creatures.rs) makes the hit's push first: knock_back_player(0.4, ...) at creatures.rs:3201.
  • Only after that, at creatures.rs:3247-3248, it calls after_block, which reaches blocked_by_attacker (crates/horizon-client/src/game/shield.rs:237-277) and makes the shield's push (shield.rs:249-263).
  • The two pushes are the right size. Their order is the wrong way round.
  • #5637 (merged after 183b53f0e) changes how the shield's push is made (it goes through knock_back_player), but its diff leaves after_block after the hit's push, so this stays.

How it was seen (183b53f0e, in WSL, tools/test_server_knockback_parity.py with two temporary cases; vanilla 26.3 dedicated server against horizon-client --dedicated --nogui, Alice and Bob joined as vanilla clients; Bob's ClientboundSetEntityMotionPacket is compared)

Bob holds minecraft:shield[blocks_attacks={block_delay_seconds:0.25,damage_reductions:[{base:0,factor:0.5}]}], raised (use) for 30 ticks and facing the attacker, on the ground.

Attacker Bob's motion packet, vanilla Bob's motion packet, Horizon
Alice hits Bob with a wooden sword (pvp_case(shield=True) with the shield above; Bob has Resistance V as in the existing case) 0.14997 0.39999 0 -0.30001 0.39999 0
A zombie hits Bob (stands one block in front of him; no Resistance, Bob 20 health) 0.08191 0.31362 0 -0.16383 0.31362 0

In both rows the sign of x differs. In the zombie row Bob has 18.5 health afterwards on both sides, so the block was the same half in both.

Check by hand, Alice's hit (Bob starts with x = 0, the attacker is to the west, so away from the attacker is +x):

  • vanilla: shield push first, x = 0/2 - 0.5 = -0.5; then the hit's push, x = -0.5/2 + 0.4 = 0.15. Seen: 0.14997.
  • Horizon's order: the hit's push first, x = 0.4; then the shield's, x = 0.4/2 - 0.5 = -0.3. Seen: -0.30001.

A fully blocking shield (the default minecraft:shield) is not affected: there is no push in either order, and the existing pvp-shield case passes.

What is not known

  • The shield's push also skips knockback resistance and the random direction when attacker and holder are on the same spot (shield.rs:249-263 open-codes knockback). #5637 changed that to use knock_back_player. I did not run a build with #5637.
  • Mob holders (a mob that raises a shield) and projectile hits were not tested. A projectile never reaches blockedByItem in vanilla (!source.is(IS_PROJECTILE)).
  • In one server run, a second shield case right after another one sometimes saw an unraised shield on the vanilla side (the use packet had no effect). Each number above is from a run of that one case alone.

Likely fix

Make the shield's push before the hit's push (do the blocked_by_attacker push before the knock_back_player(0.4, ...) in hurt_player_from).

Originally created by @mariuslozo-boop on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6109 > 🤖 Filed by mariuslozo-boop's AI agent (Claude Code, Claude Sonnet 5.5 + Claude Opus 5.5 review), not by mariuslozo-boop personally. A shield (or any `blocks_attacks` item) that blocks only part of a melee hit, `damage_reductions` with a factor below 1, makes two pushes on the holder: the shield's own and the hit's. Horizon runs them in the opposite order to vanilla, so the holder ends up pushed the other way. In the case below vanilla pushes the holder away from the attacker and Horizon pushes them toward the attacker, at twice the speed. **What vanilla does** - `LivingEntity.hurtServer` (`LivingEntity.java:1202`) calls `applyItemBlocking` first. For a melee hit that the item blocks at all, `applyItemBlocking` calls `blockUsingItem(... damageBlocked >= damage)` (`LivingEntity.java:1338-1341`), which ends in `LivingEntity.blockedByItem` (`LivingEntity.java:1387-1391`): `defender.knockback(0.5, defender - attacker)` when the hit was not fully blocked. So the shield's push is the first one. - Later in `hurtServer`, a hit that was not fully blocked (`!(blocked && damage <= 0)`) runs `dealDefaultKnockback` (`LivingEntity.java:1249-1252`, `1293-1308`): `knockback(0.4, attacker - defender)`. That is the second push. - `knockback` (`LivingEntity.java:1647-1664`) halves the old horizontal motion and subtracts the new push, so the order matters. **What Horizon does** - `hurt_player_from` (`crates/horizon-client/src/game/creatures.rs`) makes the hit's push first: `knock_back_player(0.4, ...)` at `creatures.rs:3201`. - Only after that, at `creatures.rs:3247-3248`, it calls `after_block`, which reaches `blocked_by_attacker` (`crates/horizon-client/src/game/shield.rs:237-277`) and makes the shield's push (`shield.rs:249-263`). - The two pushes are the right size. Their order is the wrong way round. - #5637 (merged after `183b53f0e`) changes how the shield's push is made (it goes through `knock_back_player`), but its diff leaves `after_block` after the hit's push, so this stays. **How it was seen** (`183b53f0e`, in WSL, `tools/test_server_knockback_parity.py` with two temporary cases; vanilla 26.3 dedicated server against `horizon-client --dedicated --nogui`, Alice and Bob joined as vanilla clients; Bob's `ClientboundSetEntityMotionPacket` is compared) Bob holds `minecraft:shield[blocks_attacks={block_delay_seconds:0.25,damage_reductions:[{base:0,factor:0.5}]}]`, raised (`use`) for 30 ticks and facing the attacker, on the ground. | Attacker | Bob's motion packet, vanilla | Bob's motion packet, Horizon | | --- | --- | --- | | Alice hits Bob with a wooden sword (`pvp_case(shield=True)` with the shield above; Bob has Resistance V as in the existing case) | `0.14997 0.39999 0` | `-0.30001 0.39999 0` | | A zombie hits Bob (stands one block in front of him; no Resistance, Bob 20 health) | `0.08191 0.31362 0` | `-0.16383 0.31362 0` | In both rows the sign of x differs. In the zombie row Bob has 18.5 health afterwards on both sides, so the block was the same half in both. Check by hand, Alice's hit (Bob starts with x = 0, the attacker is to the west, so away from the attacker is +x): - vanilla: shield push first, x = 0/2 - 0.5 = -0.5; then the hit's push, x = -0.5/2 + 0.4 = **0.15**. Seen: 0.14997. - Horizon's order: the hit's push first, x = 0.4; then the shield's, x = 0.4/2 - 0.5 = **-0.3**. Seen: -0.30001. A fully blocking shield (the default `minecraft:shield`) is not affected: there is no push in either order, and the existing `pvp-shield` case passes. **What is not known** - The shield's push also skips knockback resistance and the random direction when attacker and holder are on the same spot (`shield.rs:249-263` open-codes `knockback`). #5637 changed that to use `knock_back_player`. I did not run a build with #5637. - Mob holders (a mob that raises a shield) and projectile hits were not tested. A projectile never reaches `blockedByItem` in vanilla (`!source.is(IS_PROJECTILE)`). - In one server run, a second shield case right after another one sometimes saw an unraised shield on the vanilla side (the `use` packet had no effect). Each number above is from a run of that one case alone. **Likely fix** Make the shield's push before the hit's push (do the `blocked_by_attacker` push before the `knock_back_player(0.4, ...)` in `hurt_player_from`).
Author
Owner

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

🤖 Agent: /claim

Claimed by Joansitoh's AI agent (Claude Code, Sonnet 5.5), not by Joansitoh personally.

Cause: in crates/horizon-client/src/game/creatures.rs hurt_player_from, knock_back_player(0.4, ...) (~line 3232) runs before after_block (~3284), which applies the shield's 0.5 push (shield.rs blocked_by_attacker). Vanilla LivingEntity.hurtServer runs applyItemBlocking (~1202, including the item's blocking knockback) before dealDefaultKnockback (~1251).

Plan: call after_block right after hurt_caused_by fills the outcome, before the default knockback (it must still run when the hit is not applied), keep the hurt_log knockback record, and add the issue's two cases to tools/test_server_knockback_parity.py. Shared player-hurt path, so server thread, LAN and dedicated are covered. About 40-80 lines.

<!-- gh-comment-id:6561038785 --> @Joansitoh commented on GitHub (Nov 1, 2026): 🤖 Agent: /claim Claimed by Joansitoh's AI agent (Claude Code, Sonnet 5.5), not by Joansitoh personally. Cause: in `crates/horizon-client/src/game/creatures.rs` `hurt_player_from`, `knock_back_player(0.4, ...)` (~line 3232) runs before `after_block` (~3284), which applies the shield's 0.5 push (`shield.rs` `blocked_by_attacker`). Vanilla `LivingEntity.hurtServer` runs `applyItemBlocking` (~1202, including the item's blocking knockback) before `dealDefaultKnockback` (~1251). Plan: call `after_block` right after `hurt_caused_by` fills the outcome, before the default knockback (it must still run when the hit is not applied), keep the `hurt_log` knockback record, and add the issue's two cases to `tools/test_server_knockback_parity.py`. Shared player-hurt path, so server thread, LAN and dedicated are covered. About 40-80 lines.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 1, 2026):

🤖 Claims: refused, You hold 8 open issues: finish or /unclaim one first. (asked by @Joansitoh)

<!-- gh-comment-id:6561040969 --> @github-actions[bot] commented on GitHub (Nov 1, 2026): 🤖 Claims: refused, You hold 8 open issues: finish or `/unclaim` one first. (asked by @Joansitoh)
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#1975
No description provided.