[PR #1200] [MERGED] Mob tick: build the mob world once a tick and answer mob queries from grids #3414

Closed
opened 2026-11-03 04:09:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1200
Author: @pirut
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @ludovic111

Base: main ← Head: claude/upstream-mob-world


📝 Commits (3)

  • 6216b84 Mob tick: build the mob world once a tick, index the snapshot
  • 3b21a97 Mob goals: read nearby mobs from the tick's grid in four more places
  • 3917f35 Natural spawning: answer mob box queries from a grid after a few scans

📊 Changes

15 files changed (+433 additions, -51 deletions)

View changed files

📝 crates/horizon-client/examples/mob_ai_probe.rs (+1 -0)
📝 crates/horizon-client/src/game/creatures.rs (+17 -3)
📝 crates/horizon-client/src/game/natural_spawning.rs (+74 -14)
📝 crates/horizon-client/src/game/scoreboard.rs (+3 -5)
📝 crates/horizon-client/src/mobs.rs (+296 -9)
📝 crates/horizon-client/src/mobs/animal_brain.rs (+1 -1)
📝 crates/horizon-client/src/mobs/aquatic.rs (+1 -1)
📝 crates/horizon-client/src/mobs/enderman.rs (+5 -6)
📝 crates/horizon-client/src/mobs/goals.rs (+12 -4)
📝 crates/horizon-client/src/mobs/golem.rs (+4 -1)
📝 crates/horizon-client/src/mobs/monster_brain.rs (+1 -1)
📝 crates/horizon-client/src/mobs/ravager.rs (+1 -1)
📝 crates/horizon-client/src/mobs/villager_brain.rs (+1 -1)
📝 crates/horizon-client/src/mobs/warden_brain.rs (+1 -1)
📝 crates/horizon-client/src/mobs/world.rs (+15 -3)

📄 Description

Requested by JR

What and why

Fixes #1218.

Mob tick: build the mob world once a tick, index the snapshot

tick_creature_entities called mob_world_base for every mob. That rebuilt
the player view (its allies set scans every mob UUID) and, with any
scoreboard team, an owned copy of every mob's team, each a clone of the
team's player set: cubic in the mobs on a team. The base is now built
once and cloned per mob, with the teams borrowed behind an Arc.

100 mobs, half on a team:  37.7 ms -> 0.06 ms per tick
500 mobs, half on a team:  4297 ms -> 0.31 ms per tick

MobWorld::seen looked mobs up by scanning the snapshot; the mob ticks
now pass an id index (first slot wins, as the scan did): 2000 lookups
over 2000 mobs 1.09 -> 0.01 ms. The nearest-living-entity sensors, the
look-at goal, the ravager's roar and MobWorld::nearby read candidates
from the tick's position grid instead of every mob, in the same order:
2000 mobs 0.39 -> 0.11 ms per tick.

Mob goals: read nearby mobs from the tick's grid in four more places

FollowParentGoal (every baby, every tick), the pufferfish's puff check,
the enderman's block placing and the iron golem's DefendVillage scanned
every mob. They now read candidates from the position grid around the
area they test (one block wider where they test positions, as a box
whose bottom face holds the position meets it), in snapshot order, and
test exactly as before.

Natural spawning: answer mob box queries from a grid after a few scans

GameLevel's isUnobstructed, noCollision (living shulkers) and the
spawners' entity count each scanned every mob, computing each 1.5 KB
mob's box. A spawn pass holds the game immutably, so after eight
queries it builds a grid of the mobs' boxes once and reads candidates
from it; the first queries still scan, as the build costs a few scans.

100 box tests, 2000 mobs: 3.48 -> 0.31 ms (grid build included)

Also gives the mob_ai_probe example the new others_index field.

Vanilla reference

Same results and order as vanilla's own scans: FollowParentGoal.canUse, PufferfishPuffGoal, EnderMan$EndermanLeaveBlockGoal, DefendVillageTargetGoal.canUse, NearestLivingEntitySensor.doTick, LookAtPlayerGoal.canUse, Ravager.roar, and for natural spawning Level.isUnobstructed, CollisionGetter.noCollision and BaseSpawner.serverTick's entity count; team checks read PlayerTeam as before. Harnesses: test_mob_ai_parity.py, test_natural_spawn_parity.py, test_spawner_parity.py, test_team_rules_parity.py, test_scoreboard_parity.py.

Self-check

pr_ready (tools/pr_ready.py --base upstream/main on Mac, against upstream/main at fd0473605, 3 min 24 s)

Check Result
Scope ✅ 15 files, +433 −51
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (6 s)
clippy ✅ (1 min 13 s)
tests: horizon-client ✅ 1082 passed (2 min 0 s)
doc tests ✅ 0 passed (4 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (no vanilla data here): 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)

🤖 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/1200 **Author:** [@pirut](https://github.com/pirut) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `claude/upstream-mob-world` --- ### 📝 Commits (3) - [`6216b84`](https://github.com/horizon-rust/horizon/commit/6216b846691aab89cf46a105a66e871703670401) Mob tick: build the mob world once a tick, index the snapshot - [`3b21a97`](https://github.com/horizon-rust/horizon/commit/3b21a975bb04548d8f64a5adde7d4b24859332ce) Mob goals: read nearby mobs from the tick's grid in four more places - [`3917f35`](https://github.com/horizon-rust/horizon/commit/3917f35e3e781954186d7c2c5be5fa739a333e5e) Natural spawning: answer mob box queries from a grid after a few scans ### 📊 Changes **15 files changed** (+433 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/mob_ai_probe.rs` (+1 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+17 -3) 📝 `crates/horizon-client/src/game/natural_spawning.rs` (+74 -14) 📝 `crates/horizon-client/src/game/scoreboard.rs` (+3 -5) 📝 `crates/horizon-client/src/mobs.rs` (+296 -9) 📝 `crates/horizon-client/src/mobs/animal_brain.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/aquatic.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/enderman.rs` (+5 -6) 📝 `crates/horizon-client/src/mobs/goals.rs` (+12 -4) 📝 `crates/horizon-client/src/mobs/golem.rs` (+4 -1) 📝 `crates/horizon-client/src/mobs/monster_brain.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/ravager.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/villager_brain.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/warden_brain.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/world.rs` (+15 -3) </details> ### 📄 Description <!-- claude-projects-attribution: {"github_login":"pirut"} --> _Requested by **JR**_ ## What and why Fixes #1218. Mob tick: build the mob world once a tick, index the snapshot tick_creature_entities called mob_world_base for every mob. That rebuilt the player view (its allies set scans every mob UUID) and, with any scoreboard team, an owned copy of every mob's team, each a clone of the team's player set: cubic in the mobs on a team. The base is now built once and cloned per mob, with the teams borrowed behind an Arc. ``` 100 mobs, half on a team: 37.7 ms -> 0.06 ms per tick 500 mobs, half on a team: 4297 ms -> 0.31 ms per tick ``` MobWorld::seen looked mobs up by scanning the snapshot; the mob ticks now pass an id index (first slot wins, as the scan did): 2000 lookups over 2000 mobs 1.09 -> 0.01 ms. The nearest-living-entity sensors, the look-at goal, the ravager's roar and MobWorld::nearby read candidates from the tick's position grid instead of every mob, in the same order: 2000 mobs 0.39 -> 0.11 ms per tick. Mob goals: read nearby mobs from the tick's grid in four more places FollowParentGoal (every baby, every tick), the pufferfish's puff check, the enderman's block placing and the iron golem's DefendVillage scanned every mob. They now read candidates from the position grid around the area they test (one block wider where they test positions, as a box whose bottom face holds the position meets it), in snapshot order, and test exactly as before. Natural spawning: answer mob box queries from a grid after a few scans GameLevel's isUnobstructed, noCollision (living shulkers) and the spawners' entity count each scanned every mob, computing each 1.5 KB mob's box. A spawn pass holds the game immutably, so after eight queries it builds a grid of the mobs' boxes once and reads candidates from it; the first queries still scan, as the build costs a few scans. ``` 100 box tests, 2000 mobs: 3.48 -> 0.31 ms (grid build included) ``` Also gives the mob_ai_probe example the new others_index field. ## Vanilla reference Same results and order as vanilla's own scans: `FollowParentGoal.canUse`, `PufferfishPuffGoal`, `EnderMan$EndermanLeaveBlockGoal`, `DefendVillageTargetGoal.canUse`, `NearestLivingEntitySensor.doTick`, `LookAtPlayerGoal.canUse`, `Ravager.roar`, and for natural spawning `Level.isUnobstructed`, `CollisionGetter.noCollision` and `BaseSpawner.serverTick`'s entity count; team checks read `PlayerTeam` as before. Harnesses: `test_mob_ai_parity.py`, `test_natural_spawn_parity.py`, `test_spawner_parity.py`, `test_team_rules_parity.py`, `test_scoreboard_parity.py`. ## Self-check **pr_ready** (`tools/pr_ready.py --base upstream/main` on Mac, against upstream/main at fd0473605, 3 min 24 s) | Check | Result | | --- | --- | | Scope | ✅ 15 files, +433 −51 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (6 s) | | clippy | ✅ (1 min 13 s) | | tests: horizon-client | ✅ 1082 passed (2 min 0 s) | | doc tests | ✅ 0 passed (4 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (no vanilla data here): 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) | 🤖 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 04:09:21 +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#3414
No description provided.