[PR #5636] [MERGED] Single player: the owner loads the player file level.dat names, so a trip through 0.2.93 keeps the newer inventory #6405

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

📋 Pull Request Information

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

Base: main ← Head: fix/inventory-revert-update


📝 Commits (3)

  • be7de62 Single player: the owner loads the player file level.dat names (#5351)
  • 3e75d64 Port map: load_owner's row keeps the load and datafix gap; no stale citation
  • 7ca3d98 Single player: the owner's leave saves the file it loads; .dat_old fallback

📊 Changes

5 files changed (+187 additions, -38 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+3 -2)
📝 crates/horizon-client/src/game/lan.rs (+12 -27)
📝 crates/horizon-client/src/lan/playerdata.rs (+153 -2)
📝 crates/horizon-client/src/save.rs (+18 -6)
📝 tools/port_map/rest-020.tsv (+1 -1)

📄 Description

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

What and why

Fixes #5351. After going back from 0.2.93 to a newer build, the player got an older inventory and position. The next save then wrote them over the newer ones.

Root cause. Since #5069 (088731f31) the integrated server saves the single-player owner to two files: the one level.dat names (players/data/<singleplayer_uuid>.dat, offline Player, written by Level::write) and the owner's own (<owner uuid>.dat). On join it read the own file first. 0.2.93 and the stable builds before #5069 save the owner to the named file alone, so the own file stays where the newer build left it. Back on the newer build, the owner loaded that stale file.

Fix.

  • PlayerList.loadPlayerData (PlayerList.java:280) gives the single-player owner the file level.dat names. Level::read now records whether its player came from that file (singleplayer_file, .dat or .dat_old). playerdata::load_owner applies it before the owner's own file. The own file stays the fallback when the named file is missing (vanilla would start a new player there).
  • The owner's leave (save_guest, PlayerList.remove → save) wrote only the own file. The named file waited for the world save that follows in stop_integrated (bed release, chunks, then save_game_metadata). A game killed or failing in between would have left the named file older than the own one, and with the first change the owner would load the older state. playerdata::save_owner now writes the named file (Level::write_player, the player half of Level::write) and then the own one. So the file the owner loads is never the older of the two.
  • playerdata::load (PlayerDataStorage.load) now falls back to <uuid>.dat_old, as vanilla does. write_dat moves the old file aside before renaming the new one in, so a save cut off between the two renames leaves only .dat_old. Before, that player started empty. The named file's read already had this fallback.

Unchanged: a dedicated server has no owner, so every player still loads their own file; LAN guests too. Every save still writes the named file, which is what 0.2.93 and older builds read.

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

PlayerList.loadPlayerData (the owner gets getSinglePlayerUUID's file), PlayerDataStorage.load (.dat, then .dat_old), PlayerList.remove / PlayerList.save → PlayerDataStorage.save. Port map: the PlayerList.loadPlayerData row points at load_owner. It keeps the known gap that player files are datafixed when the world is upgraded, not on load.

Other projects' code

none

Self-check

New tests in lan::playerdata, each run failing without its fix:

  • the_owner_loads_the_file_level_dat_names_over_an_older_own_file (named: gold; own: older diamond). With the own file read first it gets the diamond.
  • the_owner_loads_its_own_file_when_the_named_one_is_missing
  • a_save_cut_off_between_its_renames_loads_the_dat_old: both files moved to .dat_old. Without the fallback, load returns nothing.
  • the_owner_leaving_saves_the_file_it_loads: the last autosave wrote a diamond; the owner leaves with gold and the world save never comes. Without the named file written on leave, the owner loads the diamond.

By hand in a window (real 0.2.93 release, isolated HORIZON_HOME, horizon-ctl):

  • unfixed main (21bddaf) → 0.2.93 → unfixed main: the newer inventory is lost (the bug).
  • this branch at its final commit, in a new world: 5 diamonds, quit → 0.2.93 sees the diamonds, swaps them for 7 gold, quit → this branch has the 7 gold → adds 3 emeralds, quit, reopen: gold and emeralds → 0.2.93 sees both, adds 9 redstone, quit → this branch has all three.

pr_ready (tools/pr_ready.py --base upstream/main on PCDKBLENDER, against upstream/main at f99f8feaa, 5 min 17 s)

Check Result
Scope ✅ 5 files, +187 −38
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 510 passed (53 s)
rustfmt ✅ (10 s)
clippy ✅ (15 s)
tests: horizon-client ✅ 1578 passed (3 min 54 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 ❌ 373 affected, (1 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)
  • Parity: this was run on Windows, where the runner needs fcntl and can't start. The affected harnesses run in CI (run-parity).

Not tested:

  • A game killed between the owner's leave and the world save, and a save cut off between its renames: unit tests only, not by hand.
  • An online-account owner: the code path is the same as offline. When level.dat names the owner's own UUID (a vanilla world), both files are the same file.
  • Opening a world whose newest player file belongs to someone else, with no singleplayer_uuid: Level::read falls back to that file, and saves then write the owner to it. That predates this change and is left alone here.

🤖 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/5636 **Author:** [@mariuslozo-boop](https://github.com/mariuslozo-boop) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/inventory-revert-update` --- ### 📝 Commits (3) - [`be7de62`](https://github.com/horizon-rust/horizon/commit/be7de6230c1610a8790968f449a9ecf6a1abd7b4) Single player: the owner loads the player file level.dat names (#5351) - [`3e75d64`](https://github.com/horizon-rust/horizon/commit/3e75d6484b5c6842d5d097acba311d0347c214d2) Port map: load_owner's row keeps the load and datafix gap; no stale citation - [`7ca3d98`](https://github.com/horizon-rust/horizon/commit/7ca3d989013018000e7f7f99c14635b3ba7cafcd) Single player: the owner's leave saves the file it loads; .dat_old fallback ### 📊 Changes **5 files changed** (+187 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+3 -2) 📝 `crates/horizon-client/src/game/lan.rs` (+12 -27) 📝 `crates/horizon-client/src/lan/playerdata.rs` (+153 -2) 📝 `crates/horizon-client/src/save.rs` (+18 -6) 📝 `tools/port_map/rest-020.tsv` (+1 -1) </details> ### 📄 Description > 🤖 Opened by mariuslozo-boop's AI agent (Claude Code, Claude Opus 5.5), not by mariuslozo-boop personally. ## What and why Fixes #5351. After going back from 0.2.93 to a newer build, the player got an older inventory and position. The next save then wrote them over the newer ones. **Root cause.** Since #5069 (088731f31) the integrated server saves the single-player owner to two files: the one level.dat names (`players/data/<singleplayer_uuid>.dat`, offline `Player`, written by `Level::write`) and the owner's own (`<owner uuid>.dat`). On join it read the **own** file first. 0.2.93 and the stable builds before #5069 save the owner to the named file alone, so the own file stays where the newer build left it. Back on the newer build, the owner loaded that stale file. **Fix.** - `PlayerList.loadPlayerData` (PlayerList.java:280) gives the single-player owner the file level.dat names. `Level::read` now records whether its player came from that file (`singleplayer_file`, `.dat` or `.dat_old`). `playerdata::load_owner` applies it before the owner's own file. The own file stays the fallback when the named file is missing (vanilla would start a new player there). - The owner's leave (`save_guest`, `PlayerList.remove` → `save`) wrote only the own file. The named file waited for the world save that follows in `stop_integrated` (bed release, chunks, then `save_game_metadata`). A game killed or failing in between would have left the named file older than the own one, and with the first change the owner would load the older state. `playerdata::save_owner` now writes the named file (`Level::write_player`, the player half of `Level::write`) and then the own one. So the file the owner loads is never the older of the two. - `playerdata::load` (`PlayerDataStorage.load`) now falls back to `<uuid>.dat_old`, as vanilla does. `write_dat` moves the old file aside before renaming the new one in, so a save cut off between the two renames leaves only `.dat_old`. Before, that player started empty. The named file's read already had this fallback. Unchanged: a dedicated server has no owner, so every player still loads their own file; LAN guests too. Every save still writes the named file, which is what 0.2.93 and older builds read. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] 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 `PlayerList.loadPlayerData` (the owner gets `getSinglePlayerUUID`'s file), `PlayerDataStorage.load` (`.dat`, then `.dat_old`), `PlayerList.remove` / `PlayerList.save` → `PlayerDataStorage.save`. Port map: the `PlayerList.loadPlayerData` row points at `load_owner`. It keeps the known gap that player files are datafixed when the world is upgraded, not on load. ## Other projects' code none ## Self-check New tests in `lan::playerdata`, each run failing without its fix: - `the_owner_loads_the_file_level_dat_names_over_an_older_own_file` (named: gold; own: older diamond). With the own file read first it gets the diamond. - `the_owner_loads_its_own_file_when_the_named_one_is_missing` - `a_save_cut_off_between_its_renames_loads_the_dat_old`: both files moved to `.dat_old`. Without the fallback, `load` returns nothing. - `the_owner_leaving_saves_the_file_it_loads`: the last autosave wrote a diamond; the owner leaves with gold and the world save never comes. Without the named file written on leave, the owner loads the diamond. By hand in a window (real 0.2.93 release, isolated `HORIZON_HOME`, horizon-ctl): - unfixed main (21bddaf) → 0.2.93 → unfixed main: the newer inventory is lost (the bug). - this branch at its final commit, in a new world: 5 diamonds, quit → 0.2.93 sees the diamonds, swaps them for 7 gold, quit → this branch has the 7 gold → adds 3 emeralds, quit, reopen: gold and emeralds → 0.2.93 sees both, adds 9 redstone, quit → this branch has all three. **pr_ready** (`tools/pr_ready.py --base upstream/main` on PCDKBLENDER, against upstream/main at f99f8feaa, 5 min 17 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +187 −38 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 510 passed (53 s) | | rustfmt | ✅ (10 s) | | clippy | ✅ (15 s) | | tests: horizon-client | ✅ 1578 passed (3 min 54 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 | ❌ 373 affected, (1 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | - Parity: this was run on Windows, where the runner needs `fcntl` and can't start. The affected harnesses run in CI (`run-parity`). Not tested: - A game killed between the owner's leave and the world save, and a save cut off between its renames: unit tests only, not by hand. - An online-account owner: the code path is the same as offline. When level.dat names the owner's own UUID (a vanilla world), both files are the same file. - Opening a world whose newest player file belongs to someone else, with no `singleplayer_uuid`: `Level::read` falls back to that file, and saves then write the owner to it. That predates this change and is left alone here. 🤖 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:20:01 +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#6405
No description provided.