[PR #4891] [MERGED] Server: an Interact packet's entity is the entity it clicks #5922

Closed
opened 2026-11-03 05:15:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4891
Author: @sirrayi
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fix/interact-packet-target


📝 Commits (7)

  • 70bf1af Server: an Interact packet's entity is the entity it clicks
  • c1a49d5 Server: the interact packet's entity keeps the crosshair pick's filters
  • 44c54ba rustfmt creatures.rs
  • 16ed874 Merge main into #4891
  • d9429e6 Merge main into #4891 again, for 825a6bbcf
  • 5c766a6 The knot comment says why a packet does not reach a knot
  • 8ec8448 Merge main into #4891 once more, for #5148's machine-menu test

📊 Changes

8 files changed (+194 additions, -54 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+85 -21)
📝 crates/horizon-client/src/game/armor_stands.rs (+23 -5)
📝 crates/horizon-client/src/game/boats.rs (+10 -5)
📝 crates/horizon-client/src/game/creatures.rs (+35 -5)
📝 crates/horizon-client/src/game/cushions.rs (+12 -5)
📝 crates/horizon-client/src/game/frames.rs (+10 -5)
📝 crates/horizon-client/src/game/lan_actions.rs (+9 -3)
📝 crates/horizon-client/src/game/minecarts.rs (+10 -5)

📄 Description

🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi themselves.

What and why

Fixes #4651. ServerGamePacketListenerImpl.handleInteract resolves packet.entityId() once, checks that
entity and the range, and hands that same entity to Player.interactOn. Horizon aimed the guest at the
named entity with look_at_entity and then let the interaction helpers pick a target again from the view,
so a mob that moved between the eye and the clicked one took the click, and a block in the way stopped an
interaction the packet had already validated.

GuestUse::Entity(Hand) becomes GuestUse::Entity(Hand, InteractTarget), where InteractTarget is the
packet's entity id and its location, and interact_entity(target) passes it to every helper
(interact_frame, interact_armor_stand, interact_cushion, interact_boat, interact_cart,
interact_mob). Each helper looks the entity up by id (Level.getEntity(id)) when the packet named one
and otherwise keeps picking from the crosshair, so:

  • the local player's behaviour is untouched — Minecraft.hitResult really is a ray pick;
  • the block-in-front and distance checks stay for the local pick and are skipped only where the packet has
    already passed handleInteract's own range check;
  • an id the level does not hold interacts with nothing, as handleInteract finds nothing then;
  • a knot stays crosshair-only for now. A knot is a block to the crosshair pick, but a server also
    tracks one as an entity (knot_ids, game/lan_entities.rs, a LeashFenceKnotEntity), so a guest's
    Interact naming a knot's id is dropped here. That is a known gap rather than a regression: nothing
    resolved knot ids before this PR either.

The range validation in the S::Interact arm is unchanged, and no packet format changes.

What the vanilla claim rests on — read this bit

I want to be explicit about the evidence grade, because it is weaker here than in my other pull requests and
a reviewer should know before spending time.

  • There is no ledger row for ServerGamePacketListenerImpl.handleInteract or Player.interactOn, and no
    Vanilla*Oracle covers them: grep -rn handleInteract tools/port_map/ mods/ finds nothing. So unlike the
    swimming change I opened today, there is no in-repo, harness-backed statement of what vanilla does. My
    claim rests on the issue's citation of the method and on its shape.
  • The id half is conservative. Using packet.entityId() for the entity that receives the click cannot
    make Horizon do anything vanilla does not: at worst it is the same entity the ray pick would have chosen.
  • The one decision that could go either way is the block-in-front check. interact_frame and
    interact_mob both refuse an interaction when a block sits between the eye and the target; I skip that
    check when the packet named the entity, on the reading that handleInteract range-checks the entity and
    does not ray-pick. If a maintainer reads handleInteract and finds a line-of-sight rejection I have
    missed, the fix is to drop the two target.is_none() && conditions
    — the rest of the change (the id
    resolution, the unknown-id case, the knot staying crosshair-only) stands on its own and would remain
    correct. That is a two-word edit, not a redesign.

The test also cannot be red on main, since named_entity and InteractTarget do not exist there; it pins
the selection rule going forward.

Kind

  • bug: a crash or a breakage

Vanilla reference

ServerGamePacketListenerImpl.handleInteract (resolve entityId(), isWithinRange, then
Player.interactOn(entity, hand)) and Level.getEntity(id). The local path keeps mirroring
Minecraft.hitResult/GameRenderer.pick.

New test game::tests::an_interact_packet_clicks_the_entity_it_names_not_the_nearest: two mobs at
different distances, the packet naming the farther one, the id lookup selecting it; the near one still
selectable when that is the one named; an unknown id selecting nothing.

What it does not cover, and a maintainer should know: it proves the id-driven selection, not a full
two-mob world with a packet in flight — that needs a LanHost and a real chunk, which no unit test here
builds. The reach, block-in-front and pose paths around it are exercised by lan_e2e.py's
interact/clicks checks on CI, which is where a regression of this change would show.

Self-check

cargo fmt --all -- --check                                                    ✅
cargo clippy --workspace --all-targets -- -D warnings                         ✅
cargo clippy -p horizon-client --all-targets --no-default-features -- -D warnings  ✅
cargo test -p horizon-client --bins an_interact_packet                        2 passed; 0 failed

Both tests pass, an_interact_packet_clicks_the_entity_it_names_not_the_nearest and
an_interact_packet_cannot_name_a_mob_the_pick_would_refuse (the by-id filter dimaniojk's review asked
for). The workspace clippy is the full CI shape, --all-targets included, so the red clippy/tests/verify
runs on the previous head are covered.

Those three red checks were not this PR. clippy, tests and verify failed at 44c54ba8b on
crates/horizon-client-render/src/audio.rs:1051 — a share() initializer missing cards_seen,
default_seen and device_ticks, which is main's splitscreen-audio change arriving under this branch's
older base. Main fixed it in f80c0360d ("Main builds again: a splitscreen share has the device tracker's
fields"); that file is not one of this PR's eight.

A second red run was coming for the same reason. 16ed874da merged 06485bfef, ten commits behind main,
and that point still has the duplicate S::Attack arm in Hub::process_inbox that 825a6bbcf removed —
unreachable, so clippy -D warnings fails. Current main is merged in (b8cf85f8c) on top of that merge,
so the branch now has one arm and builds; nothing this PR changes was resolved by hand in either merge.

python3 tools/pr_ready.py was not finished here: this machine has no prepared vanilla data
(.local/), so its harness half only lists what CI must run, and its workspace-wide passes compete for the
build cache with other work on the machine. CI's verify runs the workspace fmt/clippy/tests.

Screenshots

Not a visual change: it is which entity receives a click. A repro needs two mobs, one behind the other,
and a delayed packet; I have no prepared resources on this machine to film it.


🔄 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/4891 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/interact-packet-target` --- ### 📝 Commits (7) - [`70bf1af`](https://github.com/horizon-rust/horizon/commit/70bf1afb05d6613b1877d5cfbfe1ce113f23a4a2) Server: an Interact packet's entity is the entity it clicks - [`c1a49d5`](https://github.com/horizon-rust/horizon/commit/c1a49d50e6e547c766bae702d957545efabc5b2a) Server: the interact packet's entity keeps the crosshair pick's filters - [`44c54ba`](https://github.com/horizon-rust/horizon/commit/44c54ba8b83b2254969a9a87d45c387ca44500d9) rustfmt creatures.rs - [`16ed874`](https://github.com/horizon-rust/horizon/commit/16ed874dadf47dc59911235b3174d711b230a72c) Merge main into #4891 - [`d9429e6`](https://github.com/horizon-rust/horizon/commit/d9429e673118df1d6747fdce60d6b6ddb80165b6) Merge main into #4891 again, for 825a6bbcf - [`5c766a6`](https://github.com/horizon-rust/horizon/commit/5c766a673cf0efb36b73be7e822dc369740721b7) The knot comment says why a packet does not reach a knot - [`8ec8448`](https://github.com/horizon-rust/horizon/commit/8ec84484b55a409b150fc82be2d99d9bc4e933bd) Merge main into #4891 once more, for #5148's machine-menu test ### 📊 Changes **8 files changed** (+194 additions, -54 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+85 -21) 📝 `crates/horizon-client/src/game/armor_stands.rs` (+23 -5) 📝 `crates/horizon-client/src/game/boats.rs` (+10 -5) 📝 `crates/horizon-client/src/game/creatures.rs` (+35 -5) 📝 `crates/horizon-client/src/game/cushions.rs` (+12 -5) 📝 `crates/horizon-client/src/game/frames.rs` (+10 -5) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+9 -3) 📝 `crates/horizon-client/src/game/minecarts.rs` (+10 -5) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi themselves. ## What and why Fixes #4651. `ServerGamePacketListenerImpl.handleInteract` resolves `packet.entityId()` once, checks that entity and the range, and hands **that same entity** to `Player.interactOn`. Horizon aimed the guest at the named entity with `look_at_entity` and then let the interaction helpers pick a target again from the view, so a mob that moved between the eye and the clicked one took the click, and a block in the way stopped an interaction the packet had already validated. `GuestUse::Entity(Hand)` becomes `GuestUse::Entity(Hand, InteractTarget)`, where `InteractTarget` is the packet's entity id and its location, and `interact_entity(target)` passes it to every helper (`interact_frame`, `interact_armor_stand`, `interact_cushion`, `interact_boat`, `interact_cart`, `interact_mob`). Each helper looks the entity up by id (`Level.getEntity(id)`) when the packet named one and otherwise keeps picking from the crosshair, so: - the local player's behaviour is untouched — `Minecraft.hitResult` really is a ray pick; - the block-in-front and distance checks stay for the local pick and are skipped only where the packet has already passed `handleInteract`'s own range check; - an id the level does not hold interacts with nothing, as `handleInteract` finds nothing then; - a knot stays crosshair-only for now. A knot is a block to the crosshair pick, but a server also tracks one as an entity (`knot_ids`, `game/lan_entities.rs`, a `LeashFenceKnotEntity`), so a guest's Interact naming a knot's id is dropped here. That is a known gap rather than a regression: nothing resolved knot ids before this PR either. The range validation in the `S::Interact` arm is unchanged, and no packet format changes. ## What the vanilla claim rests on — read this bit I want to be explicit about the evidence grade, because it is weaker here than in my other pull requests and a reviewer should know before spending time. - **There is no ledger row for `ServerGamePacketListenerImpl.handleInteract` or `Player.interactOn`**, and no `Vanilla*Oracle` covers them: `grep -rn handleInteract tools/port_map/ mods/` finds nothing. So unlike the swimming change I opened today, there is no in-repo, harness-backed statement of what vanilla does. My claim rests on the issue's citation of the method and on its shape. - **The id half is conservative.** Using `packet.entityId()` for the entity that receives the click cannot make Horizon do anything vanilla does not: at worst it is the same entity the ray pick would have chosen. - **The one decision that could go either way** is the block-in-front check. `interact_frame` and `interact_mob` both refuse an interaction when a block sits between the eye and the target; I skip that check when the packet named the entity, on the reading that `handleInteract` range-checks the entity and does not ray-pick. **If a maintainer reads `handleInteract` and finds a line-of-sight rejection I have missed, the fix is to drop the two `target.is_none() &&` conditions** — the rest of the change (the id resolution, the unknown-id case, the knot staying crosshair-only) stands on its own and would remain correct. That is a two-word edit, not a redesign. The test also cannot be red on `main`, since `named_entity` and `InteractTarget` do not exist there; it pins the selection rule going forward. ## Kind - [x] bug: a crash or a breakage ## Vanilla reference `ServerGamePacketListenerImpl.handleInteract` (resolve `entityId()`, `isWithinRange`, then `Player.interactOn(entity, hand)`) and `Level.getEntity(id)`. The local path keeps mirroring `Minecraft.hitResult`/`GameRenderer.pick`. New test `game::tests::an_interact_packet_clicks_the_entity_it_names_not_the_nearest`: two mobs at different distances, the packet naming the farther one, the id lookup selecting it; the near one still selectable when that is the one named; an unknown id selecting nothing. What it does not cover, and a maintainer should know: it proves the id-driven selection, not a full two-mob world with a packet in flight — that needs a `LanHost` and a real chunk, which no unit test here builds. The reach, block-in-front and pose paths around it are exercised by `lan_e2e.py`'s `interact`/`clicks` checks on CI, which is where a regression of this change would show. ## Self-check ``` cargo fmt --all -- --check ✅ cargo clippy --workspace --all-targets -- -D warnings ✅ cargo clippy -p horizon-client --all-targets --no-default-features -- -D warnings ✅ cargo test -p horizon-client --bins an_interact_packet 2 passed; 0 failed ``` Both tests pass, `an_interact_packet_clicks_the_entity_it_names_not_the_nearest` and `an_interact_packet_cannot_name_a_mob_the_pick_would_refuse` (the by-id filter dimaniojk's review asked for). The workspace clippy is the full CI shape, `--all-targets` included, so the red `clippy`/`tests`/`verify` runs on the previous head are covered. **Those three red checks were not this PR.** `clippy`, `tests` and `verify` failed at `44c54ba8b` on `crates/horizon-client-render/src/audio.rs:1051` — a `share()` initializer missing `cards_seen`, `default_seen` and `device_ticks`, which is main's splitscreen-audio change arriving under this branch's older base. Main fixed it in `f80c0360d` ("Main builds again: a splitscreen share has the device tracker's fields"); that file is not one of this PR's eight. A second red run was coming for the same reason. `16ed874da` merged `06485bfef`, ten commits behind main, and that point still has the duplicate `S::Attack` arm in `Hub::process_inbox` that `825a6bbcf` removed — unreachable, so `clippy -D warnings` fails. Current main is merged in (`b8cf85f8c`) on top of that merge, so the branch now has one arm and builds; nothing this PR changes was resolved by hand in either merge. `python3 tools/pr_ready.py` was not finished here: this machine has no prepared vanilla data (`.local/`), so its harness half only lists what CI must run, and its workspace-wide passes compete for the build cache with other work on the machine. CI's `verify` runs the workspace fmt/clippy/tests. ## Screenshots Not a visual change: it is which entity receives a click. A repro needs two mobs, one behind the other, and a delayed packet; I have no prepared resources on this machine to film it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:15:56 +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#5922
No description provided.