[PR #6628] [MERGED] A player's attributes stay through a respawn and a change of level #6993

Closed
opened 2026-11-03 06:31:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6628
Author: @mariuslozo-boop
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/finish-3684


📝 Commits (1)

  • 3c0a4db A player's attributes stay through a respawn and a change of level (#3684)

📊 Changes

8 files changed (+316 additions, -15 deletions)

View changed files

📝 crates/horizon-client/src/game/lan_actions.rs (+16 -4)
📝 crates/horizon-client/src/game/server_travel.rs (+6 -4)
📝 crates/horizon-client/src/lan/guest.rs (+131 -2)
📝 crates/horizon-client/src/lan/playerdata.rs (+92 -2)
📝 crates/horizon-client/src/motion.rs (+18 -1)
📝 crates/horizon-client/src/pose.rs (+2 -1)
📝 tools/lan_e2e.py (+50 -0)
📝 tools/port_map/game-006.tsv (+1 -1)

📄 Description

🤖 Opened by mariuslozo-boop's AI agent (Claude Code, Claude Sonnet 5.5 + Claude Opus 5.5 review), not by mariuslozo-boop personally.

What and why

Fixes #3684: this is the last part of it. The other four items were fixed by #5580, #3571, #3594 and #3752, and the scaled box itself by #4045.

The server gave a player a new body built from the defaults when they died and respawned, and when they changed level (/execute in the_nether run tp, a Nether or End portal, the End exit after the poem, a spectator teleport). So /attribute @s minecraft:scale base set 0.1 went back to 1.0 (the box, the eye height and the reach with it), and so did every other attribute a command or a datapack had set: a max_health base of 40 was 20 again.

Vanilla keeps the same ServerPlayer through teleport. After a death, PlayerList.respawn builds a new one and ServerPlayer.restoreFrom(old, false) copies the base values to it (assignBaseValues), then gives it its max health (setHealth(getMaxHealth())). The respawn after the End poem is restoreFrom(old, true): base values and permanent modifiers (assignPermanentModifiers).

What changes:

  • PlayerMotion::carried_attributes(restore_all): the old body's attribute list in the save file's form, with its permanent modifiers when restore_all, base values only otherwise.
  • Guest::new_body(restore_all) replaces g.motion = None in the three places that drop the body for a new level or position (arrive_server_trips for portals and the End exit, the execute in level teleports, the spectator teleport) with restore_all true, and in guest_respawn with false. enter_guest applies the carried list to the new body.
  • Guest::respawn_health: the respawned player's health is the max health of the base values it takes over, instead of a fixed 20 (40 for a base of 40, 10 for 10; the attribute's range is 1 to 1024). It is set when the respawn happens, so the first health packet the client gets is already the right one.
  • playerdata::store: a player who leaves between two bodies (after a respawn, before the new body's first tick) saves the carried list, not the older one from the file.
  • Guest::dimensions: a glide the client announced (START_FALL_FLYING) before the body's own tick took that pose used a scale-1 box for that tick; it uses the body's scale (PlayerMotion.scale, the scale its dimensions were last built with).
  • Port ledger: the LivingEntity.getScale row still said there was no scale attribute.

What is carried, compared with vanilla:

  • A level change: vanilla keeps the entity, so all its modifiers stay, transient ones too. Here the base values and permanent modifiers are carried. The effects' modifiers (Horizon applies them as transient, vanilla's MobEffect.addAttributeModifiers as permanent) and the equipment and enchantment modifiers are put on the new body again, as they already were before this change (#1969): its first tick applies them from scratch.
  • The End exit: the same as vanilla's restoreFrom(old, true).
  • A death: base values only, as in vanilla. A modifier added with /attribute ... modifier add is gone after the respawn in both.

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

  • ServerPlayer.teleport(TeleportTransition) (ServerPlayer.java:1139-1196): the same player in the new level.
  • PlayerList.respawn (PlayerList.java:389-396) and ServerPlayer.restoreFrom (ServerPlayer.java:1653-1675): assignBaseValues, then assignPermanentModifiers and the old health when restoreAll, setHealth(getMaxHealth()) when not.
  • ServerGamePacketListenerImpl.handleClientCommand (ServerGamePacketListenerImpl.java:1951-1970): restoreAll only for the respawn after the End poem.
  • AttributeMap.assignBaseValues, assignPermanentModifiers (AttributeMap.java:101-117).
  • Attributes.MAX_HEALTH (20, 1 to 1024) and Attributes.SCALE (1, 0.0625 to 16) (Attributes.java:68-91).
  • LivingEntity.getDimensions with Avatar.POSES for the gliding box.

Harness: no parity harness respawns or moves a server player with changed attributes. The end-to-end check is tools/lan_e2e.py --check scale-body (below).

Other projects' code

none

Self-check

New tests, each failing without the change (the unit tests build a real body, so they need the prepared resources in .local and return early without them, as the playerdata tests beside them do; they ran here):

  • lan::guest::tests::a_respawned_player_has_the_max_health_of_their_base_values: a max health base of 40 respawns with 40, 10 with 10, 20 plus a permanent +20 with 20, 0 with 1, 2048 with 1024, and a player with no body with 20. With the fixed 20 put back it fails (base 40: left 20, right 40).
  • lan::guest::tests::a_glide_announced_before_the_body_ticks_has_the_scaled_box: at scale 0.1 and 2. On main the box is 0.6 wide.
  • lan::playerdata::tests::a_new_body_takes_the_scale_of_the_old_one: scale 0.1 and a permanent +0.4 step height; after a death the scale only, after a level change both.
  • lan::playerdata::tests::a_player_between_two_bodies_saves_the_attributes_the_next_one_takes.
  • tools/lan_e2e.py --check scale-body: two real games (--offscreen, isolated homes), the host on its server thread and a LAN guest. Each sets scale 0.1 and max health 40, goes to the Nether and back with execute in, dies (kill @s) and respawns. The eye height each client sees stays 0.162 through all of it, and both come back from the respawn with 40 health. On main it fails at the Nether (eye 1.62); with this branch but the fixed respawn health of 20, it fails at the respawn (health: 23.0: 20, then the regeneration a max of 40 allows); with this branch it passes. (Run before the last rebase onto main, which changed none of the code it covers.)

pr_ready (tools/pr_ready.py --quick --base upstream/main on PCDKBLENDER, against upstream/main at 8d93d68f1, 13 min 33 s)

Check Result
Scope ✅ 8 files, +316 −15
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 596 run, FAILED (errors=1, skipped=2) (1 min 0 s)
rustfmt ✅ (8 s)
clippy ✅ (52 s)
tests: horizon-client, horizon-client-lib ✅ 1929 passed (11 min 24 s)
doc tests ✅ 0 passed (3 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 ➖ 113 affected, to run in CI (--quick): arrow, auto_jump, enchanting, friends_integration, lan_integration, management_protocol, online_mode, remote_fireball, remote_fireworks, replace_blobs, replace_block, resource_pack and 101 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)
  • Python tests: the one error is test_world_input_capture.test_capture_lifecycle (its compiled fixture exits with 101). It fails the same on a clean checkout of 8d93d68f1: it came with #6410 and is not touched here.
  • Parity: listed for CI, not run (--quick). Since 5ebf42f7b the runner starts harnesses on Windows, but on this machine every one fails before it compares anything (its javac is JDK 21 and the oracles compile with --release 25), and the ones that start the game open a window. A full pr_ready run of this branch on eb0d9e580 was stopped in its parity step after 265 harnesses had failed that way; all its other checks passed.
  • Threads: RUST_TEST_THREADS=2 (the render tests can hang on Windows otherwise, #5238).

Not tested:

  • A Nether or End portal in the real client: the e2e check uses execute in. Portals, the End exit and the spectator teleport go through the same Guest::new_body(true).
  • A dedicated server: it runs the same server code as the host's server thread, which the e2e check covers.

Found along the way, not changed here (read in the code, not run):

  • A level change still gives the server's body fresh absorption (no golden hearts), air (300) and fire (none), where vanilla keeps the entity's. A player sprinting through a portal gets a new body without the sprint speed modifier. These are body state, not attributes.
  • Hub::collide (the "moved wrongly" check of handlePlayerPositionChange) steps up 0.6 where vanilla's player.move uses the player's step_height, so a survival player whose step height was raised by a command would likely be sent back when stepping up more than 0.6.
  • Between two bodies (until the next body exists) Guest::dimensions uses scale 1.
  • The ledger row LivingEntity.getFallDamageSound in the same map file names a function that does not exist (map-check).

🤖 Generated with Claude Code

https://claude.ai/code/session_01RodDbPWCByh96WKcbiEQpB


🔄 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/6628 **Author:** [@mariuslozo-boop](https://github.com/mariuslozo-boop) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/finish-3684` --- ### 📝 Commits (1) - [`3c0a4db`](https://github.com/horizon-rust/horizon/commit/3c0a4db876d8b69f9d3082a7503ab6f49337d25b) A player's attributes stay through a respawn and a change of level (#3684) ### 📊 Changes **8 files changed** (+316 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/lan_actions.rs` (+16 -4) 📝 `crates/horizon-client/src/game/server_travel.rs` (+6 -4) 📝 `crates/horizon-client/src/lan/guest.rs` (+131 -2) 📝 `crates/horizon-client/src/lan/playerdata.rs` (+92 -2) 📝 `crates/horizon-client/src/motion.rs` (+18 -1) 📝 `crates/horizon-client/src/pose.rs` (+2 -1) 📝 `tools/lan_e2e.py` (+50 -0) 📝 `tools/port_map/game-006.tsv` (+1 -1) </details> ### 📄 Description > 🤖 Opened by mariuslozo-boop's AI agent (Claude Code, Claude Sonnet 5.5 + Claude Opus 5.5 review), not by mariuslozo-boop personally. ## What and why Fixes #3684: this is the last part of it. The other four items were fixed by #5580, #3571, #3594 and #3752, and the scaled box itself by #4045. The server gave a player a new body built from the defaults when they died and respawned, and when they changed level (`/execute in the_nether run tp`, a Nether or End portal, the End exit after the poem, a spectator teleport). So `/attribute @s minecraft:scale base set 0.1` went back to 1.0 (the box, the eye height and the reach with it), and so did every other attribute a command or a datapack had set: a `max_health` base of 40 was 20 again. Vanilla keeps the same `ServerPlayer` through `teleport`. After a death, `PlayerList.respawn` builds a new one and `ServerPlayer.restoreFrom(old, false)` copies the base values to it (`assignBaseValues`), then gives it its max health (`setHealth(getMaxHealth())`). The respawn after the End poem is `restoreFrom(old, true)`: base values and permanent modifiers (`assignPermanentModifiers`). What changes: - `PlayerMotion::carried_attributes(restore_all)`: the old body's attribute list in the save file's form, with its permanent modifiers when `restore_all`, base values only otherwise. - `Guest::new_body(restore_all)` replaces `g.motion = None` in the three places that drop the body for a new level or position (`arrive_server_trips` for portals and the End exit, the `execute in` level teleports, the spectator teleport) with `restore_all` true, and in `guest_respawn` with false. `enter_guest` applies the carried list to the new body. - `Guest::respawn_health`: the respawned player's health is the max health of the base values it takes over, instead of a fixed 20 (40 for a base of 40, 10 for 10; the attribute's range is 1 to 1024). It is set when the respawn happens, so the first health packet the client gets is already the right one. - `playerdata::store`: a player who leaves between two bodies (after a respawn, before the new body's first tick) saves the carried list, not the older one from the file. - `Guest::dimensions`: a glide the client announced (`START_FALL_FLYING`) before the body's own tick took that pose used a scale-1 box for that tick; it uses the body's scale (`PlayerMotion.scale`, the scale its dimensions were last built with). - Port ledger: the `LivingEntity.getScale` row still said there was no scale attribute. What is carried, compared with vanilla: - A level change: vanilla keeps the entity, so all its modifiers stay, transient ones too. Here the base values and permanent modifiers are carried. The effects' modifiers (Horizon applies them as transient, vanilla's `MobEffect.addAttributeModifiers` as permanent) and the equipment and enchantment modifiers are put on the new body again, as they already were before this change (#1969): its first tick applies them from scratch. - The End exit: the same as vanilla's `restoreFrom(old, true)`. - A death: base values only, as in vanilla. A modifier added with `/attribute ... modifier add` is gone after the respawn in both. ## 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 - `ServerPlayer.teleport(TeleportTransition)` (`ServerPlayer.java:1139-1196`): the same player in the new level. - `PlayerList.respawn` (`PlayerList.java:389-396`) and `ServerPlayer.restoreFrom` (`ServerPlayer.java:1653-1675`): `assignBaseValues`, then `assignPermanentModifiers` and the old health when `restoreAll`, `setHealth(getMaxHealth())` when not. - `ServerGamePacketListenerImpl.handleClientCommand` (`ServerGamePacketListenerImpl.java:1951-1970`): `restoreAll` only for the respawn after the End poem. - `AttributeMap.assignBaseValues`, `assignPermanentModifiers` (`AttributeMap.java:101-117`). - `Attributes.MAX_HEALTH` (20, 1 to 1024) and `Attributes.SCALE` (1, 0.0625 to 16) (`Attributes.java:68-91`). - `LivingEntity.getDimensions` with `Avatar.POSES` for the gliding box. Harness: no parity harness respawns or moves a server player with changed attributes. The end-to-end check is `tools/lan_e2e.py --check scale-body` (below). ## Other projects' code none ## Self-check New tests, each failing without the change (the unit tests build a real body, so they need the prepared resources in `.local` and return early without them, as the playerdata tests beside them do; they ran here): - `lan::guest::tests::a_respawned_player_has_the_max_health_of_their_base_values`: a max health base of 40 respawns with 40, 10 with 10, 20 plus a permanent +20 with 20, 0 with 1, 2048 with 1024, and a player with no body with 20. With the fixed 20 put back it fails (`base 40: left 20, right 40`). - `lan::guest::tests::a_glide_announced_before_the_body_ticks_has_the_scaled_box`: at scale 0.1 and 2. On main the box is 0.6 wide. - `lan::playerdata::tests::a_new_body_takes_the_scale_of_the_old_one`: scale 0.1 and a permanent +0.4 step height; after a death the scale only, after a level change both. - `lan::playerdata::tests::a_player_between_two_bodies_saves_the_attributes_the_next_one_takes`. - `tools/lan_e2e.py --check scale-body`: two real games (`--offscreen`, isolated homes), the host on its server thread and a LAN guest. Each sets scale 0.1 and max health 40, goes to the Nether and back with `execute in`, dies (`kill @s`) and respawns. The eye height each client sees stays 0.162 through all of it, and both come back from the respawn with 40 health. On main it fails at the Nether (eye 1.62); with this branch but the fixed respawn health of 20, it fails at the respawn (`health: 23.0`: 20, then the regeneration a max of 40 allows); with this branch it passes. (Run before the last rebase onto main, which changed none of the code it covers.) **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on PCDKBLENDER, against upstream/main at 8d93d68f1, 13 min 33 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +316 −15 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 596 run, FAILED (errors=1, skipped=2) (1 min 0 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (52 s) | | tests: horizon-client, horizon-client-lib | ✅ 1929 passed (11 min 24 s) | | doc tests | ✅ 0 passed (3 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 | ➖ 113 affected, to run in CI (--quick): arrow, auto_jump, enchanting, friends_integration, lan_integration, management_protocol, online_mode, remote_fireball, remote_fireworks, replace_blobs, replace_block, resource_pack and 101 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | - **Python tests:** the one error is `test_world_input_capture.test_capture_lifecycle` (its compiled fixture exits with 101). It fails the same on a clean checkout of `8d93d68f1`: it came with #6410 and is not touched here. - **Parity:** listed for CI, not run (`--quick`). Since 5ebf42f7b the runner starts harnesses on Windows, but on this machine every one fails before it compares anything (its `javac` is JDK 21 and the oracles compile with `--release 25`), and the ones that start the game open a window. A full `pr_ready` run of this branch on `eb0d9e580` was stopped in its parity step after 265 harnesses had failed that way; all its other checks passed. - **Threads:** `RUST_TEST_THREADS=2` (the render tests can hang on Windows otherwise, #5238). Not tested: - A Nether or End portal in the real client: the e2e check uses `execute in`. Portals, the End exit and the spectator teleport go through the same `Guest::new_body(true)`. - A dedicated server: it runs the same server code as the host's server thread, which the e2e check covers. Found along the way, not changed here (read in the code, not run): - A level change still gives the server's body fresh absorption (no golden hearts), air (300) and fire (none), where vanilla keeps the entity's. A player sprinting through a portal gets a new body without the sprint speed modifier. These are body state, not attributes. - `Hub::collide` (the "moved wrongly" check of `handlePlayerPositionChange`) steps up 0.6 where vanilla's `player.move` uses the player's `step_height`, so a survival player whose step height was raised by a command would likely be sent back when stepping up more than 0.6. - Between two bodies (until the next body exists) `Guest::dimensions` uses scale 1. - The ledger row `LivingEntity.getFallDamageSound` in the same map file names a function that does not exist (`map-check`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RodDbPWCByh96WKcbiEQpB --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:31:10 +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#6993
No description provided.