[PR #4628] [MERGED] Save the ridden vehicle tree in the player's file and take it on leave #5737

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4628
Author: @AurelienBelloir
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: parity/save-parent-vehicle


📝 Commits (6)

  • 7136fd7 Save the ridden vehicle tree in the player's file and take it on leave
  • 5fa3563 Merge remote-tracking branch 'origin/main' into parity/save-parent-vehicle
  • 0111493 Save a minecart's mob passengers with its ride and climb to it as root
  • 8d86472 Merge main into #4628
  • 5ecf9f7 Merge main into #4628
  • 639a32b Saving: main's autosave of every player's file uses this PR's playerdata::save

📊 Changes

7 files changed (+385 additions, -69 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+29 -4)
📝 crates/horizon-client/src/game/dedicated.rs (+3 -10)
📝 crates/horizon-client/src/game/integrated.rs (+1 -3)
📝 crates/horizon-client/src/game/lan.rs (+113 -18)
📝 crates/horizon-client/src/game/persist.rs (+198 -16)
📝 crates/horizon-client/src/lan/playerdata.rs (+36 -12)
📝 crates/horizon-client/src/save.rs (+5 -6)

📄 Description

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

What and why

Vanilla ServerPlayer.saveParentVehicle writes RootVehicle {Attach: mount UUID, Entity: root vehicle with passengers}, but only while the root has exactly one player passenger (Entity.hasExactlyOnePlayerPassenger). PlayerList.remove then takes that vehicle tree out of the world with the player and unrides it. PlayerList.removeAll does the same for each player in turn on shutdown, and loadAndSpawnParentVehicle spawns the tree again on the next login. Horizon wrote only Attach and left the vehicle in the world. A vanilla reader of a Horizon save got no vehicle back, and the horse or boat stayed in the world after the rider left (#3520 rows saveParentVehicle / loadAndSpawnParentVehicle).

  • persist.rs: vehicle_root (getRootVehicle: mob stack bottom or the boat under it), vehicle_tree_nbt (mob tree, boat with its mobs, minecart), parent_vehicle_tag (the one-player check, then the full RootVehicle compound), remove_vehicle_tree. Replaces root_vehicle_uuid.
  • lan.rs: take_parent_vehicle, used when a guest leaves (HostEvent::Left), and save_leaving_guests, used by lan_close, stop_integrated and stop_dedicated. When the guest is the only player on its vehicle, the tree goes into the guest's saved compound, leaves the world, and the guest unrides. The guest's dimension is entered if needed. store_owner writes the full RootVehicle at autosave for the integrated server's owner.
  • playerdata: store takes the RootVehicle compound; save no longer takes a vehicle. An unrestored RootVehicle from the file is kept whole.
  • game.rs sync_level: the local player's full RootVehicle, and a stale one removed.
  • save.rs: comments updated.
  • Test: a_saved_root_vehicle_comes_back now checks the full compound round trip.

Not in this change: Entity.shouldBeSaved (leaving a vehicle with one player rider out of chunk saves). It needs non-owner guests to be saved at autosave first, or vehicles could be lost.

Fixes #4627

Not covered: 1) Entity.shouldBeSaved is not implemented: chunk saves still include a vehicle ridden by exactly one player. I left it out on purpose. Horizon does not save the files of guests other than the owner at autosave (vanilla's PlayerList.saveAll does), and chunk unloads or dimension switches (entity_chunks with remove=true) would drop the vehicle. Leaving it out cannot lose a vehicle, and the 'restored' dedupe stops a duplicate on load. The only difference left is this: after a crash, or if the chunk loads before the player's restore, the older chunk copy can be the one ridden. 2) Vanilla discards the spawned tree when re-attaching fails ("Couldn't reattach entity to player"); restore_saved_vehicle still leaves it in the world. 3) A mob riding a minecart is not saved as part of the cart's tree. This was already true of Horizon's chunk saving and was kept the same.

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

