[PR #4084] [MERGED] Runtime spawns run Mob.finalizeSpawn and wither skeletons hit for 4 #5408

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

📋 Pull Request Information

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

Base: main ← Head: fix-2783


📝 Commits (1)

  • 6b8e3b8 Runtime spawns run Mob.finalizeSpawn and wither skeletons hit for 4

📊 Changes

4 files changed (+118 additions, -24 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+2 -0)
📝 crates/horizon-client/src/mobs/finalize.rs (+24 -11)
📝 crates/horizon-client/src/mobs/spawning.rs (+91 -1)
📝 crates/horizon-client/src/mobs/villager.rs (+1 -12)

📄 Description

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

What and why

Mobs spawned while the game runs (/summon, spawn eggs, spawners, natural spawns, raids, structure mobs that are finalized on load) go through the reduced mobs::spawning::finalize. That function never ran the common Mob.finalizeSpawn or WitherSkeleton.finalizeSpawn. As a result:

  • no runtime-spawned mob got the minecraft:random_spawn_bonus follow range modifier, and none was ever left-handed (vanilla makes 5 percent of mobs left-handed);
  • wither skeletons kept the default 2.0 attack damage, so fortress wither skeletons hit for half of vanilla's damage (vanilla uses 4.0).

The worldgen path (finalize::Ctx::mob) already had the right Mob.finalizeSpawn body, and the summoned iron golem had a copy of it. This PR moves that body into one shared finalize::mob_spawn(m, random). Ctx::mob, villager::finalize_summoned_golem and the runtime spawning::finalize all call it now. The runtime path skips the cave spider, because CaveSpider.finalizeSpawn returns without calling super. The runtime path also sets the wither skeleton's attack_damage base to 4.0.

Bred babies are created through the same runtime spawn, but vanilla's Animal.spawnChildFromBreeding gets them from getBreedOffspring, which never calls finalizeSpawn. The breeding code already resets the sound variant for that reason. It now also drops the follow range bonus and the left hand again, through spawning::bred_offspring (using a new finalize::remove_modifier, vanilla's AttributeInstance.removeModifier).

This is one slice of the issue. It doesn't touch the rest of the omnibus (piglin/hoglin babies, parrot variant, panda genes, the drowned's nautilus shell, spider effects and jockeys, jockeys by spawn reason), and it doesn't touch the goat and fox parts that #3955 covers. The runtime path keeps using the mob's own random, as the rest of spawning::finalize does.

Part of #2783

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Checked with javap on the 26.3 client jar:

  • Mob.finalizeSpawn: if FOLLOW_RANGE has no RANDOM_SPAWN_BONUS_ID modifier, it adds one with random.triangle(0.0, 0.11485) and ADD_MULTIPLIED_BASE. Then it calls setLeftHanded(random.nextFloat() < 0.05F).
  • WitherSkeleton.finalizeSpawn: calls super.finalizeSpawn (AbstractSkeleton), then getAttribute(ATTACK_DAMAGE).setBaseValue(4.0) and reassessWeaponGoal().
  • CaveSpider.finalizeSpawn: returns the group data without calling super.
  • Animal.spawnChildFromBreeding: getBreedOffspring, setBaby, snapTo, finalizeSpawnChildFromBreeding, addFreshEntityWithPassengers. It never calls finalizeSpawn, and no getBreedOffspring of an animal does.

Checks:

  • New unit tests in mobs::spawning::tests.
  • tools/test_finalize_spawn_parity.py still matches vanilla after the shared helper refactor (24,000 cases).

Self-check

tools/pr_ready.py doesn't run on Windows, so I ran these checks by hand:

cargo fmt --all -- --check                                      # ok
cargo clippy -p horizon-client --all-targets -- -D warnings     # ok, no warnings
cargo test -p horizon-client --lib -- mobs::spawning::tests
  before (fix reverted, tests kept):
    runtime_spawns_run_the_mob_finalize_spawn ... FAILED
      assertion failed: has_modifier(&m, Attr::FollowRange, "minecraft:random_spawn_bonus")
    runtime_wither_skeletons_hit_for_four ... FAILED
      left: 2.0  right: 4.0
  after: 2 passed
