[PR #4204] [MERGED] Spectating players are hidden from players who aren't spectators #5480

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4204
Author: @d3grando
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3520-spectator-tracking


📝 Commits (1)

  • e445e0e Spectating players are tracked only by other spectators

📊 Changes

5 files changed (+87 additions, -8 deletions)

View changed files

📝 crates/horizon-client/src/game/dragon.rs (+1 -0)
📝 crates/horizon-client/src/game/lan_entities.rs (+1 -0)
📝 crates/horizon-client/src/lan/entity.rs (+74 -4)
📝 crates/horizon-client/src/lan/hub.rs (+10 -4)
📝 crates/horizon-client/tests/lan_bot.rs (+1 -0)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves.

What and why

A player in spectator mode stayed tracked by everyone else. The hub's entity tracker (lan/entity.rs sees, called by Entities::tick from Hub::track_entities) only checked range and chunks. It never asked vanilla's Entity.broadcastToPlayer. Since #3954 a spectator only gets the invisible flag, so the other players still got its AddEntity, its equipment updates and its nametag data. Their crosshair also kept picking it: on main, horizon-ctl looking-at on the host returns the spectating guest's entity. Clients that draw invisible players' armour show it as floating armour and a floating held item.

The fix:

  • EntityState has a new spectator field, and so does Viewer. track_entities fills them in from Guest::spectator() (and from game_mode == 3 for the in-frame host).
  • The pair check now follows ServerPlayer.broadcastToPlayer: a spectator is only paired with viewers who are spectators too. A spectating viewer still sees every player, because a LAN guest's camera is always its own player.
  • When a player goes in or out of spectator mode, its pairs are checked again on that tick, the same way a section change triggers the check. Players who aren't spectators get RemoveEntities for it right away. When it comes back, it is paired again with its armour.

Part of #3520: its ServerPlayer.broadcastToPlayer (missing) and ChunkMap.TrackedEntity.updatePlayers (gap) rows. The issue is a list of port gaps, so it stays open.

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

  • ChunkMap$TrackedEntity.updatePlayer(ServerPlayer): a pair needs range, then entity.broadcastToPlayer(player), then the chunk being tracked.
  • ServerPlayer.broadcastToPlayer(ServerPlayer): if the viewer is a spectator, it returns getCamera() == this. Otherwise it returns !isSpectator() && super.broadcastToPlayer(...). Player and Entity return true.
  • ChunkMap.move(ServerPlayer): runs updatePlayers on the player's own tracked entity and updatePlayer on every other one. Vanilla catches a game-mode change on the player's next move (at most a second later, because of the client's position reminder). Horizon checks the pairs on the tick the mode changes.

I read all of these with javap on the 26.3 jars. No parity harness covers entity tracking. The check is the unit test lan::entity::tests::spectators_are_tracked_only_by_spectators, which follows these steps:

  • Two clients play players 1 and 2. A third player is already spectating.
  • Player 2 starts spectating: client 1 gets RemoveEntities [2], and client 2 still tracks player 1 and the other spectator.
  • Player 2's armour changes: nothing reaches client 1.
  • Player 1 starts spectating too: it sees both spectators.
  • Both go back to survival: they still track each other and lose the third player.

Self-check

tools/pr_ready.py doesn't run on Windows, so I ran its steps by hand:

  • cargo fmt --all -- --check: clean.
  • cargo clippy --profile fast -p horizon-client --all-targets -- -D warnings: clean.
  • cargo test --profile fast -p horizon-client --lib lan::entity::tests::spectators_are_tracked_only_by_spectators
    • Before (the sees check and the re-check on a mode change reverted): FAILED, assertion failed: !c.trackers[0].is_tracking(3) && !c.trackers[1].is_tracking(3).
    • After: ok.
  • cargo test --profile fast -p horizon-client --lib lan::: 59 passed, 0 failed, 1 ignored.
  • cargo test --profile fast -p horizon-client --bin horizon-client game::lan: 11 passed.
  • In game (Windows, server-thread host plus a second game joining as a LAN guest; the guest wears full diamond armour and holds a diamond sword, 4 blocks in front of the host):
    • Before: the guest runs /gamemode spectator. horizon-ctl entities on the host still lists the guest's player entity, and horizon-ctl looking-at on the host returns that entity under the crosshair.
    • After: the host's entities is empty and looking-at is none. The spectating guest still sees the host. When the host spectates too, it sees the guest again. When both go back to creative, the host gets the guest back, armour and sword drawn.

Screenshots

None attached. Horizon's own client already hides a spectating player's model, so a before and after screenshot from Horizon look the same. The change shows in the tracking state, the crosshair target and the packets, which the in-game check above covers. A vanilla client is where the floating armour and held item would show.

🤖 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/4204 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3520-spectator-tracking` --- ### 📝 Commits (1) - [`e445e0e`](https://github.com/horizon-rust/horizon/commit/e445e0edf650a3f7e768415767d012af83b361a9) Spectating players are tracked only by other spectators ### 📊 Changes **5 files changed** (+87 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/dragon.rs` (+1 -0) 📝 `crates/horizon-client/src/game/lan_entities.rs` (+1 -0) 📝 `crates/horizon-client/src/lan/entity.rs` (+74 -4) 📝 `crates/horizon-client/src/lan/hub.rs` (+10 -4) 📝 `crates/horizon-client/tests/lan_bot.rs` (+1 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why A player in spectator mode stayed tracked by everyone else. The hub's entity tracker (`lan/entity.rs` `sees`, called by `Entities::tick` from `Hub::track_entities`) only checked range and chunks. It never asked vanilla's `Entity.broadcastToPlayer`. Since #3954 a spectator only gets the invisible flag, so the other players still got its `AddEntity`, its equipment updates and its nametag data. Their crosshair also kept picking it: on main, `horizon-ctl looking-at` on the host returns the spectating guest's entity. Clients that draw invisible players' armour show it as floating armour and a floating held item. The fix: - `EntityState` has a new `spectator` field, and so does `Viewer`. `track_entities` fills them in from `Guest::spectator()` (and from `game_mode == 3` for the in-frame host). - The pair check now follows `ServerPlayer.broadcastToPlayer`: a spectator is only paired with viewers who are spectators too. A spectating viewer still sees every player, because a LAN guest's camera is always its own player. - When a player goes in or out of spectator mode, its pairs are checked again on that tick, the same way a section change triggers the check. Players who aren't spectators get `RemoveEntities` for it right away. When it comes back, it is paired again with its armour. Part of #3520: its `ServerPlayer.broadcastToPlayer` (missing) and `ChunkMap.TrackedEntity.updatePlayers` (gap) rows. The issue is a list of port gaps, so it stays open. ## Kind - [x] 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 - `ChunkMap$TrackedEntity.updatePlayer(ServerPlayer)`: a pair needs range, then `entity.broadcastToPlayer(player)`, then the chunk being tracked. - `ServerPlayer.broadcastToPlayer(ServerPlayer)`: if the viewer is a spectator, it returns `getCamera() == this`. Otherwise it returns `!isSpectator() && super.broadcastToPlayer(...)`. `Player` and `Entity` return true. - `ChunkMap.move(ServerPlayer)`: runs `updatePlayers` on the player's own tracked entity and `updatePlayer` on every other one. Vanilla catches a game-mode change on the player's next move (at most a second later, because of the client's position reminder). Horizon checks the pairs on the tick the mode changes. I read all of these with javap on the 26.3 jars. No parity harness covers entity tracking. The check is the unit test `lan::entity::tests::spectators_are_tracked_only_by_spectators`, which follows these steps: - Two clients play players 1 and 2. A third player is already spectating. - Player 2 starts spectating: client 1 gets `RemoveEntities [2]`, and client 2 still tracks player 1 and the other spectator. - Player 2's armour changes: nothing reaches client 1. - Player 1 starts spectating too: it sees both spectators. - Both go back to survival: they still track each other and lose the third player. ## Self-check `tools/pr_ready.py` doesn't run on Windows, so I ran its steps by hand: - `cargo fmt --all -- --check`: clean. - `cargo clippy --profile fast -p horizon-client --all-targets -- -D warnings`: clean. - `cargo test --profile fast -p horizon-client --lib lan::entity::tests::spectators_are_tracked_only_by_spectators` - Before (the `sees` check and the re-check on a mode change reverted): FAILED, `assertion failed: !c.trackers[0].is_tracking(3) && !c.trackers[1].is_tracking(3)`. - After: ok. - `cargo test --profile fast -p horizon-client --lib lan::`: 59 passed, 0 failed, 1 ignored. - `cargo test --profile fast -p horizon-client --bin horizon-client game::lan`: 11 passed. - In game (Windows, server-thread host plus a second game joining as a LAN guest; the guest wears full diamond armour and holds a diamond sword, 4 blocks in front of the host): - Before: the guest runs `/gamemode spectator`. `horizon-ctl entities` on the host still lists the guest's player entity, and `horizon-ctl looking-at` on the host returns that entity under the crosshair. - After: the host's `entities` is empty and `looking-at` is `none`. The spectating guest still sees the host. When the host spectates too, it sees the guest again. When both go back to creative, the host gets the guest back, armour and sword drawn. ## Screenshots None attached. Horizon's own client already hides a spectating player's model, so a before and after screenshot from Horizon look the same. The change shows in the tracking state, the crosshair target and the packets, which the in-game check above covers. A vanilla client is where the floating armour and held item would show. 🤖 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 05:12:54 +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#5480
No description provided.