[PR #5140] [MERGED] Native mods: hook points for the server starting and stopping (API next) #6100

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

📋 Pull Request Information

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

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


📝 Commits (5)

  • cf57da8 Native mods: hook points for the server starting and stopping
  • e46f743 Merge remote-tracking branch 'hr/main' into mods/native-server-starting
  • 85be6c2 Merge remote-tracking branch 'hr/main' into mods/native-server-starting
  • 2283c9c Docs: one blank line before the bundle section
  • 46a0cf3 Merge remote-tracking branch 'hr/main' into mods/native-server-starting

📊 Changes

5 files changed (+55 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game/dedicated.rs (+4 -0)
📝 crates/horizon-client/src/game/integrated.rs (+4 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+24 -1)
📝 docs/native-mods.md (+7 -0)
📝 native-hooks.json (+16 -0)

📄 Description

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

What and why

Fixes #5138. Part of #4953 and #3911 (Mods). NATIVE_HOOKS_API 40 → 41 (API next: the number is set at merge).

Two server-side hook points, in the catalog with neoforge/side/cancellable as native-hooks-neoforge.md proposes:

  • native_server_about_to_start(dedicated): before the worlds load, NeoForge's ServerAboutToStartEvent ("Called before the server begins loading anything", javadoc). Single player: once Play is pressed, at the start of integrated_open. Dedicated: after "Preparing level", before load_world. Each is followed by native_world_lifecycle's WorldOpenReady or WorldOpenFailed.
  • native_server_stopping(dedicated): an orderly stop begins, NeoForge's ServerStoppingEvent ("Called when the server begins an orderly shutdown, before ServerStoppedEvent", javadoc). At the start of stop_integrated / stop_dedicated, with the worlds loaded and the players still connected and not yet saved. WorldCloseFinal follows. A server whose loop fails never runs the stop, so it reports WorldCloseFailed instead.

Neither cancels. dedicated tells the two servers apart. A client of a remote server fires neither.

The only overlap with an open PR is #5131 (Qwerner88880's chunk and player hooks), which also edits the two stop functions. Both are one-line additions, so whichever merges second has a trivial rebase.

Kind

  • feature: something new for players (listed under New in the release notes)
  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only hook points, placed at vanilla 26.3's own steps:

  • MinecraftServer.runServer → initServer: DedicatedServer.initServer logs "Preparing level" and then calls loadLevel (createLevels, prepareLevels). The start hook fires at loadLevel's start.
  • MinecraftServer.stopServer begins with "Stopping server" and then playerList.saveAll() / removeAll(). The stop hook fires before both.

Names and contracts come only from NeoForge's public javadoc (linked above). No mod's source is used.

Other projects' code

none

Tested in the game

A throwaway eprintln! in both hooks and in native_world_lifecycle (removed before the commit). Fresh mktemp -d homes, HORIZON_NO_AUDIO=1, --profile fast.

Run Log, in order
Single player (server thread): horizon-ctl launch --world A --offscreen, Save and Quit to Title, open B, quit about_to_start dedicated=false players=0 → WorldOpenReady → stopping dedicated=false players=1 → WorldCloseFinal, then the same four again for world B
Dedicated (--dedicated --nogui, offline) with two horizon-ctl --offscreen clients: Alex and Steve join, Alex disconnects, stop with Steve on "Preparing level" → about_to_start dedicated=true players=0 → WorldOpenReady → Alex/Steve joined → Alex left → stopping dedicated=true players=1 → "Stopping server" → "Saving players" → WorldCloseFinal
The two clients' own windows nothing (a client of a remote server fires neither)

Unit: native_hooks::tests (catalog_matches_hook_points, hook_points_stay_hookable) pass.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at 01bbb4c65, 2 min 18 s)

Check Result
Scope ✅ 5 files, +55 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (25 s)
rustfmt ✅ (5 s)
clippy ✅ (1 min 6 s)
tests: horizon-client ✅ 1340 passed (41 s)
doc tests ✅ 0 passed (1 s)
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses

🤖 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/5140 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/native-server-starting` --- ### 📝 Commits (5) - [`cf57da8`](https://github.com/horizon-rust/horizon/commit/cf57da8885635aaccaade77bb3362b4b17ac013e) Native mods: hook points for the server starting and stopping - [`e46f743`](https://github.com/horizon-rust/horizon/commit/e46f743fa4d9f475531e5bd0774c0aa8549a1f82) Merge remote-tracking branch 'hr/main' into mods/native-server-starting - [`85be6c2`](https://github.com/horizon-rust/horizon/commit/85be6c20bbfa63d85f9e371ec44573c977ab14fe) Merge remote-tracking branch 'hr/main' into mods/native-server-starting - [`2283c9c`](https://github.com/horizon-rust/horizon/commit/2283c9cc2501fb6a1ae1bde66fbf5b0aadf5a325) Docs: one blank line before the bundle section - [`46a0cf3`](https://github.com/horizon-rust/horizon/commit/46a0cf3eea870052d64daed9decc24fc0f41ca81) Merge remote-tracking branch 'hr/main' into mods/native-server-starting ### 📊 Changes **5 files changed** (+55 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/dedicated.rs` (+4 -0) 📝 `crates/horizon-client/src/game/integrated.rs` (+4 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+24 -1) 📝 `docs/native-mods.md` (+7 -0) 📝 `native-hooks.json` (+16 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. ## What and why Fixes #5138. Part of #4953 and #3911 (Mods). `NATIVE_HOOKS_API` 40 → 41 (**API next**: the number is set at merge). Two server-side hook points, in the catalog with `neoforge`/`side`/`cancellable` as [native-hooks-neoforge.md](docs/native-hooks-neoforge.md) proposes: - **`native_server_about_to_start(dedicated)`**: before the worlds load, NeoForge's `ServerAboutToStartEvent` ("Called before the server begins loading anything", [javadoc](https://mcstreetguy.github.io/NeoForgeJavaDocs/1.20.3-20.3.8/net/neoforged/neoforge/event/server/ServerAboutToStartEvent.html)). Single player: once Play is pressed, at the start of `integrated_open`. Dedicated: after "Preparing level", before `load_world`. Each is followed by `native_world_lifecycle`'s `WorldOpenReady` or `WorldOpenFailed`. - **`native_server_stopping(dedicated)`**: an orderly stop begins, NeoForge's `ServerStoppingEvent` ("Called when the server begins an orderly shutdown, before ServerStoppedEvent", [javadoc](https://mcstreetguy.github.io/NeoForgeJavaDocs/1.20.3-20.3.8/net/neoforged/neoforge/event/server/ServerStoppingEvent.html)). At the start of `stop_integrated` / `stop_dedicated`, with the worlds loaded and the players still connected and not yet saved. `WorldCloseFinal` follows. A server whose loop fails never runs the stop, so it reports `WorldCloseFailed` instead. Neither cancels. `dedicated` tells the two servers apart. A client of a remote server fires neither. The only overlap with an open PR is #5131 (Qwerner88880's chunk and player hooks), which also edits the two stop functions. Both are one-line additions, so whichever merges second has a trivial rebase. ## Kind - [x] feature: something new for players (listed under New in the release notes) - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only hook points, placed at vanilla 26.3's own steps: - `MinecraftServer.runServer` → `initServer`: `DedicatedServer.initServer` logs "Preparing level" and then calls `loadLevel` (`createLevels`, `prepareLevels`). The start hook fires at `loadLevel`'s start. - `MinecraftServer.stopServer` begins with "Stopping server" and then `playerList.saveAll()` / `removeAll()`. The stop hook fires before both. Names and contracts come only from NeoForge's public javadoc (linked above). No mod's source is used. ## Other projects' code none ## Tested in the game A throwaway `eprintln!` in both hooks and in `native_world_lifecycle` (removed before the commit). Fresh `mktemp -d` homes, `HORIZON_NO_AUDIO=1`, `--profile fast`. | Run | Log, in order | |---|---| | Single player (server thread): `horizon-ctl launch --world A --offscreen`, Save and Quit to Title, `open B`, `quit` | `about_to_start dedicated=false players=0` → `WorldOpenReady` → `stopping dedicated=false players=1` → `WorldCloseFinal`, then the same four again for world B | | Dedicated (`--dedicated --nogui`, offline) with two `horizon-ctl --offscreen` clients: Alex and Steve join, Alex disconnects, `stop` with Steve on | "Preparing level" → `about_to_start dedicated=true players=0` → `WorldOpenReady` → Alex/Steve joined → Alex left → `stopping dedicated=true players=1` → "Stopping server" → "Saving players" → `WorldCloseFinal` | | The two clients' own windows | nothing (a client of a remote server fires neither) | Unit: `native_hooks::tests` (`catalog_matches_hook_points`, `hook_points_stay_hookable`) pass. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at 01bbb4c65, 2 min 18 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +55 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (25 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 6 s) | | tests: horizon-client | ✅ 1340 passed (41 s) | | doc tests | ✅ 0 passed (1 s) | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | 🤖 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 06:11: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#6100
No description provided.