[PR #942] [MERGED] Villagers, traders and golems never despawn for distance (#917) #2927

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

📋 Pull Request Information

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

Base: main ← Head: fix/village-villagers


📝 Commits (1)

  • 875773a Villagers, traders and golems never despawn for distance

📊 Changes

1 file changed (+44 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/mobs/ai.rs (+44 -7)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #917 (reported by tydragon on Discord: villagers missing from villages, only the iron golem there; noticed as a LAN guest).

What and why

Villages place their villagers through the jigsaw templates' entity entries (StructureTemplate.placeEntities, village/*/villagers/*.nbt), and Horizon does that correctly. But those villager entries are saved without PersistenceRequired (0), while village/common/iron_golem.nbt has it (1). Horizon's Mob.checkDespawn then treated villagers as removable: every villager of a village generated more than 128 blocks from the nearest player (that is, any village you walk or fly towards with a render distance above 8) was discarded at once, and the rest randomly past 32 blocks. The golem survived only because of its persistence flag.

Vanilla 26.3 never despawns them for distance: Villager.removeWhenFarAway, WanderingTrader.removeWhenFarAway and AbstractGolem.removeWhenFarAway (iron, snow and copper golems, shulkers) all return false. This ports those overrides into mobs::ai::check_despawn (never_removed_when_far), next to the ones Horizon already had (Allay, Warden, and the wither's checkDespawn). Shulkers in end cities were affected the same way.

Proof

Seed 1234, plains village at (-960, 176): the player is teleported to (-780, 176), 180 blocks away, so the village generates beyond 128 blocks; then the villagers within 100 blocks of the village centre are counted (horizon-ctl mobs), also after going into the village.

villagers iron golems
main (24bcef42) 0 1
this branch 14 1
vanilla 26.3 dedicated server, same seed (execute positioned -960 70 176 if entity @e[type=villager,distance=..100] after force-loading the village) 14 1

Reporter's LAN case, seed -8713567381149888028: the village nearest spawn (vanilla locate: -432, 128, about 420 blocks from spawn) is placed on the host with its villagers when generated near a player (12), and a LAN guest teleported there is sent every villager the host has (8 of 8 after a night of zombies, plus the golem and the cats). So the guest's side only lost them through this despawn, not in tracking. (Side finding: Horizon's /locate structure #minecraft:village answers a farther village there: #938.)

Unit test despawn_tests::villagers_traders_and_golems_never_despawn_for_distance.

Self-check

Check Result
Scope ✅ 1 files, +44 −7
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (12 s)
clippy ✅ (3 min 30 s)
tests: horizon-client ✅ 978 passed (12 min 19 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ❌ 96 affected, 95 passed, failed: world_spawn (93 min 18 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

world_spawn timed out at its 1500 s limit with the Mac mini at ~90 % CPU from other agents' runs; every seed it reached matched vanilla (ok for all 40+ printed). It only places the player at the world spawn, nothing that despawns. A lone rerun is in progress; result in a comment.

Nothing needs Ludovic.

🤖 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/942 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/village-villagers` --- ### 📝 Commits (1) - [`875773a`](https://github.com/horizon-rust/horizon/commit/875773a08fc568fe637b0255799c3fc5f87a35d8) Villagers, traders and golems never despawn for distance ### 📊 Changes **1 file changed** (+44 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/ai.rs` (+44 -7) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #917 (reported by tydragon on Discord: villagers missing from villages, only the iron golem there; noticed as a LAN guest). ## What and why Villages place their villagers through the jigsaw templates' entity entries (`StructureTemplate.placeEntities`, `village/*/villagers/*.nbt`), and Horizon does that correctly. But those villager entries are saved **without** `PersistenceRequired` (`0`), while `village/common/iron_golem.nbt` has it (`1`). Horizon's `Mob.checkDespawn` then treated villagers as removable: every villager of a village generated more than 128 blocks from the nearest player (that is, any village you walk or fly towards with a render distance above 8) was discarded at once, and the rest randomly past 32 blocks. The golem survived only because of its persistence flag. Vanilla 26.3 never despawns them for distance: `Villager.removeWhenFarAway`, `WanderingTrader.removeWhenFarAway` and `AbstractGolem.removeWhenFarAway` (iron, snow and copper golems, shulkers) all return `false`. This ports those overrides into `mobs::ai::check_despawn` (`never_removed_when_far`), next to the ones Horizon already had (`Allay`, `Warden`, and the wither's `checkDespawn`). Shulkers in end cities were affected the same way. ## Proof Seed 1234, plains village at (-960, 176): the player is teleported to (-780, 176), 180 blocks away, so the village generates beyond 128 blocks; then the villagers within 100 blocks of the village centre are counted (`horizon-ctl mobs`), also after going into the village. | | villagers | iron golems | | --- | --- | --- | | main (24bcef42) | **0** | 1 | | this branch | **14** | 1 | | vanilla 26.3 dedicated server, same seed (`execute positioned -960 70 176 if entity @e[type=villager,distance=..100]` after force-loading the village) | **14** | 1 | Reporter's LAN case, seed `-8713567381149888028`: the village nearest spawn (vanilla `locate`: -432, 128, about 420 blocks from spawn) is placed on the host with its villagers when generated near a player (12), and a LAN guest teleported there is sent every villager the host has (8 of 8 after a night of zombies, plus the golem and the cats). So the guest's side only lost them through this despawn, not in tracking. (Side finding: Horizon's `/locate structure #minecraft:village` answers a farther village there: #938.) Unit test `despawn_tests::villagers_traders_and_golems_never_despawn_for_distance`. ## Self-check | Check | Result | | --- | --- | | Scope | ✅ 1 files, +44 −7 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (12 s) | | clippy | ✅ (3 min 30 s) | | tests: horizon-client | ✅ 978 passed (12 min 19 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ❌ 96 affected, 95 passed, failed: world_spawn (93 min 18 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | `world_spawn` timed out at its 1500 s limit with the Mac mini at ~90 % CPU from other agents' runs; every seed it reached matched vanilla (`ok` for all 40+ printed). It only places the player at the world spawn, nothing that despawns. A lone rerun is in progress; result in a comment. Nothing needs Ludovic. 🤖 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-02 16:00:11 +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#2927
No description provided.