cargo test -p horizon-client --lib -- mobs::finalize mobs::villager mobs::spawning mobs::spawn_rules mobs::equine
  22 passed, 0 failed, 1 ignored
python tools/test_finalize_spawn_parity.py
  24,000 finalizeSpawn cases match vanilla (60,992 entities, 1,828 enchanted items)
cargo build --profile fast -p horizon-client --bins               # ok

In game, single player on the server thread, Hard, spawn_mobs false, everything else killed, then 60 skeletons, one wither skeleton and one creeper summoned:

Check main this PR
execute if entity @e[type=skeleton,nbt={LeftHanded:1b}] Test failed (0 of 60) 6 of 60
attribute @e[type=wither_skeleton,limit=1] minecraft:attack_damage base get 2.0 4.0
data get entity @e[type=creeper,limit=1] attributes Found no elements follow_range with a minecraft:random_spawn_bonus modifier (add_multiplied_base)
two summoned cows bred (InLove:600): the baby's attributes not run (main never adds the modifier) []: no random_spawn_bonus, LeftHanded:0b; the summoned parent has the modifier

(attribute ... follow_range modifier value get doesn't show the modifier on either build, because the command reads its own attribute map and not the mob's. That is a separate issue, so I checked the saved NBT with data get.)

Screenshots

Before: chat shows "Test failed" for left-handed skeletons, "The base value of attribute Attack Damage for entity Wither Skeleton is 2.0" and "Found no elements matching attributes" for the creeper. After: the wither skeleton reads 4.0, and the creeper's data shows the minecraft:random_spawn_bonus follow range modifier.

