[PR #3623] [MERGED] Fish form schools: port FollowFlockLeaderGoal (#3026) #5100

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

📋 Pull Request Information

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

Base: main ← Head: fix/issue-3026-fish-schools


📝 Commits (1)

  • 35345be Fish form schools: port FollowFlockLeaderGoal (#3026)

📊 Changes

4 files changed (+275 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+2 -0)
📝 crates/horizon-client/src/mobs.rs (+26 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+1 -0)
📝 crates/horizon-client/src/mobs/aquatic.rs (+246 -2)

📄 Description

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

Fixes #3026.

What

Cod, salmon and tropical fish never formed schools: Horizon gave them only panic, player avoidance and random swimming. Vanilla also gives them FollowFlockLeaderGoal, so they gather around a leader and follow it. This PR ports that goal and the AbstractSchoolingFish state it relies on.

Vanilla

  • AbstractSchoolingFish.registerGoals adds FollowFlockLeaderGoal at priority 5 (it sets no flags). canRandomSwim is false while the fish follows a live leader, which turns off AbstractFish.FishSwimGoal. That gate is checked before RandomSwimmingGoal.canUse draws its interval roll.
  • FollowFlockLeaderGoal: a leader with followers never uses the goal, and a follower always does. Any other fish counts down a start delay first: reducedTickDelay(200 + nextInt(200) % 20), i.e. 100–110 ticks, drawn on the fish's own random in the constructor and again on every attempt. When the delay runs out, it lists the fish of its own class whose boxes meet its box inflated by 8 and that either lead a school with room (canBeFollowed) or follow no one. It picks the first school with room as the leader, or else leads itself. The leader then recruits fish from that list that follow no one. The cap is getMaxSchoolSize - schoolSize, applied before the leader itself is skipped. A follower re-paths to its leader every adjustedTickDelay(10) ticks and leaves the school when the leader dies or is more than 11 blocks away (distanceToSqr > 121).
  • schoolSize starts at 1. startFollowing/stopFollowing add one to it or take one away. canBeFollowed = schoolSize > 1 && schoolSize < max. AbstractSchoolingFish.tick (after super.tick) rolls nextInt(200) == 1 on the level random once a tick while the fish has followers. On a hit, it resets the school to 1 if no other fish of its class is within 8 blocks.
  • getMaxSchoolSize: 8 for cod and tropical fish (AbstractFish.getMaxSpawnClusterSize; TropicalFish has no override), 5 for salmon (Salmon.getMaxSchoolSize).

How

  • mobs/aquatic.rs: FollowFlockLeader (named FollowFlockLeaderGoal), a FishSwim wrapper around the existing swimming Stroll that adds the canRandomSwim gate, and school_tick for the 1-in-200 reset. Pufferfish keep their goals as before.
  • mobs.rs: Extra.followers holds schoolSize - 1, and Seen.school gives other fish (leader, followers). A goal can't change other mobs directly, so recruiting goes through two new MobEvents, StartFollowing and SchoolSize. apply_brain_events applies them right after the recruiting fish's tick, the same way BreedTarget is handled.
  • mobs/ai.rs: one call to school_tick at the end of the living tick, next to the bee and panda hooks.
  • game/creatures.rs: one no-op match arm for the two events, which have already been applied by then.

Verified

  • In game (scratch home, creative, a sealed 20×5×20 water box, 8 summon cod in two rows of four 5 blocks apart, the rows 12 blocks apart; entities sampled every second for 80–90 s). Clusters = groups of cod linked within 4 blocks:

    build clusters, t ≥ 40 s (avg) clusters at end
    v0.2.91 7.3 7
    main 6.5 6
    this PR 2.1 2

    With the fix, the cod drop to 3 clusters by 20 s and to 2 by 50 s, and stay there. Main and v0.2.91 stay at 6–8 clusters the whole time. Mean pairwise distance hardly changes (about 12 m on all three builds) because the two schools stay apart: the rows are 12 blocks apart, farther than the 8-block recruit range.

  • Unit tests mobs::aquatic::school_tests: school sizes and canBeFollowed, the start-delay range, and a recruit that another leader already took this tick staying with that leader.

  • mob_ai harness: axolotl_hunting (it has a no-AI cod) still matches all 46 ticks. finalize_spawn, natural_spawn and spawner pass: fish now draw from their random once at construction, as vanilla's goal constructor does.

Known differences

  • Mobs see each other through the per-tick snapshot. If a fish ticks after a recruiter but before the fish it recruited, it still sees the recruit as free. start_following refuses to move a fish that already follows a live leader, so school counts stay consistent. In vanilla the second recruiter would have skipped that fish to begin with. This only matters when two start delays end in the same tick.
  • Dying fish (health 0, not yet removed) are left out of the neighbour lists. Vanilla's getEntitiesOfClass still counts them.
  • Spawn groups (SchoolSpawnGroupData in finalize.rs) set a follower's leader without adding to the leader's schoolSize. That path only runs from structure mobs and the finalize fixture; natural spawning doesn't pass group data.
  • No new parity scenario. I tried cod_school and salmon_school in the mob_ai harness, with the oracle drawing the goal's start delay again after seeding. The RNG matched at first, but the run diverged at ticks 2–20, before schooling can start: Horizon's RandomSwimmingGoal position search uses all its attempts (332 draws) where vanilla stops early, and picks targets above the pool. That's a separate existing gap, so I left the scenarios out.

pr_ready

pr_ready (tools/pr_ready.py --quick on horizon-build, against origin/main at 77bfff8eb, 6 min 16 s)

Check Result
Scope ✅ 4 files, +275 −2
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 408 passed (29 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 55 s)
tests: horizon-client ✅ 802 passed (3 min 23 s)
doc tests ✅ 0 passed (20 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 ➖ 347 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 335 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/3623 **Author:** [@degepie](https://github.com/degepie) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix/issue-3026-fish-schools` --- ### 📝 Commits (1) - [`35345be`](https://github.com/horizon-rust/horizon/commit/35345be1026e83d86f1652e99eb44ea4e13a09fa) Fish form schools: port FollowFlockLeaderGoal (#3026) ### 📊 Changes **4 files changed** (+275 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+2 -0) 📝 `crates/horizon-client/src/mobs.rs` (+26 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+1 -0) 📝 `crates/horizon-client/src/mobs/aquatic.rs` (+246 -2) </details> ### 📄 Description > 🤖 Opened by degepie's AI agent (Claude Code), not by degepie personally. Fixes #3026. ## What Cod, salmon and tropical fish never formed schools: Horizon gave them only panic, player avoidance and random swimming. Vanilla also gives them `FollowFlockLeaderGoal`, so they gather around a leader and follow it. This PR ports that goal and the `AbstractSchoolingFish` state it relies on. ## Vanilla - `AbstractSchoolingFish.registerGoals` adds `FollowFlockLeaderGoal` at priority 5 (it sets no flags). `canRandomSwim` is false while the fish follows a live leader, which turns off `AbstractFish.FishSwimGoal`. That gate is checked before `RandomSwimmingGoal.canUse` draws its interval roll. - `FollowFlockLeaderGoal`: a leader with followers never uses the goal, and a follower always does. Any other fish counts down a start delay first: `reducedTickDelay(200 + nextInt(200) % 20)`, i.e. 100–110 ticks, drawn on the fish's own random in the constructor and again on every attempt. When the delay runs out, it lists the fish of its own class whose boxes meet its box inflated by 8 and that either lead a school with room (`canBeFollowed`) or follow no one. It picks the first school with room as the leader, or else leads itself. The leader then recruits fish from that list that follow no one. The cap is `getMaxSchoolSize - schoolSize`, applied before the leader itself is skipped. A follower re-paths to its leader every `adjustedTickDelay(10)` ticks and leaves the school when the leader dies or is more than 11 blocks away (`distanceToSqr > 121`). - `schoolSize` starts at 1. `startFollowing`/`stopFollowing` add one to it or take one away. `canBeFollowed` = `schoolSize > 1 && schoolSize < max`. `AbstractSchoolingFish.tick` (after `super.tick`) rolls `nextInt(200) == 1` on the level random once a tick while the fish has followers. On a hit, it resets the school to 1 if no other fish of its class is within 8 blocks. - `getMaxSchoolSize`: 8 for cod and tropical fish (`AbstractFish.getMaxSpawnClusterSize`; TropicalFish has no override), 5 for salmon (`Salmon.getMaxSchoolSize`). ## How - `mobs/aquatic.rs`: `FollowFlockLeader` (named `FollowFlockLeaderGoal`), a `FishSwim` wrapper around the existing swimming `Stroll` that adds the `canRandomSwim` gate, and `school_tick` for the 1-in-200 reset. Pufferfish keep their goals as before. - `mobs.rs`: `Extra.followers` holds `schoolSize - 1`, and `Seen.school` gives other fish (leader, followers). A goal can't change other mobs directly, so recruiting goes through two new `MobEvent`s, `StartFollowing` and `SchoolSize`. `apply_brain_events` applies them right after the recruiting fish's tick, the same way `BreedTarget` is handled. - `mobs/ai.rs`: one call to `school_tick` at the end of the living tick, next to the bee and panda hooks. - `game/creatures.rs`: one no-op match arm for the two events, which have already been applied by then. ## Verified - In game (scratch home, creative, a sealed 20×5×20 water box, 8 `summon cod` in two rows of four 5 blocks apart, the rows 12 blocks apart; `entities` sampled every second for 80–90 s). Clusters = groups of cod linked within 4 blocks: | build | clusters, t ≥ 40 s (avg) | clusters at end | |---|---|---| | v0.2.91 | 7.3 | 7 | | main | 6.5 | 6 | | this PR | 2.1 | 2 | With the fix, the cod drop to 3 clusters by 20 s and to 2 by 50 s, and stay there. Main and v0.2.91 stay at 6–8 clusters the whole time. Mean pairwise distance hardly changes (about 12 m on all three builds) because the two schools stay apart: the rows are 12 blocks apart, farther than the 8-block recruit range. - Unit tests `mobs::aquatic::school_tests`: school sizes and `canBeFollowed`, the start-delay range, and a recruit that another leader already took this tick staying with that leader. - `mob_ai` harness: `axolotl_hunting` (it has a no-AI cod) still matches all 46 ticks. `finalize_spawn`, `natural_spawn` and `spawner` pass: fish now draw from their random once at construction, as vanilla's goal constructor does. ## Known differences - Mobs see each other through the per-tick snapshot. If a fish ticks after a recruiter but before the fish it recruited, it still sees the recruit as free. `start_following` refuses to move a fish that already follows a live leader, so school counts stay consistent. In vanilla the second recruiter would have skipped that fish to begin with. This only matters when two start delays end in the same tick. - Dying fish (health 0, not yet removed) are left out of the neighbour lists. Vanilla's `getEntitiesOfClass` still counts them. - Spawn groups (`SchoolSpawnGroupData` in `finalize.rs`) set a follower's leader without adding to the leader's `schoolSize`. That path only runs from structure mobs and the finalize fixture; natural spawning doesn't pass group data. - No new parity scenario. I tried `cod_school` and `salmon_school` in the `mob_ai` harness, with the oracle drawing the goal's start delay again after seeding. The RNG matched at first, but the run diverged at ticks 2–20, before schooling can start: Horizon's `RandomSwimmingGoal` position search uses all its attempts (332 draws) where vanilla stops early, and picks targets above the pool. That's a separate existing gap, so I left the scenarios out. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick` on horizon-build, against origin/main at 77bfff8eb, 6 min 16 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +275 −2 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 408 passed (29 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 55 s) | | tests: horizon-client | ✅ 802 passed (3 min 23 s) | | doc tests | ✅ 0 passed (20 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 | ➖ 347 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 335 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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:10:14 +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#5100
No description provided.