Read from the 26.3 bytecode with javap -c:

  • ServerPlayer.saveParentVehicle
  • ServerPlayer.loadAndSpawnParentVehicle
  • PlayerList.remove
  • PlayerList.removeAll
  • Entity.hasExactlyOnePlayerPassenger
  • Entity.shouldBeSaved
  • Entity.save
  • Entity.saveAsPassenger

Tests added or extended:

  • lan::playerdata::tests::a_saved_root_vehicle_comes_back (extended: the full RootVehicle {Attach, Entity} goes out in the file, comes back as saved_vehicle, and is kept whole when the player is saved again before riding it)

No new parity harness.

Self-check

The full tools/pr_ready.py needs more disk than this machine has (see #4543). Checked by hand on Windows, with prepared 26.3 resources in HORIZON_RESOURCES (CARGO_INCREMENTAL=0):

  • rustfmt: ✅
  • cargo clippy -p horizon-client --all-targets -- -D warnings: ✅
  • cargo test --no-fail-fast -p horizon-client --lib --bins --tests: horizon-client lib 780 passed, 1 failed: title::tests::each_world_preset_writes_its_own_generator, which fails on Windows only and already fails on main; #4544 fixes it; horizon-client bin 240 passed; horizon-ctl 18 passed; all 8 integration suites pass
  • Public tree hook: ✅
  • An independent review against the 26.3 bytecode before opening; its findings are fixed in this branch.

🤖 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/4628 **Author:** [@AurelienBelloir](https://github.com/AurelienBelloir) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `parity/save-parent-vehicle` --- ### 📝 Commits (6) - [`7136fd7`](https://github.com/horizon-rust/horizon/commit/7136fd7e75a2fc5eb9ecab6503cc5bfba51da1a6) Save the ridden vehicle tree in the player's file and take it on leave - [`5fa3563`](https://github.com/horizon-rust/horizon/commit/5fa35637737db86fcc87d0d1091bbfdf73276ed5) Merge remote-tracking branch 'origin/main' into parity/save-parent-vehicle - [`0111493`](https://github.com/horizon-rust/horizon/commit/0111493fc8f08ee26f96c11e8780e6ea4e23b556) Save a minecart's mob passengers with its ride and climb to it as root - [`8d86472`](https://github.com/horizon-rust/horizon/commit/8d86472e015b9ffaacf4a1783e0637dc76151102) Merge main into #4628 - [`5ecf9f7`](https://github.com/horizon-rust/horizon/commit/5ecf9f7b9117ebf7d1ca242fc88b4238e1ba69a2) Merge main into #4628 - [`639a32b`](https://github.com/horizon-rust/horizon/commit/639a32b0c227fbf718a914d6c5bccbbadf8259fc) Saving: main's autosave of every player's file uses this PR's playerdata::save ### 📊 Changes **7 files changed** (+385 additions, -69 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+29 -4) 📝 `crates/horizon-client/src/game/dedicated.rs` (+3 -10) 📝 `crates/horizon-client/src/game/integrated.rs` (+1 -3) 📝 `crates/horizon-client/src/game/lan.rs` (+113 -18) 📝 `crates/horizon-client/src/game/persist.rs` (+198 -16) 📝 `crates/horizon-client/src/lan/playerdata.rs` (+36 -12) 📝 `crates/horizon-client/src/save.rs` (+5 -6) </details> ### 📄 Description > 🤖 Opened by AurelienBelloir's AI agent (Claude Code, Claude Opus 5.5), not by AurelienBelloir personally. ## What and why Vanilla `ServerPlayer.saveParentVehicle` writes `RootVehicle {Attach: mount UUID, Entity: root vehicle with passengers}`, but only while the root has exactly one player passenger (`Entity.hasExactlyOnePlayerPassenger`). `PlayerList.remove` then takes that vehicle tree out of the world with the player and unrides it. `PlayerList.removeAll` does the same for each player in turn on shutdown, and `loadAndSpawnParentVehicle` spawns the tree again on the next login. Horizon wrote only `Attach` and left the vehicle in the world. A vanilla reader of a Horizon save got no vehicle back, and the horse or boat stayed in the world after the rider left (#3520 rows saveParentVehicle / loadAndSpawnParentVehicle). - persist.rs: `vehicle_root` (`getRootVehicle`: mob stack bottom or the boat under it), `vehicle_tree_nbt` (mob tree, boat with its mobs, minecart), `parent_vehicle_tag` (the one-player check, then the full RootVehicle compound), `remove_vehicle_tree`. Replaces `root_vehicle_uuid`. - lan.rs: `take_parent_vehicle`, used when a guest leaves (`HostEvent::Left`), and `save_leaving_guests`, used by `lan_close`, `stop_integrated` and `stop_dedicated`. When the guest is the only player on its vehicle, the tree goes into the guest's saved compound, leaves the world, and the guest unrides. The guest's dimension is entered if needed. `store_owner` writes the full RootVehicle at autosave for the integrated server's owner. - playerdata: `store` takes the RootVehicle compound; `save` no longer takes a vehicle. An unrestored RootVehicle from the file is kept whole. - game.rs `sync_level`: the local player's full RootVehicle, and a stale one removed. - save.rs: comments updated. - Test: `a_saved_root_vehicle_comes_back` now checks the full compound round trip. Not in this change: `Entity.shouldBeSaved` (leaving a vehicle with one player rider out of chunk saves). It needs non-owner guests to be saved at autosave first, or vehicles could be lost. Fixes #4627 Not covered: 1) Entity.shouldBeSaved is not implemented: chunk saves still include a vehicle ridden by exactly one player. I left it out on purpose. Horizon does not save the files of guests other than the owner at autosave (vanilla's PlayerList.saveAll does), and chunk unloads or dimension switches (entity_chunks with remove=true) would drop the vehicle. Leaving it out cannot lose a vehicle, and the 'restored' dedupe stops a duplicate on load. The only difference left is this: after a crash, or if the chunk loads before the player's restore, the older chunk copy can be the one ridden. 2) Vanilla discards the spawned tree when re-attaching fails ("Couldn't reattach entity to player"); restore_saved_vehicle still leaves it in the world. 3) A mob riding a minecart is not saved as part of the cart's tree. This was already true of Horizon's chunk saving and was kept the same. ## 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 Read from the 26.3 bytecode with `javap -c`: - `ServerPlayer.saveParentVehicle` - `ServerPlayer.loadAndSpawnParentVehicle` - `PlayerList.remove` - `PlayerList.removeAll` - `Entity.hasExactlyOnePlayerPassenger` - `Entity.shouldBeSaved` - `Entity.save` - `Entity.saveAsPassenger` Tests added or extended: - `lan::playerdata::tests::a_saved_root_vehicle_comes_back (extended: the full RootVehicle {Attach, Entity} goes out in the file, comes back as saved_vehicle, and is kept whole when the player is saved again before riding it)` No new parity harness. ## Self-check The full `tools/pr_ready.py` needs more disk than this machine has (see #4543). Checked by hand on Windows, with prepared 26.3 resources in `HORIZON_RESOURCES` (`CARGO_INCREMENTAL=0`): - rustfmt: ✅ - `cargo clippy -p horizon-client --all-targets -- -D warnings`: ✅ - `cargo test --no-fail-fast -p horizon-client --lib --bins --tests`: horizon-client lib 780 passed, 1 failed: `title::tests::each_world_preset_writes_its_own_generator`, which fails on Windows only and already fails on main; #4544 fixes it; horizon-client bin 240 passed; horizon-ctl 18 passed; all 8 integration suites pass - Public tree hook: ✅ - An independent review against the 26.3 bytecode before opening; its findings are fixed in this branch. 🤖 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:14:39 +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#5737
No description provided.