[PR #5903] [MERGED] Aim a guest's attack at a visible point of the mob, so hits through a slab or trapdoor gap land #6551

Closed
opened 2026-11-03 06:22:48 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5903
Author: @repositorykreml1n
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/attack-through-gaps-5772


📝 Commits (2)

  • d2e4a36 Aim a guest's attack at a visible point of the mob, so hits through a slab or trapdoor gap land
  • 97c18d7 lan_e2e attack_over_slab: a hit aimed at a zombie's head over a bottom slab lands (#5772)

📊 Changes

2 files changed (+208 additions, -6 deletions)

View changed files

📝 crates/horizon-client/src/game/lan_actions.rs (+163 -6)
📝 tools/lan_e2e.py (+45 -0)

📄 Description

🤖 Opened by repositorykreml1n's AI agent (Claude Code, Sonnet 5.5, with Gemini 3.8 Flash writing part of the code), not by repositorykreml1n personally.

What and why

Fixes #5772 (cannot attack mobs through slabs/trapdoors, which breaks mob farms).

Root cause: in single-player the player's attack goes through the integrated server as a guest attack. guest_attack (crates/horizon-client/src/game/lan_actions.rs) calls look_at_entity, which aimed the swapped-in player at the CENTRE of the target mob, and then Game::attack() drops the hit when a block outline is nearer than the mob along that ray (pick() vs mob_hit()). The attack packet names only the entity, so the server never sees the ray the player's crosshair really used. A mob that the player's own crosshair hits through a gap (top slab, closed top trapdoor, ...) therefore had its centre hidden behind the block and the hit was dropped (the sword swings, no damage, no hurt flash).

Fix: for mobs, look_at_entity now aims at a VISIBLE point of the mob's box: the centre when it is visible (behaviour unchanged), else the visible point of a 3x5x3 grid of points inside the box nearest to the centre (nearer the eyes on ties), found with block_between (a clip_ray from the eyes). When the whole box is hidden the centre is kept, so a really blocked hit is still refused as before. Other entity kinds (boats, minecarts, armor stands, frames, paintings, dragon parts) are untouched. look_at_entity has only two callers (guest attack, guest interact); the interact path on mobs gets the same visible-point choice.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

No vanilla source was checked in this change; parity was not verified. The expectation is the one in the issue (a mob in a gap that the crosshair hits can be hit).

Tests: game::lan_actions::aim_point_tests (6 tests of the pure visible_aim_point: visible centre kept; a top-slab gap picks a visible point inside the box lower than the centre; a bottom slab picks a point above it; a fully hidden mob keeps the centre; deterministic; an equally near point on the side of the eyes wins). These were written together with the fix, so they were not seen failing; the failing check before the fix is the in-game measurement below.

cargo test -p horizon-client --bin horizon-client aim_point_tests: 6 passed on d91cab6 + this patch, and 6 passed again on main (5edb339a7) + this patch after rustfmt. The vanilla jar is not prepared on the author's machine, so tools/rea_vanilla.py could not be run; CONTRIBUTING asks for a parity harness for gameplay changes and none was added here, the in-game measurement above is the only check.

In-game check

Windows, single-player, a copy of the reporter's world, official nightly d91cab6 for "before", the same source plus this patch built with the fast profile for "after"; a NoAI 1000-hp zombie in a 1x1 cell behind the gap block, real mouse clicks through horizon-ctl, 1 click per aim height, aims at y 70.3/70.9/71.5, the gap block on the open side. The in-game runs were on d91cab6 + this patch (before the rustfmt pass, which changed only formatting); the patch was not run in a game on main.

54 cases = 3 player feet heights (69, 70, 71) x standing/sneaking x 9 gap blocks (top slab, bottom slab, closed trapdoor bottom half, closed trapdoor top half, open trapdoor, stairs bottom, stairs top, fence, air control).

  • Before: 52 OK, 2 BUG_DROPPED (each 1 of 2 clicks dropped): closed top-half trapdoor standing at feet 69 and top slab sneaking at feet 69.
  • After: 54 OK, 0 dropped.

A separate earlier run, sneaking at feet 69 with a top slab, 5 clicks per case, 12 gap blocks: before top slab 0 of 5 hits, after 5 of 5; all other gap blocks hit before and after.

These are small samples (1-5 clicks per case), not statistics, and cases where the geometry itself hides the mob are reported as not targetable (correct behaviour), never counted as a drop.

Self-check

tools/pr_ready.py --base origin/main --quick on Windows, against origin/main at 5edb339a7 (5 min 59 s):

Check Result
Scope ✅ 1 file, +163 −6
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed
rustfmt ✅
clippy ❌ not run: clippy is not installed on this machine (cargo: no such command: clippy)
tests: horizon-client ❌ 1611 passed, 1 failed
doc tests ✅
Parity ➖ not run (--quick); no harness added for this change

The one failing test is game::native_hooks::tests::loot_table_load_stays_hookable. It reads crates/horizon-world/src/loot.rs and looks for the text "\n}\n", which a Windows checkout with CRLF line endings does not contain, so it panics on an unwrap() of None (native_hooks.rs:4215). This change touches only lan_actions.rs. I did not run that test on an unpatched main, so "unrelated" is from reading the test, not from a before/after run. The new tests pass: game::lan_actions::aim_point_tests 6 passed.

Limitations:

  • Not run on a dedicated server or LAN with a remote guest (a remote guest also uses guest_attack, so it takes the same path but this was not tested).
  • A mob whose whole box is hidden is still not hittable (intended).
  • Up to 45 clip_ray calls per attack, only when the centre is hidden.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5903 **Author:** [@repositorykreml1n](https://github.com/repositorykreml1n) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/attack-through-gaps-5772` --- ### 📝 Commits (2) - [`d2e4a36`](https://github.com/horizon-rust/horizon/commit/d2e4a36055c0d37d63bbc2f0884d52bc93a90922) Aim a guest's attack at a visible point of the mob, so hits through a slab or trapdoor gap land - [`97c18d7`](https://github.com/horizon-rust/horizon/commit/97c18d71274c9022f7772cac20f1390b9d00d85d) lan_e2e attack_over_slab: a hit aimed at a zombie's head over a bottom slab lands (#5772) ### 📊 Changes **2 files changed** (+208 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/lan_actions.rs` (+163 -6) 📝 `tools/lan_e2e.py` (+45 -0) </details> ### 📄 Description > 🤖 Opened by repositorykreml1n's AI agent (Claude Code, Sonnet 5.5, with Gemini 3.8 Flash writing part of the code), not by repositorykreml1n personally. ## What and why Fixes #5772 (cannot attack mobs through slabs/trapdoors, which breaks mob farms). Root cause: in single-player the player's attack goes through the integrated server as a guest attack. `guest_attack` (crates/horizon-client/src/game/lan_actions.rs) calls `look_at_entity`, which aimed the swapped-in player at the CENTRE of the target mob, and then `Game::attack()` drops the hit when a block outline is nearer than the mob along that ray (`pick()` vs `mob_hit()`). The attack packet names only the entity, so the server never sees the ray the player's crosshair really used. A mob that the player's own crosshair hits through a gap (top slab, closed top trapdoor, ...) therefore had its centre hidden behind the block and the hit was dropped (the sword swings, no damage, no hurt flash). Fix: for mobs, `look_at_entity` now aims at a VISIBLE point of the mob's box: the centre when it is visible (behaviour unchanged), else the visible point of a 3x5x3 grid of points inside the box nearest to the centre (nearer the eyes on ties), found with `block_between` (a `clip_ray` from the eyes). When the whole box is hidden the centre is kept, so a really blocked hit is still refused as before. Other entity kinds (boats, minecarts, armor stands, frames, paintings, dragon parts) are untouched. `look_at_entity` has only two callers (guest attack, guest interact); the interact path on mobs gets the same visible-point choice. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference No vanilla source was checked in this change; parity was not verified. The expectation is the one in the issue (a mob in a gap that the crosshair hits can be hit). Tests: `game::lan_actions::aim_point_tests` (6 tests of the pure `visible_aim_point`: visible centre kept; a top-slab gap picks a visible point inside the box lower than the centre; a bottom slab picks a point above it; a fully hidden mob keeps the centre; deterministic; an equally near point on the side of the eyes wins). These were written together with the fix, so they were not seen failing; the failing check before the fix is the in-game measurement below. `cargo test -p horizon-client --bin horizon-client aim_point_tests`: 6 passed on d91cab6 + this patch, and 6 passed again on `main` (5edb339a7) + this patch after `rustfmt`. The vanilla jar is not prepared on the author's machine, so `tools/rea_vanilla.py` could not be run; CONTRIBUTING asks for a parity harness for gameplay changes and none was added here, the in-game measurement above is the only check. ## In-game check Windows, single-player, a copy of the reporter's world, official nightly d91cab6 for "before", the same source plus this patch built with the `fast` profile for "after"; a NoAI 1000-hp zombie in a 1x1 cell behind the gap block, real mouse clicks through horizon-ctl, 1 click per aim height, aims at y 70.3/70.9/71.5, the gap block on the open side. The in-game runs were on d91cab6 + this patch (before the `rustfmt` pass, which changed only formatting); the patch was not run in a game on `main`. 54 cases = 3 player feet heights (69, 70, 71) x standing/sneaking x 9 gap blocks (top slab, bottom slab, closed trapdoor bottom half, closed trapdoor top half, open trapdoor, stairs bottom, stairs top, fence, air control). - **Before:** 52 OK, 2 BUG_DROPPED (each 1 of 2 clicks dropped): closed top-half trapdoor standing at feet 69 and top slab sneaking at feet 69. - **After:** 54 OK, 0 dropped. A separate earlier run, sneaking at feet 69 with a top slab, 5 clicks per case, 12 gap blocks: before top slab 0 of 5 hits, after 5 of 5; all other gap blocks hit before and after. These are small samples (1-5 clicks per case), not statistics, and cases where the geometry itself hides the mob are reported as not targetable (correct behaviour), never counted as a drop. ## Self-check `tools/pr_ready.py --base origin/main --quick` on Windows, against origin/main at 5edb339a7 (5 min 59 s): | Check | Result | | --- | --- | | Scope | ✅ 1 file, +163 −6 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed | | rustfmt | ✅ | | clippy | ❌ not run: clippy is not installed on this machine (`cargo: no such command: clippy`) | | tests: horizon-client | ❌ 1611 passed, 1 failed | | doc tests | ✅ | | Parity | ➖ not run (--quick); no harness added for this change | The one failing test is `game::native_hooks::tests::loot_table_load_stays_hookable`. It reads `crates/horizon-world/src/loot.rs` and looks for the text `"\n}\n"`, which a Windows checkout with CRLF line endings does not contain, so it panics on an `unwrap()` of `None` (native_hooks.rs:4215). This change touches only `lan_actions.rs`. I did not run that test on an unpatched `main`, so "unrelated" is from reading the test, not from a before/after run. The new tests pass: `game::lan_actions::aim_point_tests` 6 passed. Limitations: - Not run on a dedicated server or LAN with a remote guest (a remote guest also uses `guest_attack`, so it takes the same path but this was not tested). - A mob whose whole box is hidden is still not hittable (intended). - Up to 45 `clip_ray` calls per attack, only when the centre is hidden. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:22:48 +07:00
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#6551
No description provided.