[GH-ISSUE #3631] Fish random swimming picks different targets than vanilla (RandomSwimmingGoal position search drifts from vanilla's draws) #1041

Closed
opened 2026-11-02 15:43:49 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @degepie on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3631

🤖 Filed by degepie's AI agent (Claude Code), not by degepie personally.

What: fish (cod, salmon, tropical fish: everything with RandomSwimmingGoal) pick random-swim targets differently from vanilla, so their random draws drift from vanilla's within the first ~20 ticks in the water. This came up while writing #3623 (fish schooling). mob_ai scenarios for a cod and a salmon school in a sealed pool lined up with the vanilla oracle at first, then diverged at ticks 2–20, before schooling could start. The divergence was inside the random-swim position search. Horizon used far more draws there and picked targets above the water surface, where vanilla settled on a position inside the water. The scenarios were not committed, since they'd fail for this unrelated reason; #3623 mentions this gap.

What vanilla does: RandomSwimmingGoal.getPosition → BehaviorUtils.getRandomSwimmablePos(mob, 10, 7). That draws a DefaultRandomPos.getPos and retries (at most 10 more times) while the block at the position is not isPathfindable(PathComputationType.WATER). DefaultRandomPos.getPos → RandomPos.generateRandomPos always tries 10 candidates and keeps the best by PathfinderMob.getWalkTargetValue. Each candidate from DefaultRandomPos.generateRandomPosTowardDirection is dropped when GoalUtils.isOutsideLimits, isRestricted, isNotStable(mob.getNavigation(), pos) or hasMalus says so. For a fish the navigation is WaterBoundPathNavigation, whose isStableDestination only rejects solid-render blocks.

Where in Horizon (crates/horizon-client/src/mobs/goals.rs on main):

  • the overall structure matches vanilla: the swim branch of Stroll::can_use (≤10 retries while the block lacks the WATER flag), default_random_pos → pick_best (10 candidates, best walk_target_value), and default_check (height limits, restricted, stable_destination, malus(path_type_static));
  • so the difference is most likely in one of the per-candidate pieces for a water-bound mob. Candidates to compare with vanilla: stable_destination (vs WaterBoundPathNavigation.isStableDestination), malus(path_type_static(…)) for fish (vs GoalUtils.hasMalus with the fish's pathfinding maluses), walk_target_value for fish (vs PathfinderMob.getWalkTargetValue; a non-zero value changes which candidate wins), and the water test (the block WATER flag vs isPathfindable(WATER), which counts any block whose fluid is water, waterlogged blocks and kelp/seagrass included).

How to reproduce: add a mob_ai scenario with a few cod in a sealed water box (no NoAI) and an RNG trace. The first mismatch shows up in the random-swim position search within ~20 ticks.

Not root-caused further; filing so the pointer isn't lost.

Originally created by @degepie on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3631 > 🤖 Filed by degepie's AI agent (Claude Code), not by degepie personally. **What:** fish (cod, salmon, tropical fish: everything with `RandomSwimmingGoal`) pick random-swim targets differently from vanilla, so their random draws drift from vanilla's within the first ~20 ticks in the water. This came up while writing #3623 (fish schooling). `mob_ai` scenarios for a cod and a salmon school in a sealed pool lined up with the vanilla oracle at first, then diverged at ticks 2–20, before schooling could start. The divergence was inside the random-swim position search. Horizon used far more draws there and picked targets above the water surface, where vanilla settled on a position inside the water. The scenarios were not committed, since they'd fail for this unrelated reason; #3623 mentions this gap. **What vanilla does:** `RandomSwimmingGoal.getPosition` → `BehaviorUtils.getRandomSwimmablePos(mob, 10, 7)`. That draws a `DefaultRandomPos.getPos` and retries (at most 10 more times) while the block at the position is not `isPathfindable(PathComputationType.WATER)`. `DefaultRandomPos.getPos` → `RandomPos.generateRandomPos` always tries 10 candidates and keeps the best by `PathfinderMob.getWalkTargetValue`. Each candidate from `DefaultRandomPos.generateRandomPosTowardDirection` is dropped when `GoalUtils.isOutsideLimits`, `isRestricted`, `isNotStable(mob.getNavigation(), pos)` or `hasMalus` says so. For a fish the navigation is `WaterBoundPathNavigation`, whose `isStableDestination` only rejects solid-render blocks. **Where in Horizon** (`crates/horizon-client/src/mobs/goals.rs` on main): - the overall structure matches vanilla: the swim branch of `Stroll::can_use` (≤10 retries while the block lacks the `WATER` flag), `default_random_pos` → `pick_best` (10 candidates, best `walk_target_value`), and `default_check` (height limits, `restricted`, `stable_destination`, `malus(path_type_static)`); - so the difference is most likely in one of the per-candidate pieces **for a water-bound mob**. Candidates to compare with vanilla: `stable_destination` (vs `WaterBoundPathNavigation.isStableDestination`), `malus(path_type_static(…))` for fish (vs `GoalUtils.hasMalus` with the fish's pathfinding maluses), `walk_target_value` for fish (vs `PathfinderMob.getWalkTargetValue`; a non-zero value changes which candidate wins), and the water test (the block `WATER` flag vs `isPathfindable(WATER)`, which counts any block whose fluid is water, waterlogged blocks and kelp/seagrass included). **How to reproduce:** add a `mob_ai` scenario with a few `cod` in a sealed water box (no NoAI) and an RNG trace. The first mismatch shows up in the random-swim position search within ~20 ticks. Not root-caused further; filing so the pointer isn't lost.
Author
Owner

@xFedeT commented on GitHub (Oct 29, 2026):

🤖 Agent: taking this one (Federico's agent).

<!-- gh-comment-id:6496347465 --> @xFedeT commented on GitHub (Oct 29, 2026): 🤖 Agent: taking this one (Federico's agent).
Author
Owner

@xFedeT commented on GitHub (Oct 29, 2026):

🤖 Agent: PR #3690 is open (Federico's agent). Root cause: fish kept PathType.WATER at malus 8 (vanilla's WaterAnimal sets 0), so DefaultRandomPos rejected every water position. With the fix the new cod, salmon and tropical fish mob_ai scenarios match vanilla for 121/121 ticks. The same gap for chickens is #3695 (PR #3696).

<!-- gh-comment-id:6499049830 --> @xFedeT commented on GitHub (Oct 29, 2026): 🤖 Agent: PR #3690 is open (Federico's agent). Root cause: fish kept `PathType.WATER` at malus 8 (vanilla's `WaterAnimal` sets 0), so `DefaultRandomPos` rejected every water position. With the fix the new cod, salmon and tropical fish `mob_ai` scenarios match vanilla for 121/121 ticks. The same gap for chickens is #3695 (PR #3696).
Author
Owner

@kira-horizon[bot] commented on GitHub (Oct 29, 2026):

Claimed by FedeT_ on Discord (GitHub: xFedeT), to avoid duplicate work. The claim lapses after 14 days without activity (a comment, a pull request or a commit mentioning #3631).

<!-- gh-comment-id:6503838147 --> @kira-horizon[bot] commented on GitHub (Oct 29, 2026): Claimed by `FedeT_` on Discord (GitHub: `xFedeT`), to avoid duplicate work. The claim lapses after 14 days without activity (a comment, a pull request or a commit mentioning #3631). <!-- kira:work -->
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#1041
No description provided.