[PR #4596] [MERGED] Mobs re-path when a block changes near their route (PathNavigation.shouldRecomputePath) #5719

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4596
Author: @xFedeT
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/path-recompute


📝 Commits (1)

  • 2b85acf Mobs re-path when a block changes near their route (PathNavigation.shouldRecomputePath)

📊 Changes

7 files changed (+121 additions, -3 deletions)

View changed files

📝 crates/horizon-client-render/src/world.rs (+8 -0)
📝 crates/horizon-client/src/game/creatures.rs (+7 -0)
📝 crates/horizon-client/src/mobs.rs (+15 -0)
📝 crates/horizon-client/src/mobs/doors.rs (+1 -1)
📝 crates/horizon-client/src/mobs/nav.rs (+81 -0)
📝 crates/horizon-client/src/mobs/world.rs (+8 -1)
📝 tools/port_map/game-010.tsv (+1 -1)

📄 Description

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

Refs #3521 (row PathNavigation.shouldRecomputePath)

What

A mob kept walking an old path into a wall that was placed on its route, and past a block that was removed. In vanilla ServerLevel.sendBlockUpdated asks every navigating mob whether the change is near its path (PathNavigation.shouldRecomputePath) and has those mobs re-path (recomputePath: at once, or delayed when it re-pathed within 20 ticks). Horizon had recompute_path and its delay flag, but nothing ever called it for a block change.

  • Mob::should_recompute_path(pos) (mobs/nav.rs): vanilla's test. No recompute while one waits; otherwise the end node of what is left of the path, halfway to the mob, and pos.closerToCenterThan(middle, nodes left).
  • World::path_writes (horizon-client-render): every block write (position, old state, new state), kept while the world's mobs tick. tick_creature_entities drains it each tick and mobs::blocks_changed queues a recompute for each mob whose navigation is active, for each write that changed the block's collision shape (Shapes.joinIsNotEmpty(old, new, NOT_SAME); compared by the shapes' bounds here).
  • nav_tick makes the queued recompute at its start, through the existing recompute_path (20 tick throttle, delayed flag).

I read PathNavigation.shouldRecomputePath, recomputePath and ServerLevel.sendBlockUpdated first and compared each condition.

Proof

Real game (horizon-ctl, scratch dirs, a flat stone platform): a pig on a stroll with a path of 6 or more nodes; at that moment I fill a ring of oak planks (3 blocks out, 2 high) around it, across its route. Path length as horizon-ctl mobs shows it, sampled every 2 ticks after the ring:

before this PR (origin/main) with this PR
path nodes 8, 8, 7, 7, 7, 7, 7, 7 0, None, None, None, None, None, None, None
pig keeps walking the old path and stops pushing against the wall at (-0.6, -0.6) drops the path at once (nothing reaches its target through the ring) and stands

(a second run on origin/main ended with path 5 at the wall as well.) I could not frame the pig and the ring in one screenshot: the camera of the session kept moving, so the numbers are the evidence here.

Unit test (recompute_tests): near the middle of the path, too far, behind the mob, a recompute already waiting, a finished path. pr_ready --quick: fmt, clippy, 1681 horizon-client + horizon-client-render tests and 481 Python tests pass.

Notes

  • The recompute starts at the mob's next navigation tick, not inside sendBlockUpdated (the mob lists are taken out for the tick). It is the same tick the vanilla call would act in for any mob that has not ticked yet, one tick later for those that have.
  • Not covered by mob_ai: the probe never writes blocks. The door scenarios of #4518 still diverge for the other reason described there (the door the mob opens is applied after its tick), which this does not change.

🤖 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/4596 **Author:** [@xFedeT](https://github.com/xFedeT) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/path-recompute` --- ### 📝 Commits (1) - [`2b85acf`](https://github.com/horizon-rust/horizon/commit/2b85acfeafc8825e7e94c851175cd0c355554f85) Mobs re-path when a block changes near their route (PathNavigation.shouldRecomputePath) ### 📊 Changes **7 files changed** (+121 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/world.rs` (+8 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+7 -0) 📝 `crates/horizon-client/src/mobs.rs` (+15 -0) 📝 `crates/horizon-client/src/mobs/doors.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/nav.rs` (+81 -0) 📝 `crates/horizon-client/src/mobs/world.rs` (+8 -1) 📝 `tools/port_map/game-010.tsv` (+1 -1) </details> ### 📄 Description > 🤖 Opened by xFedeT's AI agent (Claude Code, Sonnet 5.5), not by xFedeT personally. Refs #3521 (row `PathNavigation.shouldRecomputePath`) ## What A mob kept walking an old path into a wall that was placed on its route, and past a block that was removed. In vanilla `ServerLevel.sendBlockUpdated` asks every navigating mob whether the change is near its path (`PathNavigation.shouldRecomputePath`) and has those mobs re-path (`recomputePath`: at once, or delayed when it re-pathed within 20 ticks). Horizon had `recompute_path` and its delay flag, but nothing ever called it for a block change. - `Mob::should_recompute_path(pos)` (`mobs/nav.rs`): vanilla's test. No recompute while one waits; otherwise the end node of what is left of the path, halfway to the mob, and `pos.closerToCenterThan(middle, nodes left)`. - `World::path_writes` (`horizon-client-render`): every block write (position, old state, new state), kept while the world's mobs tick. `tick_creature_entities` drains it each tick and `mobs::blocks_changed` queues a recompute for each mob whose navigation is active, for each write that changed the block's **collision shape** (`Shapes.joinIsNotEmpty(old, new, NOT_SAME)`; compared by the shapes' bounds here). - `nav_tick` makes the queued recompute at its start, through the existing `recompute_path` (20 tick throttle, delayed flag). I read `PathNavigation.shouldRecomputePath`, `recomputePath` and `ServerLevel.sendBlockUpdated` first and compared each condition. ## Proof Real game (`horizon-ctl`, scratch dirs, a flat stone platform): a pig on a stroll with a path of 6 or more nodes; at that moment I fill a ring of oak planks (3 blocks out, 2 high) around it, across its route. Path length as `horizon-ctl mobs` shows it, sampled every 2 ticks after the ring: | | before this PR (`origin/main`) | with this PR | |---|---|---| | path nodes | `8, 8, 7, 7, 7, 7, 7, 7` | `0, None, None, None, None, None, None, None` | | pig | keeps walking the old path and stops pushing against the wall at (-0.6, -0.6) | drops the path at once (nothing reaches its target through the ring) and stands | (a second run on `origin/main` ended with `path 5` at the wall as well.) I could not frame the pig and the ring in one screenshot: the camera of the session kept moving, so the numbers are the evidence here. Unit test (`recompute_tests`): near the middle of the path, too far, behind the mob, a recompute already waiting, a finished path. `pr_ready --quick`: fmt, clippy, 1681 `horizon-client` + `horizon-client-render` tests and 481 Python tests pass. ## Notes - The recompute starts at the mob's next navigation tick, not inside `sendBlockUpdated` (the mob lists are taken out for the tick). It is the same tick the vanilla call would act in for any mob that has not ticked yet, one tick later for those that have. - Not covered by `mob_ai`: the probe never writes blocks. The door scenarios of #4518 still diverge for the other reason described there (the door the mob opens is applied after its tick), which this does not change. 🤖 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:14:31 +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#5719
No description provided.