🤖 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/4084 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-2783` --- ### 📝 Commits (1) - [`6b8e3b8`](https://github.com/horizon-rust/horizon/commit/6b8e3b8f5f61ef5d70bdcfb9f7d8314169b7e8fd) Runtime spawns run Mob.finalizeSpawn and wither skeletons hit for 4 ### 📊 Changes **4 files changed** (+118 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+2 -0) 📝 `crates/horizon-client/src/mobs/finalize.rs` (+24 -11) 📝 `crates/horizon-client/src/mobs/spawning.rs` (+91 -1) 📝 `crates/horizon-client/src/mobs/villager.rs` (+1 -12) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why Mobs spawned while the game runs (`/summon`, spawn eggs, spawners, natural spawns, raids, structure mobs that are finalized on load) go through the reduced `mobs::spawning::finalize`. That function never ran the common `Mob.finalizeSpawn` or `WitherSkeleton.finalizeSpawn`. As a result: - no runtime-spawned mob got the `minecraft:random_spawn_bonus` follow range modifier, and none was ever left-handed (vanilla makes 5 percent of mobs left-handed); - wither skeletons kept the default 2.0 attack damage, so fortress wither skeletons hit for half of vanilla's damage (vanilla uses 4.0). The worldgen path (`finalize::Ctx::mob`) already had the right `Mob.finalizeSpawn` body, and the summoned iron golem had a copy of it. This PR moves that body into one shared `finalize::mob_spawn(m, random)`. `Ctx::mob`, `villager::finalize_summoned_golem` and the runtime `spawning::finalize` all call it now. The runtime path skips the cave spider, because `CaveSpider.finalizeSpawn` returns without calling `super`. The runtime path also sets the wither skeleton's `attack_damage` base to 4.0. Bred babies are created through the same runtime spawn, but vanilla's `Animal.spawnChildFromBreeding` gets them from `getBreedOffspring`, which never calls `finalizeSpawn`. The breeding code already resets the sound variant for that reason. It now also drops the follow range bonus and the left hand again, through `spawning::bred_offspring` (using a new `finalize::remove_modifier`, vanilla's `AttributeInstance.removeModifier`). This is one slice of the issue. It doesn't touch the rest of the omnibus (piglin/hoglin babies, parrot variant, panda genes, the drowned's nautilus shell, spider effects and jockeys, jockeys by spawn reason), and it doesn't touch the goat and fox parts that #3955 covers. The runtime path keeps using the mob's own random, as the rest of `spawning::finalize` does. Part of #2783 ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Checked with javap on the 26.3 client jar: - `Mob.finalizeSpawn`: if `FOLLOW_RANGE` has no `RANDOM_SPAWN_BONUS_ID` modifier, it adds one with `random.triangle(0.0, 0.11485)` and `ADD_MULTIPLIED_BASE`. Then it calls `setLeftHanded(random.nextFloat() < 0.05F)`. - `WitherSkeleton.finalizeSpawn`: calls `super.finalizeSpawn` (AbstractSkeleton), then `getAttribute(ATTACK_DAMAGE).setBaseValue(4.0)` and `reassessWeaponGoal()`. - `CaveSpider.finalizeSpawn`: returns the group data without calling `super`. - `Animal.spawnChildFromBreeding`: `getBreedOffspring`, `setBaby`, `snapTo`, `finalizeSpawnChildFromBreeding`, `addFreshEntityWithPassengers`. It never calls `finalizeSpawn`, and no `getBreedOffspring` of an animal does. Checks: - New unit tests in `mobs::spawning::tests`. - `tools/test_finalize_spawn_parity.py` still matches vanilla after the shared helper refactor (24,000 cases). ## Self-check `tools/pr_ready.py` doesn't run on Windows, so I ran these checks by hand: ``` cargo fmt --all -- --check # ok cargo clippy -p horizon-client --all-targets -- -D warnings # ok, no warnings cargo test -p horizon-client --lib -- mobs::spawning::tests before (fix reverted, tests kept): runtime_spawns_run_the_mob_finalize_spawn ... FAILED assertion failed: has_modifier(&m, Attr::FollowRange, "minecraft:random_spawn_bonus") runtime_wither_skeletons_hit_for_four ... FAILED left: 2.0 right: 4.0 after: 2 passed cargo test -p horizon-client --lib -- mobs::finalize mobs::villager mobs::spawning mobs::spawn_rules mobs::equine 22 passed, 0 failed, 1 ignored python tools/test_finalize_spawn_parity.py 24,000 finalizeSpawn cases match vanilla (60,992 entities, 1,828 enchanted items) cargo build --profile fast -p horizon-client --bins # ok ``` In game, single player on the server thread, Hard, `spawn_mobs false`, everything else killed, then 60 skeletons, one wither skeleton and one creeper summoned: | Check | main | this PR | |---|---|---| | `execute if entity @e[type=skeleton,nbt={LeftHanded:1b}]` | Test failed (0 of 60) | 6 of 60 | | `attribute @e[type=wither_skeleton,limit=1] minecraft:attack_damage base get` | 2.0 | 4.0 | | `data get entity @e[type=creeper,limit=1] attributes` | Found no elements | `follow_range` with a `minecraft:random_spawn_bonus` modifier (`add_multiplied_base`) | | two summoned cows bred (`InLove:600`): the baby's `attributes` | not run (main never adds the modifier) | `[]`: no `random_spawn_bonus`, `LeftHanded:0b`; the summoned parent has the modifier | (`attribute ... follow_range modifier value get` doesn't show the modifier on either build, because the command reads its own attribute map and not the mob's. That is a separate issue, so I checked the saved NBT with `data get`.) ## Screenshots Before: chat shows "Test failed" for left-handed skeletons, "The base value of attribute Attack Damage for entity Wither Skeleton is 2.0" and "Found no elements matching attributes" for the creeper. After: the wither skeleton reads 4.0, and the creeper's data shows the `minecraft:random_spawn_bonus` follow range modifier. 🤖 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:12:23 +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#5408
No description provided.