[PR #4457] [MERGED] Save and restore the player's attribute bases #5635

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4457
Author: @DenisHumen
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/player-attribute-save


📝 Commits (1)

  • 6a066d9 Save and restore the player's attribute bases (#4425)

📊 Changes

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

View changed files

📝 crates/horizon-client/src/game.rs (+2 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+6 -2)
📝 crates/horizon-client/src/lan/playerdata.rs (+10 -0)
📝 crates/horizon-client/src/motion.rs (+152 -0)

📄 Description

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

What

The player's attribute bases are saved with the world and come back when it is reopened. Before, /attribute @s minecraft:scale base set 2, quit, reopen → base get said 1.0, and it was the same for every attribute (max_health, ...).

  • PlayerMotion::saved_attributes builds the attributes list from the live map (id, base, permanent modifiers; modifiers left out when empty), and apply_saved_attributes merges a saved list back in. Unknown ids are skipped.
  • Host (single player on the integrated server thread): sync_level writes the list into the player compound; load_saved_state_once applies it before the health, so a raised max_health keeps its saved hearts.
  • LAN guests: playerdata::store writes the list from the live body (it keeps the file's list while there is no body yet), and the first body after joining applies it.

Why (vanilla 26.3)

  • LivingEntity.addAdditionalSaveData stores attributes with AttributeInstance.Packed.LIST_CODEC from AttributeMap.pack(): every instance's pack(), i.e. its base and permanent modifiers.
  • LivingEntity.readAdditionalSaveData reads attributes (server side) and calls AttributeMap.apply right after AbsorptionAmount, before Health.
  • Horizon kept the list as it was first loaded and never wrote the live attribute map to it or read it back into the player.

Checked

  • New test motion::tests::attribute_bases_survive_a_save_and_reload: scale base 2, max_health base 30 plus a permanent ×1.5 modifier, health 40, run through player_tag → read_player → load_saved_state_once. It fails without the fix (left: 1.0, right: 2.0) and passes with it, including max health 45 and health 40.
  • In game (target/fast, scratch HORIZON_HOME, horizon-ctl): /attribute @s minecraft:scale base set 2 and max_health base set 30, quit, relaunch the same world → The base value of attribute Scale ... is 2.0 and Max Health ... is 30.0 (main gave 1.0).
  • I didn't run the LAN guest path in a game. It goes through the same two functions.
  • Out of scope, noted for later: /attribute ... modifier add adds a transient modifier to the player (set_modifier), while vanilla's addPermanentModifier adds a permanent one, so command-added modifiers are still not saved. Base values carrying over a respawn (ServerPlayer.restoreFrom) aren't touched here either.

Fixes #4425

pr_ready (tools/pr_ready.py --base upstream/main on DenisPC, against upstream/main at 3132240f2, 4 min 52 s)

Check Result
Scope ✅ 4 files, +170 −2
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 480 passed (58 s)
rustfmt ✅ (7 s)
clippy ❌ failed (16 s)
tests: horizon-client ❌ 763 passed, 1 failed (3 min 22 s)
doc tests ✅ 0 passed (1 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 ❌ 365 affected, (1 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The red rows are Windows-only and outside this change:

  • clippy: the clippy 1.96 manual_range_contains lint in horizon-world/src/worldgen/aquifer/noise_based.rs. cargo clippy -p horizon-client --all-targets -- -D warnings with the three new 1.96 lints allowed is clean.
  • title::tests::each_world_preset_writes_its_own_generator fails on Windows.
  • Parity: tools/parity.py needs fcntl and can't run on Windows. CI runs the harnesses with run-parity.

🤖 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/4457 **Author:** [@DenisHumen](https://github.com/DenisHumen) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/player-attribute-save` --- ### 📝 Commits (1) - [`6a066d9`](https://github.com/horizon-rust/horizon/commit/6a066d9076d85ffae5d55144283ad9d253522bc4) Save and restore the player's attribute bases (#4425) ### 📊 Changes **4 files changed** (+170 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+2 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+6 -2) 📝 `crates/horizon-client/src/lan/playerdata.rs` (+10 -0) 📝 `crates/horizon-client/src/motion.rs` (+152 -0) </details> ### 📄 Description > 🤖 Opened by DenisHumen's AI agent (Claude Code, Opus 5.5), not by DenisHumen personally. ## What The player's attribute bases are saved with the world and come back when it is reopened. Before, `/attribute @s minecraft:scale base set 2`, quit, reopen → `base get` said 1.0, and it was the same for every attribute (`max_health`, ...). - `PlayerMotion::saved_attributes` builds the `attributes` list from the live map (id, base, permanent modifiers; `modifiers` left out when empty), and `apply_saved_attributes` merges a saved list back in. Unknown ids are skipped. - Host (single player on the integrated server thread): `sync_level` writes the list into the player compound; `load_saved_state_once` applies it **before** the health, so a raised `max_health` keeps its saved hearts. - LAN guests: `playerdata::store` writes the list from the live body (it keeps the file's list while there is no body yet), and the first body after joining applies it. ## Why (vanilla 26.3) - `LivingEntity.addAdditionalSaveData` stores `attributes` with `AttributeInstance.Packed.LIST_CODEC` from `AttributeMap.pack()`: every instance's `pack()`, i.e. its base and permanent modifiers. - `LivingEntity.readAdditionalSaveData` reads `attributes` (server side) and calls `AttributeMap.apply` right after `AbsorptionAmount`, before `Health`. - Horizon kept the list as it was first loaded and never wrote the live attribute map to it or read it back into the player. ## Checked - New test `motion::tests::attribute_bases_survive_a_save_and_reload`: scale base 2, max_health base 30 plus a permanent ×1.5 modifier, health 40, run through `player_tag` → `read_player` → `load_saved_state_once`. It fails without the fix (`left: 1.0, right: 2.0`) and passes with it, including max health 45 and health 40. - In game (`target/fast`, scratch `HORIZON_HOME`, horizon-ctl): `/attribute @s minecraft:scale base set 2` and `max_health base set 30`, `quit`, relaunch the same world → `The base value of attribute Scale ... is 2.0` and `Max Health ... is 30.0` (main gave 1.0). - I didn't run the LAN guest path in a game. It goes through the same two functions. - Out of scope, noted for later: `/attribute ... modifier add` adds a transient modifier to the player (`set_modifier`), while vanilla's `addPermanentModifier` adds a permanent one, so command-added modifiers are still not saved. Base values carrying over a respawn (`ServerPlayer.restoreFrom`) aren't touched here either. Fixes #4425 **pr_ready** (`tools/pr_ready.py --base upstream/main` on DenisPC, against upstream/main at 3132240f2, 4 min 52 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +170 −2 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 480 passed (58 s) | | rustfmt | ✅ (7 s) | | clippy | ❌ failed (16 s) | | tests: horizon-client | ❌ 763 passed, 1 failed (3 min 22 s) | | doc tests | ✅ 0 passed (1 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 | ❌ 365 affected, (1 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The red rows are Windows-only and outside this change: - clippy: the clippy 1.96 `manual_range_contains` lint in `horizon-world/src/worldgen/aquifer/noise_based.rs`. `cargo clippy -p horizon-client --all-targets -- -D warnings` with the three new 1.96 lints allowed is clean. - `title::tests::each_world_preset_writes_its_own_generator` fails on Windows. - Parity: `tools/parity.py` needs `fcntl` and can't run on Windows. CI runs the harnesses with `run-parity`. 🤖 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:13:58 +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#5635
No description provided.