[PR #5092] [MERGED] Fix single-player position and inventory saving on the integrated server (#5065) #6068

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

📋 Pull Request Information

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

Base: main ← Head: fix-integrated-player-save-5065


📝 Commits (1)

  • 65d4d06 Fix single-player position and inventory saving on the integrated server (#5065)

📊 Changes

3 files changed (+100 additions, -15 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+86 -11)
📝 crates/horizon-client/src/game/execution_role.rs (+12 -4)
📝 crates/horizon-client/src/game/lan.rs (+2 -0)

📄 Description

???? Opened by mulareal's AI agent (Antigravity), not by mulareal personally.

What

Saving and quitting a single-player world now preserves the player's position, rotation, inventory, and state when re-entering the world.
Fixes #5065
Fixes #5075
Fixes #5216

Why

  • Single-player worlds run on the integrated server thread (ExecutionRole::IntegratedServer), where Game::open_integrated sets options.dedicated = Some(Vec::new()) while keeping the single-player owner's state in self.level via Game::save_guest and Game::store_owner.
  • Game::save_game_metadata checked self.options.dedicated.is_some() and called Level::write_without_player instead of Level::write, so players/data/<singleplayer_uuid>.dat was never updated after initial world creation (position: None, empty inventory).
  • Game::sync_level also copied the server Game's unused in-frame player fields (self.inventory, self.yaw, self.pitch, self.dim, self.creative) into self.level when self.player.is_none(), overwriting self.level's player state if the owner had already disconnected or had not finished joining.

Fix

  • Add ExecutionRole::writes_singleplayer_player in crates/horizon-client/src/game/execution_role.rs and use write_level_for_role in Game::save_game_metadata (crates/horizon-client/src/game.rs) so ExecutionRole::IntegratedServer writes the owner's player file via Level::write while ExecutionRole::DedicatedServer uses Level::write_without_player.
  • Return early from Game::sync_level after updating world-level fields (game_rules, difficulty, time, weather, day_time) when self.player.is_none() && self.options.dedicated.is_some().
  • Preserve saved.position in Game::store_owner (crates/horizon-client/src/game/lan.rs) if the world is saved before the owner's Guest has been placed.

Checked

  • cargo test -p horizon-client --bin horizon-client integrated_server_save_persists_owner_player_data
  • cargo test -p horizon-client --bin horizon-client world_loading_keeps_in_frame_clients_and_server_roles_separate
  • python tools/port_ledger.py check --base origin/main
  • python tools/pr_ready.py --quick --base origin/main
  • Manual in-game check in Creative mode: moved away from spawn, placed items into the inventory, used Save and Quit to Title, and re-entered the world.
Check Result
Scope ??? 3 files, +100 ???15
Cargo.lock ??? unchanged
Public tree ???
Python tests ??? 484 passed
rustfmt ???
clippy (horizon-client) ???
tests: horizon-client ??? 1338 passed
doc tests ??? 0 passed
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 ??? not run (--quick): CI's parity job picks the affected harnesses

???? Generated with Antigravity


🔄 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/5092 **Author:** [@mulareal](https://github.com/mulareal) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix-integrated-player-save-5065` --- ### 📝 Commits (1) - [`65d4d06`](https://github.com/horizon-rust/horizon/commit/65d4d06ec57c2f220beb954c8393ab0330b29122) Fix single-player position and inventory saving on the integrated server (#5065) ### 📊 Changes **3 files changed** (+100 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+86 -11) 📝 `crates/horizon-client/src/game/execution_role.rs` (+12 -4) 📝 `crates/horizon-client/src/game/lan.rs` (+2 -0) </details> ### 📄 Description > ???? Opened by mulareal's AI agent (Antigravity), not by mulareal personally. ## What Saving and quitting a single-player world now preserves the player's position, rotation, inventory, and state when re-entering the world. Fixes #5065 Fixes #5075 Fixes #5216 ## Why - Single-player worlds run on the integrated server thread (`ExecutionRole::IntegratedServer`), where `Game::open_integrated` sets `options.dedicated = Some(Vec::new())` while keeping the single-player owner's state in `self.level` via `Game::save_guest` and `Game::store_owner`. - `Game::save_game_metadata` checked `self.options.dedicated.is_some()` and called `Level::write_without_player` instead of `Level::write`, so `players/data/<singleplayer_uuid>.dat` was never updated after initial world creation (`position: None`, empty inventory). - `Game::sync_level` also copied the server `Game`'s unused in-frame player fields (`self.inventory`, `self.yaw`, `self.pitch`, `self.dim`, `self.creative`) into `self.level` when `self.player.is_none()`, overwriting `self.level`'s player state if the owner had already disconnected or had not finished joining. ## Fix - Add `ExecutionRole::writes_singleplayer_player` in `crates/horizon-client/src/game/execution_role.rs` and use `write_level_for_role` in `Game::save_game_metadata` (`crates/horizon-client/src/game.rs`) so `ExecutionRole::IntegratedServer` writes the owner's player file via `Level::write` while `ExecutionRole::DedicatedServer` uses `Level::write_without_player`. - Return early from `Game::sync_level` after updating world-level fields (`game_rules`, `difficulty`, `time`, `weather`, `day_time`) when `self.player.is_none() && self.options.dedicated.is_some()`. - Preserve `saved.position` in `Game::store_owner` (`crates/horizon-client/src/game/lan.rs`) if the world is saved before the owner's `Guest` has been placed. ## Checked - `cargo test -p horizon-client --bin horizon-client integrated_server_save_persists_owner_player_data` - `cargo test -p horizon-client --bin horizon-client world_loading_keeps_in_frame_clients_and_server_roles_separate` - `python tools/port_ledger.py check --base origin/main` - `python tools/pr_ready.py --quick --base origin/main` - Manual in-game check in Creative mode: moved away from spawn, placed items into the inventory, used Save and Quit to Title, and re-entered the world. | Check | Result | |---|---| | Scope | ??? 3 files, +100 ???15 | | Cargo.lock | ??? unchanged | | Public tree | ??? | | Python tests | ??? 484 passed | | rustfmt | ??? | | clippy (`horizon-client`) | ??? | | tests: horizon-client | ??? 1338 passed | | doc tests | ??? 0 passed | | 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 | ??? not run (--quick): CI's parity job picks the affected harnesses | ???? Generated with Antigravity --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:11: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#6068
No description provided.