[PR #6911] [MERGED] Native hooks: PlayerEvent.Clone, LoadFromFile and SaveToFile #7186

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

📋 Pull Request Information

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

Base: main ← Head: v2/ses_01M6DKF0Z8BE7TF075HX2BZ8T2-a14d111139e2


📝 Commits (10+)

  • 146bb12 Add native_player_clone (PlayerEvent.Clone)
  • c5e5ac8 Add native_player_load_from_file (PlayerEvent.LoadFromFile)
  • 1c4209f Add native_player_save_to_file (PlayerEvent.SaveToFile)
  • 60ca8bc Fix native player file hooks: qualify Path, fire owner SaveToFile after level.dat write
  • d311c4d Create the player directory before the player file hooks run
  • b953491 Document that the player directory exists for the file hooks
  • a9f3a84 Document the save hook's directory too
  • 31c6f2f Keep the player file path a pure builder and create the directory once per save loop
  • e409dcd Fix player_save_to_file docs: guests not heard on integrated autosaves
  • 6a53803 Regenerate the mod API

📊 Changes

11 files changed (+264 additions, -25 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+8 -1)
📝 crates/horizon-client/src/game/lan.rs (+20 -20)
📝 crates/horizon-client/src/game/lan_actions.rs (+4 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+42 -0)
📝 crates/horizon-client/src/game/server_travel.rs (+6 -0)
📝 crates/horizon-client/src/lan/playerdata.rs (+15 -4)
📝 crates/horizon-client/src/mod_api/generated.rs (+104 -0)
📝 docs/native-mods.md (+17 -0)
➕ tools/native-hook-fragments/native_player_clone.json (+16 -0)
➕ tools/native-hook-fragments/native_player_load_from_file.json (+16 -0)
➕ tools/native-hook-fragments/native_player_save_to_file.json (+16 -0)

📄 Description

🤖 Opened by Aria's agent swarm, Dyna, not by Aria.

Adds three server-side listen hooks matching NeoForge's PlayerEvent.Clone, PlayerEvent.LoadFromFile and PlayerEvent.SaveToFile. None is cancellable.

  • native_player_clone(player, name, was_death): fires after the data copy and before respawn placement, on death (was_death = true, the end of restoreFrom) and on the End exit (false, PlayerList.respawn keeping all data).
  • native_player_load_from_file(player, name, directory): fires when a player's data is read and applied, before the player is placed, with the players/data directory.
  • native_player_save_to_file(player, name, directory): fires when a LAN guest leaves or the world closes, when the dedicated server saves everyone, and for the integrated owner once level.dat is written. On an integrated server an autosave saves only the owner, so guests are heard on leave or world close; docs/native-mods.md says so.

playerdata::directory creates players/data on first use, as PlayerDataStorage's constructor does, so a mod can write next to the player file. store_owner now returns the stored owner so the save hook fires only when the owner was written.

Tested in game

Built through the launcher (native-build, dev profile) with a throwaway trait mod on a throwaway branch of https://github.com/arismoko/horizon-machine-sample (the recommended end-to-end route, used here). The build was one test merge of this PR with the batch's other hooks PRs (#6910, #6912) on main db813a1c3. Each hook logged a WAVE_PROOF line.

Hook Server thread (integrated, LAN) Dedicated server
player_clone ✅ /kill and respawn logged was_death = true; leaving the End through the exit portal logged false ✅ both
player_load_from_file ✅ the owner's join and a LAN guest's join (a second client) each logged …/saves/W1/players/data ✅ a client join logged …/world/players/data
player_save_to_file ✅ the owner's save logged; a LAN guest disconnecting logged ✅ save-all logged …/world/players/data

pr_ready

pr_ready (tools/pr_ready.py --quick --base db813a1c3879cd7334b6d6e11b9ef2eeb175a49f at 6a5380383f, 4 min 9 s)

Check Result
Scope ✅ 11 files, +264 −25
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 610 passed (45 s)
rustfmt ✅ (10 s)
clippy ✅ (1 min 52 s)
tests: horizon-client, horizon-client-lib ✅ 2001 passed (56 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
mod API up to date ✅ (23 s)
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
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Part of #4953.

🤖 Generated with Dyna.


🔄 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/6911 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `v2/ses_01M6DKF0Z8BE7TF075HX2BZ8T2-a14d111139e2` --- ### 📝 Commits (10+) - [`146bb12`](https://github.com/horizon-rust/horizon/commit/146bb12bcf64adb56855b77d1191be0e3b478d61) Add native_player_clone (PlayerEvent.Clone) - [`c5e5ac8`](https://github.com/horizon-rust/horizon/commit/c5e5ac8df00ab307146f7e5a2e3ec8e43509e1f2) Add native_player_load_from_file (PlayerEvent.LoadFromFile) - [`1c4209f`](https://github.com/horizon-rust/horizon/commit/1c4209f298f38975c7d99bbb3834b06988dcca8e) Add native_player_save_to_file (PlayerEvent.SaveToFile) - [`60ca8bc`](https://github.com/horizon-rust/horizon/commit/60ca8bcd1bec8eec6fecaafb6cd87a9f9b23c7a4) Fix native player file hooks: qualify Path, fire owner SaveToFile after level.dat write - [`d311c4d`](https://github.com/horizon-rust/horizon/commit/d311c4d882d4f4d33f8bebdbc2a2532cafc8f551) Create the player directory before the player file hooks run - [`b953491`](https://github.com/horizon-rust/horizon/commit/b95349183ed96736d33603a4983211a83062ff1a) Document that the player directory exists for the file hooks - [`a9f3a84`](https://github.com/horizon-rust/horizon/commit/a9f3a8439992fba54734378e4c668c311472380a) Document the save hook's directory too - [`31c6f2f`](https://github.com/horizon-rust/horizon/commit/31c6f2f549255a94931e7054cf1bf710548e6115) Keep the player file path a pure builder and create the directory once per save loop - [`e409dcd`](https://github.com/horizon-rust/horizon/commit/e409dcdedd09a74f03bb72c4408b66a65cba4a24) Fix player_save_to_file docs: guests not heard on integrated autosaves - [`6a53803`](https://github.com/horizon-rust/horizon/commit/6a5380383f14f20781303c5ed24012029c2c2a69) Regenerate the mod API ### 📊 Changes **11 files changed** (+264 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+8 -1) 📝 `crates/horizon-client/src/game/lan.rs` (+20 -20) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+4 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+42 -0) 📝 `crates/horizon-client/src/game/server_travel.rs` (+6 -0) 📝 `crates/horizon-client/src/lan/playerdata.rs` (+15 -4) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+104 -0) 📝 `docs/native-mods.md` (+17 -0) ➕ `tools/native-hook-fragments/native_player_clone.json` (+16 -0) ➕ `tools/native-hook-fragments/native_player_load_from_file.json` (+16 -0) ➕ `tools/native-hook-fragments/native_player_save_to_file.json` (+16 -0) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Adds three server-side listen hooks matching NeoForge's `PlayerEvent.Clone`, `PlayerEvent.LoadFromFile` and `PlayerEvent.SaveToFile`. None is cancellable. - `native_player_clone(player, name, was_death)`: fires after the data copy and before respawn placement, on death (`was_death = true`, the end of `restoreFrom`) and on the End exit (`false`, `PlayerList.respawn` keeping all data). - `native_player_load_from_file(player, name, directory)`: fires when a player's data is read and applied, before the player is placed, with the `players/data` directory. - `native_player_save_to_file(player, name, directory)`: fires when a LAN guest leaves or the world closes, when the dedicated server saves everyone, and for the integrated owner once `level.dat` is written. On an integrated server an autosave saves only the owner, so guests are heard on leave or world close; `docs/native-mods.md` says so. `playerdata::directory` creates `players/data` on first use, as `PlayerDataStorage`'s constructor does, so a mod can write next to the player file. `store_owner` now returns the stored owner so the save hook fires only when the owner was written. ## Tested in game Built through the launcher (native-build, dev profile) with a throwaway trait mod on a throwaway branch of https://github.com/arismoko/horizon-machine-sample (the recommended end-to-end route, used here). The build was one test merge of this PR with the batch's other hooks PRs (#6910, #6912) on main db813a1c3. Each hook logged a `WAVE_PROOF` line. | Hook | Server thread (integrated, LAN) | Dedicated server | | --- | --- | --- | | `player_clone` | ✅ `/kill` and respawn logged `was_death = true`; leaving the End through the exit portal logged `false` | ✅ both | | `player_load_from_file` | ✅ the owner's join and a LAN guest's join (a second client) each logged `…/saves/W1/players/data` | ✅ a client join logged `…/world/players/data` | | `player_save_to_file` | ✅ the owner's save logged; a LAN guest disconnecting logged | ✅ `save-all` logged `…/world/players/data` | ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base db813a1c3879cd7334b6d6e11b9ef2eeb175a49f` at 6a5380383f, 4 min 9 s) | Check | Result | | --- | --- | | Scope | ✅ 11 files, +264 −25 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 610 passed (45 s) | | rustfmt | ✅ (10 s) | | clippy | ✅ (1 min 52 s) | | tests: horizon-client, horizon-client-lib | ✅ 2001 passed (56 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (23 s) | | 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 | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Part of #4953. 🤖 Generated with Dyna. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:35:24 +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#7186
No description provided.