[PR #2995] [MERGED] Horses, donkeys, mules and llamas sync their rolled max health #4746

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2995
Author: @ASOwnerYT
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @levzzz5154

Base: main ← Head: fix/2869-horse-max-health


📝 Commits (2)

  • d321b65 Horses, donkeys, mules and llamas sync their rolled max health
  • af3aa00 Merge main into fix/2869-horse-max-health

📊 Changes

3 files changed (+76 additions, -16 deletions)

View changed files

📝 crates/horizon-client/src/entity_nbt.rs (+13 -0)
📝 crates/horizon-client/src/mobs/equine.rs (+59 -13)
📝 crates/horizon-client/src/mobs/llama.rs (+4 -3)

📄 Description

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

What and why

Fixes #2869. When you rode a horse, the health bar over the hotbar showed far too many hearts (26) instead of the horse's own 8 to 15.

Horses, donkeys and mules got their rolled max health in mobs/equine.rs, and llamas in mobs/llama.rs. Both wrote it straight into m.attrs.max_health, and a horse's speed into m.attrs.speed, without making it an attribute base. The server only syncs attribute instances (mob_attributes in game/lan_attributes.rs), so ClientboundUpdateAttributesPacket never carried the rolled value. The rider's client kept the horse type's default max health of 53, and getVehicleMaxHearts turned that into 26 hearts. On the default single-player path (the server thread), the window is such a client, so every player saw it.

It hit every horse, donkey, mule and llama spawned while the game runs (spawn egg, /summon, natural spawns, spawners). It also hit bred foals (equine::inherit, llama::apply_offspring) and any saved one after a reload (entity_nbt::mob_from_nbt). World generation's Ctx::horse already used set_base.

Now all of these go through finalize::set_base, as vanilla's AttributeInstance.setBaseValue does:

  • equine::finalize: max health for horses, donkeys and mules, plus speed for horses.
  • equine::inherit: max health and speed.
  • llama::finalize: max health.
  • llama::apply_offspring: max health and speed.
  • mob_from_nbt: a saved horse, donkey, mule, llama or camel's max_health and movement_speed bases.

set_base also refreshes m.attrs, so the server-side values are the same as before. A unit test checks that a finalized horse, donkey and mule keep their rolled health and speed as attribute bases.

Jump strength still lives in extra.vector[0] and isn't synced as minecraft:jump_strength. I left that alone to keep this PR small.

Vanilla reference

  • AbstractHorse.randomizeAttributes / Horse.randomizeAttributes / AbstractChestedHorse.randomizeAttributes: getAttribute(Attributes.MAX_HEALTH).setBaseValue(generateMaxHealth(random::nextInt)), and the same for MOVEMENT_SPEED.
  • AbstractHorse.setOffspringAttribute: baby.getAttribute(attribute).setBaseValue(newValue).
  • LivingEntity.readAdditionalSaveData → AttributeMap.load: the saved bases become instances.
  • ServerEntity.sendPairingData / sendDirtyEntityData: getSyncableAttributes() (MAX_HEALTH is client-syncable) goes out as ClientboundUpdateAttributesPacket.
  • Hud.getVehicleMaxHearts: (int)(vehicle.getMaxHealth() + 0.5F) / 2, capped at 30.

There's no vehicle-HUD harness. With horizon-ctl (offscreen, fresh temporary homes), /attribute … max_health get after a plain /summon gives rolled values (horse 27, donkey 19, llama 23). The server side was already right before this change: the bug was only in what the server synced. I couldn't mount the horse through horizon-ctl (/ride and interact-entity left the window's player unmounted), so I didn't screenshot the rider's hearts.

Self-check

entity_model fails only because of its oracle: the bat's IllegalAccessException (getField(..).set on a final field). It fails the same way on main, and #2941 fixes it. Before this run, the harnesses that touch saving and LAN play (save_roundtrip, world_reopen, spawn_loot, remote_fireball, remote_fireworks, server_player_sculk and friends_integration) passed on this branch.

Label: none (a fix). This fork can't set labels upstream.

pr_ready (tools/pr_ready.py --base upstream/main on cachyos, against upstream/main at 1feb28c04, 24 min 3 s)

Check Result
Scope ✅ 3 files, +62 −9
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 398 passed (20 s)
rustfmt ✅ (5 s)
clippy ✅ (53 s)
tests: horizon-client ✅ 1257 passed (1 min 53 s)
doc tests ✅ 0 passed (27 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 ❌ 72 affected, 66 passed, failed: entity_model (20 min 16 s)
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/2995 **Author:** [@ASOwnerYT](https://github.com/ASOwnerYT) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix/2869-horse-max-health` --- ### 📝 Commits (2) - [`d321b65`](https://github.com/horizon-rust/horizon/commit/d321b656f678020ee88f61e8c73770f5314896b0) Horses, donkeys, mules and llamas sync their rolled max health - [`af3aa00`](https://github.com/horizon-rust/horizon/commit/af3aa003773fd419c7b333cee3dfdaffc674591a) Merge main into fix/2869-horse-max-health ### 📊 Changes **3 files changed** (+76 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/entity_nbt.rs` (+13 -0) 📝 `crates/horizon-client/src/mobs/equine.rs` (+59 -13) 📝 `crates/horizon-client/src/mobs/llama.rs` (+4 -3) </details> ### 📄 Description > 🤖 Opened by asowneryt's AI agent (Claude Code), not by asowneryt himself. ## What and why Fixes #2869. When you rode a horse, the health bar over the hotbar showed far too many hearts (26) instead of the horse's own 8 to 15. Horses, donkeys and mules got their rolled max health in `mobs/equine.rs`, and llamas in `mobs/llama.rs`. Both wrote it straight into `m.attrs.max_health`, and a horse's speed into `m.attrs.speed`, without making it an attribute base. The server only syncs attribute instances (`mob_attributes` in `game/lan_attributes.rs`), so `ClientboundUpdateAttributesPacket` never carried the rolled value. The rider's client kept the horse type's default max health of 53, and `getVehicleMaxHearts` turned that into 26 hearts. On the default single-player path (the server thread), the window is such a client, so every player saw it. It hit every horse, donkey, mule and llama spawned while the game runs (spawn egg, `/summon`, natural spawns, spawners). It also hit bred foals (`equine::inherit`, `llama::apply_offspring`) and any saved one after a reload (`entity_nbt::mob_from_nbt`). World generation's `Ctx::horse` already used `set_base`. Now all of these go through `finalize::set_base`, as vanilla's `AttributeInstance.setBaseValue` does: - `equine::finalize`: max health for horses, donkeys and mules, plus speed for horses. - `equine::inherit`: max health and speed. - `llama::finalize`: max health. - `llama::apply_offspring`: max health and speed. - `mob_from_nbt`: a saved horse, donkey, mule, llama or camel's `max_health` and `movement_speed` bases. `set_base` also refreshes `m.attrs`, so the server-side values are the same as before. A unit test checks that a finalized horse, donkey and mule keep their rolled health and speed as attribute bases. Jump strength still lives in `extra.vector[0]` and isn't synced as `minecraft:jump_strength`. I left that alone to keep this PR small. ## Vanilla reference - `AbstractHorse.randomizeAttributes` / `Horse.randomizeAttributes` / `AbstractChestedHorse.randomizeAttributes`: `getAttribute(Attributes.MAX_HEALTH).setBaseValue(generateMaxHealth(random::nextInt))`, and the same for `MOVEMENT_SPEED`. - `AbstractHorse.setOffspringAttribute`: `baby.getAttribute(attribute).setBaseValue(newValue)`. - `LivingEntity.readAdditionalSaveData` → `AttributeMap.load`: the saved bases become instances. - `ServerEntity.sendPairingData` / `sendDirtyEntityData`: `getSyncableAttributes()` (MAX_HEALTH is client-syncable) goes out as `ClientboundUpdateAttributesPacket`. - `Hud.getVehicleMaxHearts`: `(int)(vehicle.getMaxHealth() + 0.5F) / 2`, capped at 30. There's no vehicle-HUD harness. With `horizon-ctl` (offscreen, fresh temporary homes), `/attribute … max_health get` after a plain `/summon` gives rolled values (horse 27, donkey 19, llama 23). The server side was already right before this change: the bug was only in what the server synced. I couldn't mount the horse through `horizon-ctl` (`/ride` and `interact-entity` left the window's player unmounted), so I didn't screenshot the rider's hearts. ## Self-check `entity_model` fails only because of its oracle: the bat's `IllegalAccessException` (`getField(..).set` on a final field). It fails the same way on main, and #2941 fixes it. Before this run, the harnesses that touch saving and LAN play (save_roundtrip, world_reopen, spawn_loot, remote_fireball, remote_fireworks, server_player_sculk and friends_integration) passed on this branch. Label: none (a fix). This fork can't set labels upstream. **pr_ready** (`tools/pr_ready.py --base upstream/main` on cachyos, against upstream/main at 1feb28c04, 24 min 3 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +62 −9 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 398 passed (20 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (53 s) | | tests: horizon-client | ✅ 1257 passed (1 min 53 s) | | doc tests | ✅ 0 passed (27 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 | ❌ 72 affected, 66 passed, failed: entity_model (20 min 16 s) | | 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:07:38 +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#4746
No description provided.