[PR #4938] [MERGED] Phantoms target only a player they can see (#4929) #5956

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4938
Author: @k3yh
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/phantom-line-of-sight


📝 Commits (1)

  • b4da901 Phantoms target only a player they can see (#4929)

📊 Changes

3 files changed (+122 additions, -37 deletions)

View changed files

📝 crates/horizon-client/src/mobs/ai.rs (+1 -33)
📝 crates/horizon-client/src/mobs/phantom.rs (+71 -3)
📝 crates/horizon-client/src/mobs/world.rs (+50 -1)

📄 Description

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

What and why

Fixes #4929.

In vanilla 26.3, three phantom checks call Phantom.canAttack(level, player, TargetingConditions.DEFAULT):

  • PhantomAttackPlayerTargetGoal.canUse, for each player in the box,
  • PhantomAttackPlayerTargetGoal.canContinueToUse,
  • PhantomAttackStrategyGoal.canUse.

DEFAULT is forCombat(), and its test ends with Sensing.hasLineOfSight unless the conditions call ignoreLineOfSight(). I read this in the shipped 26.3 bytecode with javap: the constructor sets checkLineOfSight = true. So a phantom only takes a player it can see, and drops one it can no longer see.

Horizon's can_attack only checked that the player is alive, not creative and not a spectator. So a phantom took a player under a roof, through glass or boxed in, and kept swooping at it, as the report says.

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

Change

  • phantom.rs: can_attack_seen is can_attack and m.sees(w, Who::Player), the existing per-tick Sensing cache over ClipContext.Block.COLLIDER. The three checks above use it.
  • PhantomSweepAttackGoal.canContinueToUse keeps the plain check. Vanilla checks alive, spectator, creative and canUse there, with no sight test.
  • Test support:
    • mobs::world::with_built_test_world is with_test_world with a closure that places blocks first. with_test_world calls it with nothing to place.
    • The fox test's PlayerView builder moved to a shared test_player.

Vanilla reference

  • Phantom$PhantomAttackPlayerTargetGoal.canUse and canContinueToUse.
  • Phantom$PhantomAttackStrategyGoal.canUse.
  • Phantom$PhantomSweepAttackGoal.canContinueToUse.
  • Phantom.canAttack(ServerLevel, LivingEntity, TargetingConditions).
  • TargetingConditions.DEFAULT, forCombat, test.
  • Sensing.hasLineOfSight.

Test

mobs::phantom::tests::a_phantom_cannot_target_a_player_it_cannot_see:

  • Setup: a phantom 16 blocks above a player, with no box, a hollow stone box or a hollow glass box around the player.
  • With no box, the target goal takes the player and keeps them.
  • In either box, it does neither.
  • With the sight check removed, the test fails on the stone box.

In game (single player, survival, night, Resistance on the player, this branch):

  • The player was enclosed in a hollow stone box (fill … stone hollow), and a phantom was summoned 25 blocks up.
  • I polled the phantom's goals, target and position with horizon-ctl mobs every 3 s.
45 s boxed in after the box's roof is removed
nightly 2026-10-30 (1da354b) takes the player at 3 s, then swoops into the box walls again and again (AttackStrategy, SweepAttack, down to y 72 beside the box) not run
this branch never takes the player: CircleAroundAnchor only, 95 to 100 blocks up takes the player within 3 s and swoops (AttackStrategy, SweepAttack)

Not checked: a dedicated server or LAN guest, though the AI is the same code. Not checked either: more than one player in range. Horizon's target goal reads the one w.player, which is unchanged here.

Overlap

#4539 (kacpherek's parity batch) also edits phantom.rs. It adds set_size just above can_attack, while this PR adds can_attack_seen just below it. The two changes don't depend on each other.

A test merge (git merge-tree) of this branch with #4539's head merges phantom.rs cleanly. Its list of conflicting files (game/lan.rs, remote_mob_data.rs, mobs/ai.rs, fox.rs, frog.rs, piglin.rs, level/interact.rs) is exactly the list #4539 already has against main, so this PR adds no conflict of its own.

Self-check

pr_ready (tools/pr_ready.py --quick --base 480f6b3d1 on DESKTOP-S9O4938, against 480f6b3d1 at 480f6b3d1, 5 min 32 s)

Check Result
Scope ✅ 3 files, +122 −37
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 486 run, FAILED (errors=2, skipped=1) (50 s)
rustfmt ✅ (7 s)
Rust ⚠️ 1.98.1 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with rustup update
clippy ❌ failed; likely the old Rust above (28 s)
tests: horizon-client ❌ 906 passed, 1 failed (4 min 3 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

None of the failures is in code this PR touches:

  • clippy stopped on horizon-threads/src/lib.rs:438 (useless_vec, a test on main), before it reached horizon-client. My Rust (1.98.1) is older than CI's. cargo clippy -p horizon-client --lib --tests -- -D warnings on this branch is clean.
  • The other three also failed on main (3dc5b432f) on this machine:
    • motion::tests::a_swimming_passenger_sits_up_even_when_standing_does_not_fit
    • test_port_ledger, which cannot import tests.test_class_index
    • test_perf_bench, whose windows_version() gets nothing from cmd /C ver on a Spanish Windows

🤖 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/4938 **Author:** [@k3yh](https://github.com/k3yh) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/phantom-line-of-sight` --- ### 📝 Commits (1) - [`b4da901`](https://github.com/horizon-rust/horizon/commit/b4da90182fe9acd9ea5d57db8e25e3c4281b6da5) Phantoms target only a player they can see (#4929) ### 📊 Changes **3 files changed** (+122 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/ai.rs` (+1 -33) 📝 `crates/horizon-client/src/mobs/phantom.rs` (+71 -3) 📝 `crates/horizon-client/src/mobs/world.rs` (+50 -1) </details> ### 📄 Description > 🤖 Opened by k3yh's AI agent (Claude Code, Claude Opus 5.5), not by k3yh personally. ## What and why Fixes #4929. In vanilla 26.3, three phantom checks call `Phantom.canAttack(level, player, TargetingConditions.DEFAULT)`: - `PhantomAttackPlayerTargetGoal.canUse`, for each player in the box, - `PhantomAttackPlayerTargetGoal.canContinueToUse`, - `PhantomAttackStrategyGoal.canUse`. `DEFAULT` is `forCombat()`, and its `test` ends with `Sensing.hasLineOfSight` unless the conditions call `ignoreLineOfSight()`. I read this in the shipped 26.3 bytecode with `javap`: the constructor sets `checkLineOfSight = true`. So a phantom only takes a player it can see, and drops one it can no longer see. Horizon's `can_attack` only checked that the player is alive, not creative and not a spectator. So a phantom took a player under a roof, through glass or boxed in, and kept swooping at it, as the report says. ## 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 ## Change - `phantom.rs`: `can_attack_seen` is `can_attack` and `m.sees(w, Who::Player)`, the existing per-tick `Sensing` cache over `ClipContext.Block.COLLIDER`. The three checks above use it. - `PhantomSweepAttackGoal.canContinueToUse` keeps the plain check. Vanilla checks alive, spectator, creative and `canUse` there, with no sight test. - Test support: - `mobs::world::with_built_test_world` is `with_test_world` with a closure that places blocks first. `with_test_world` calls it with nothing to place. - The fox test's `PlayerView` builder moved to a shared `test_player`. ## Vanilla reference - `Phantom$PhantomAttackPlayerTargetGoal.canUse` and `canContinueToUse`. - `Phantom$PhantomAttackStrategyGoal.canUse`. - `Phantom$PhantomSweepAttackGoal.canContinueToUse`. - `Phantom.canAttack(ServerLevel, LivingEntity, TargetingConditions)`. - `TargetingConditions.DEFAULT`, `forCombat`, `test`. - `Sensing.hasLineOfSight`. ## Test `mobs::phantom::tests::a_phantom_cannot_target_a_player_it_cannot_see`: - Setup: a phantom 16 blocks above a player, with no box, a hollow stone box or a hollow glass box around the player. - With no box, the target goal takes the player and keeps them. - In either box, it does neither. - With the sight check removed, the test fails on the stone box. **In game** (single player, survival, night, Resistance on the player, this branch): - The player was enclosed in a hollow stone box (`fill … stone hollow`), and a phantom was summoned 25 blocks up. - I polled the phantom's goals, target and position with `horizon-ctl mobs` every 3 s. | | 45 s boxed in | after the box's roof is removed | |---|---|---| | nightly 2026-10-30 (1da354b) | takes the player at 3 s, then swoops into the box walls again and again (`AttackStrategy, SweepAttack`, down to y 72 beside the box) | not run | | this branch | never takes the player: `CircleAroundAnchor` only, 95 to 100 blocks up | takes the player within 3 s and swoops (`AttackStrategy, SweepAttack`) | Not checked: a dedicated server or LAN guest, though the AI is the same code. Not checked either: more than one player in range. Horizon's target goal reads the one `w.player`, which is unchanged here. ## Overlap #4539 (kacpherek's parity batch) also edits `phantom.rs`. It adds `set_size` just above `can_attack`, while this PR adds `can_attack_seen` just below it. The two changes don't depend on each other. A test merge (`git merge-tree`) of this branch with #4539's head merges `phantom.rs` cleanly. Its list of conflicting files (`game/lan.rs`, `remote_mob_data.rs`, `mobs/ai.rs`, `fox.rs`, `frog.rs`, `piglin.rs`, `level/interact.rs`) is exactly the list #4539 already has against main, so this PR adds no conflict of its own. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base 480f6b3d1` on DESKTOP-S9O4938, against 480f6b3d1 at 480f6b3d1, 5 min 32 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +122 −37 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 486 run, FAILED (errors=2, skipped=1) (50 s) | | rustfmt | ✅ (7 s) | | Rust | ⚠️ 1.98.1 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with `rustup update` | | clippy | ❌ failed; likely the old Rust above (28 s) | | tests: horizon-client | ❌ 906 passed, 1 failed (4 min 3 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | None of the failures is in code this PR touches: - clippy stopped on `horizon-threads/src/lib.rs:438` (`useless_vec`, a test on main), before it reached `horizon-client`. My Rust (1.98.1) is older than CI's. `cargo clippy -p horizon-client --lib --tests -- -D warnings` on this branch is clean. - The other three also failed on main (3dc5b432f) on this machine: - `motion::tests::a_swimming_passenger_sits_up_even_when_standing_does_not_fit` - `test_port_ledger`, which cannot import `tests.test_class_index` - `test_perf_bench`, whose `windows_version()` gets nothing from `cmd /C ver` on a Spanish Windows 🤖 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:16:12 +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#5956
No description provided.