[PR #5159] [CLOSED] Native mods: a server-starting phase before any world loads #6107

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5159
Author: @sirrayi
Created: 10/31/2026
Status: ❌ Closed

Base: main ← Head: feat/native-server-starting


📝 Commits (1)

  • 46d09fa Native mods: a server-starting phase before any world loads

📊 Changes

3 files changed (+62 additions, -6 deletions)

View changed files

📝 crates/horizon-client/src/game/native_hooks.rs (+7 -1)
📝 crates/horizon-client/src/game/native_lifecycle.rs (+50 -5)
📝 docs/native-mods.md (+5 -0)

📄 Description

🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi themselves.

What and why

Fixes #5152, one item from #4953. native_world_lifecycle reported only after load_world returned, so a
native mod had no equivalent of NeoForge's ServerStartingEvent — the moment the server exists and no world
does yet, which is when a mod registers what the world will need before it loads.

Nothing had to be invented for the firing point: both server paths already call
native_lifecycle_open_started() immediately before load_world (game/integrated.rs, game/dedicated.rs),
and NativeLifecycle::begin_open already assigns the open attempt's epoch right there (a fresh process-wide
epoch, never reused). So the new phase fires from that call, carrying the same NativeLifecycleContext as the
WorldOpenReady or WorldOpenFailed that follows it:

  • a mod can pair ServerStarting with the world's own phases by epoch;
  • a retry after a failed open is a fresh start (new epoch), not a second ServerStarting for the same one;
  • reads stay off — permits_read only allows native_server_block inside a server tick's hook body, and the
    new test pins that ServerStarting's context does not qualify.

API 41 (mods that use it need "hooks": 41). No new hook point, so native-hooks.json is unchanged and the
launcher's catalog test still matches.

Kind

  • feature: something new for players (listed under New in the release notes)

Vanilla reference

NeoForge's ServerStartingEvent for the contract — fired on the server thread once the server exists and
before any world is loaded, exactly where Horizon's two call sites sit relative to load_world. Vanilla itself
has no such event; every hook body here is empty, so with no native mods nothing changes.

Self-check

cargo fmt --all -- --check                                     ✅
cargo clippy -p horizon-client --bins --tests -- -D warnings    ✅
cargo test -p horizon-client --bins native_lifecycle            10 passed; 0 failed
cargo test -p horizon-client --bins catalog_matches_hook_points 1 passed
cargo test -p horizon-client --bins lifecycle_source_stays_hookable  (in the same run) ✅

Exit codes read with set -o pipefail.

The two new tests are server_starting_belongs_to_the_open_that_follows (the starting context equals the
ready context of the same attempt, and a retry after a failed open has a different epoch) and
server_starting_is_not_a_read_scope (permits_read is false for it). Both drive NativeLifecycle, the state
machine, so they need no game and no assets — the module already had seven tests of that shape.

What is not covered

A test cannot watch a real server start; the hook body is empty by construction, so what is verifiable is the
ordering and the epoch pairing, which is what the new tests do. A mod author checking it in game sees
ServerStarting in the hook log before the first WorldOpenReady, on the same epoch, on the single-player
server thread and on a dedicated server.


🔄 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/5159 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/31/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/native-server-starting` --- ### 📝 Commits (1) - [`46d09fa`](https://github.com/horizon-rust/horizon/commit/46d09fa69dd8440ce9e3e0451cac657207786a0d) Native mods: a server-starting phase before any world loads ### 📊 Changes **3 files changed** (+62 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/native_hooks.rs` (+7 -1) 📝 `crates/horizon-client/src/game/native_lifecycle.rs` (+50 -5) 📝 `docs/native-mods.md` (+5 -0) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi themselves. ## What and why Fixes #5152, one item from #4953. `native_world_lifecycle` reported only *after* `load_world` returned, so a native mod had no equivalent of NeoForge's `ServerStartingEvent` — the moment the server exists and no world does yet, which is when a mod registers what the world will need before it loads. Nothing had to be invented for the firing point: both server paths already call `native_lifecycle_open_started()` immediately before `load_world` (`game/integrated.rs`, `game/dedicated.rs`), and `NativeLifecycle::begin_open` already assigns the open attempt's epoch right there (a fresh process-wide epoch, never reused). So the new phase fires from that call, carrying the same `NativeLifecycleContext` as the `WorldOpenReady` or `WorldOpenFailed` that follows it: - a mod can pair `ServerStarting` with the world's own phases by epoch; - a retry after a failed open is a **fresh** start (new epoch), not a second `ServerStarting` for the same one; - reads stay off — `permits_read` only allows `native_server_block` inside a server tick's hook body, and the new test pins that `ServerStarting`'s context does not qualify. API 41 (mods that use it need `"hooks": 41`). No new hook point, so `native-hooks.json` is unchanged and the launcher's catalog test still matches. ## Kind - [x] feature: something new for players (listed under New in the release notes) ## Vanilla reference NeoForge's `ServerStartingEvent` for the contract — fired on the server thread once the server exists and before any world is loaded, exactly where Horizon's two call sites sit relative to `load_world`. Vanilla itself has no such event; every hook body here is empty, so with no native mods nothing changes. ## Self-check ``` cargo fmt --all -- --check ✅ cargo clippy -p horizon-client --bins --tests -- -D warnings ✅ cargo test -p horizon-client --bins native_lifecycle 10 passed; 0 failed cargo test -p horizon-client --bins catalog_matches_hook_points 1 passed cargo test -p horizon-client --bins lifecycle_source_stays_hookable (in the same run) ✅ ``` Exit codes read with `set -o pipefail`. The two new tests are `server_starting_belongs_to_the_open_that_follows` (the starting context equals the ready context of the same attempt, and a retry after a failed open has a different epoch) and `server_starting_is_not_a_read_scope` (`permits_read` is false for it). Both drive `NativeLifecycle`, the state machine, so they need no game and no assets — the module already had seven tests of that shape. ## What is not covered A test cannot watch a real server start; the hook body is empty by construction, so what is verifiable is the ordering and the epoch pairing, which is what the new tests do. A mod author checking it in game sees `ServerStarting` in the hook log before the first `WorldOpenReady`, on the same epoch, on the single-player server thread and on a dedicated server. --- <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:51 +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#6107
No description provided.