[PR #5131] [MERGED] Native mods: hook points for chunks and players coming and going (API next) #6095

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

📋 Pull Request Information

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

Base: main ← Head: hooks-chunk-player


📝 Commits (5)

  • 815de41 Native mods: hook points for chunks and players coming and going
  • 9b1f9db Merge main; the chunk and player hooks as an API fragment
  • 1aedc16 Merge remote-tracking branch 'hr/main' into qw-5131
  • a58ad8b Merge remote-tracking branch 'hr/main' into qw-5131
  • 6491049 Merge remote-tracking branch 'origin/main' into sweep/5131-m3

📊 Changes

12 files changed (+207 additions, -18 deletions)

View changed files

📝 crates/horizon-client-render/src/chunk.rs (+4 -0)
📝 crates/horizon-client-render/src/streaming.rs (+12 -1)
📝 crates/horizon-client-render/src/world.rs (+4 -0)
📝 crates/horizon-client/src/game.rs (+2 -0)
📝 crates/horizon-client/src/game/dedicated.rs (+2 -0)
📝 crates/horizon-client/src/game/integrated.rs (+2 -0)
📝 crates/horizon-client/src/game/lan.rs (+35 -5)
📝 crates/horizon-client/src/game/levels.rs (+3 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+81 -0)
📝 crates/horizon-client/tests/generation_saves.rs (+40 -11)
📝 docs/native-hooks-neoforge.md (+0 -1)
➕ tools/native-hook-fragments/chunks_players.json (+22 -0)

📄 Description

🤖 Opened by Qwerner88880's AI agent (ZCode, GLM-5.3), not by Qwerner88880 personally.

What and why

Fixes #5128. Part of #3911 (Mods). NATIVE_HOOKS_API 40 → 42 (41 goes to the item-handler branch if it merges first; the number is the next free one and moves if another branch merges first).

Four server-side hook points, in the catalog with side/cancellable/the NeoForge event they mirror:

  • native_chunk_load(dimension, chunk, new): after a chunk joins the level. new is true when it was just generated, false when it came from the save. A level that closes empty reports its chunks first if it opens again.
  • native_chunk_unload(dimension, chunk): when a chunk leaves — streamed out, or the level closing because it ran empty (close_idle_levels).
  • native_player_logged_in(player, name): on HostEvent::Joined, whichever way the level runs.
  • native_player_logged_out(player, name): exactly once per joined player, however they leave: a disconnect, a kick, stop_dedicated, stop_integrated, lan_close, and the Err paths of run_dedicated/run_integrated. At a stop the hooks run before the save with the players still listed, and the last mod messages (native_players_leaving flushes them) still go out.

Loads and unloads are told apart from saved columns (Chunk::generated set at Job::Finish), a chunk generated at the moment players leave is still told (Streaming::dropped_new), and an error during a level pass doesn't skip the players' exit. None of the four cancels anything; they observe.

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; they sit where vanilla has ChunkEvent.Load/Unload and PlayerLoggedInEvent/LoggedOutEvent (the NeoForge events the catalog names), and where vanilla's server tells its own listeners a chunk or a player came and went. No vanilla code is used, so there is nothing to jar-check; parity is left to CI.

Other projects' code

none

Tests

Unit: a_new_column_is_told_apart_from_a_saved_one (generation_saves.rs), run with the vanilla data linked in — a new column loads with new: true, a saved one without (it silently skips without .local data).

Live, on this branch (at 4a85a05c6; the final 815de4119 adds one doc-comment line on top): a throwaway mixin bundle on a dedicated server with two horizon-ctl --offscreen clients (Alex and Steve) and a single-player world, fresh temp folders, HORIZON_NO_AUDIO=1. RESULT: 33 checks, 0 failures. Covers: each join told once with the player already listed and a login-hook message delivered to the client; the client's own copy telling nothing; chunks around spawn told, a new world's chunks new; walking away unloading and loading with nothing told twice or left over; a chest's block entity still there when its chunk left and its items intact on return, loading from the save, not as new; a disconnect, a kick and the server's stop each told exactly once, logins and logouts pairing up; the stop telling before it saves, with the players still listed and the last mod message sent; single player telling its owner's join, chunks and closing.

Not verified live: the Err paths of run_dedicated/run_integrated (they share the stop code the stop check exercises).

Self-check

pr_ready (tools/pr_ready.py --quick on DESKTOP-H7P5E7K, against origin/main at 13ce6bcc6, 2 min 35 s)

Check Result
Scope ✅ 13 files, +203 −14
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (1 min 22 s)
rustfmt ✅ (11 s)
clippy ✅ (11 s)
tests: horizon-client, horizon-client-render ✅ 2042 passed (43 s)
doc tests ✅ 0 passed (2 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 ➖ 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)

The unit test above was run on its own with the vanilla data linked in, outside pr_ready (without the data it silently skips).

🤖 Generated with ZCode (GLM-5.3)


🔄 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/5131 **Author:** [@Qwerner88880](https://github.com/Qwerner88880) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `hooks-chunk-player` --- ### 📝 Commits (5) - [`815de41`](https://github.com/horizon-rust/horizon/commit/815de4119d2f984e2c97e67c163c705cc79b7be4) Native mods: hook points for chunks and players coming and going - [`9b1f9db`](https://github.com/horizon-rust/horizon/commit/9b1f9dbf836286401f39ec5c89e841d467e675fb) Merge main; the chunk and player hooks as an API fragment - [`1aedc16`](https://github.com/horizon-rust/horizon/commit/1aedc168c7d23aa60f874ef4f5c8332e1ee5065d) Merge remote-tracking branch 'hr/main' into qw-5131 - [`a58ad8b`](https://github.com/horizon-rust/horizon/commit/a58ad8b2eec2af5b8c7ec888a74faabf421e8f5e) Merge remote-tracking branch 'hr/main' into qw-5131 - [`6491049`](https://github.com/horizon-rust/horizon/commit/6491049437e9a3b78ede6e9f94b9d4dca67268b6) Merge remote-tracking branch 'origin/main' into sweep/5131-m3 ### 📊 Changes **12 files changed** (+207 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/chunk.rs` (+4 -0) 📝 `crates/horizon-client-render/src/streaming.rs` (+12 -1) 📝 `crates/horizon-client-render/src/world.rs` (+4 -0) 📝 `crates/horizon-client/src/game.rs` (+2 -0) 📝 `crates/horizon-client/src/game/dedicated.rs` (+2 -0) 📝 `crates/horizon-client/src/game/integrated.rs` (+2 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+35 -5) 📝 `crates/horizon-client/src/game/levels.rs` (+3 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+81 -0) 📝 `crates/horizon-client/tests/generation_saves.rs` (+40 -11) 📝 `docs/native-hooks-neoforge.md` (+0 -1) ➕ `tools/native-hook-fragments/chunks_players.json` (+22 -0) </details> ### 📄 Description > 🤖 Opened by Qwerner88880's AI agent (ZCode, GLM-5.3), not by Qwerner88880 personally. ## What and why Fixes #5128. Part of #3911 (Mods). `NATIVE_HOOKS_API` 40 → **42** (41 goes to the item-handler branch if it merges first; the number is the next free one and moves if another branch merges first). Four server-side hook points, in the catalog with `side`/`cancellable`/the NeoForge event they mirror: - **`native_chunk_load(dimension, chunk, new)`:** after a chunk joins the level. `new` is true when it was just generated, false when it came from the save. A level that closes empty reports its chunks first if it opens again. - **`native_chunk_unload(dimension, chunk)`:** when a chunk leaves — streamed out, or the level closing because it ran empty (`close_idle_levels`). - **`native_player_logged_in(player, name)`:** on `HostEvent::Joined`, whichever way the level runs. - **`native_player_logged_out(player, name)`:** exactly once per joined player, however they leave: a disconnect, a kick, `stop_dedicated`, `stop_integrated`, `lan_close`, and the `Err` paths of `run_dedicated`/`run_integrated`. At a stop the hooks run before the save with the players still listed, and the last mod messages (`native_players_leaving` flushes them) still go out. Loads and unloads are told apart from saved columns (`Chunk::generated` set at `Job::Finish`), a chunk generated at the moment players leave is still told (`Streaming::dropped_new`), and an error during a level pass doesn't skip the players' exit. None of the four cancels anything; they observe. ## 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; they sit where vanilla has `ChunkEvent.Load`/`Unload` and `PlayerLoggedInEvent`/`LoggedOutEvent` (the NeoForge events the catalog names), and where vanilla's server tells its own listeners a chunk or a player came and went. No vanilla code is used, so there is nothing to jar-check; parity is left to CI. ## Other projects' code none ## Tests **Unit:** `a_new_column_is_told_apart_from_a_saved_one` (`generation_saves.rs`), run with the vanilla data linked in — a new column loads with `new: true`, a saved one without (it silently skips without `.local` data). **Live, on this branch** (at `4a85a05c6`; the final `815de4119` adds one doc-comment line on top): a throwaway mixin bundle on a dedicated server with two `horizon-ctl --offscreen` clients (Alex and Steve) and a single-player world, fresh temp folders, `HORIZON_NO_AUDIO=1`. RESULT: 33 checks, 0 failures. Covers: each join told once with the player already listed and a login-hook message delivered to the client; the client's own copy telling nothing; chunks around spawn told, a new world's chunks new; walking away unloading and loading with nothing told twice or left over; a chest's block entity still there when its chunk left and its items intact on return, loading from the save, not as new; a disconnect, a kick and the server's stop each told exactly once, logins and logouts pairing up; the stop telling before it saves, with the players still listed and the last mod message sent; single player telling its owner's join, chunks and closing. **Not verified live:** the `Err` paths of `run_dedicated`/`run_integrated` (they share the stop code the stop check exercises). ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on DESKTOP-H7P5E7K, against origin/main at 13ce6bcc6, 2 min 35 s) | Check | Result | | --- | --- | | Scope | ✅ 13 files, +203 −14 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (1 min 22 s) | | rustfmt | ✅ (11 s) | | clippy | ✅ (11 s) | | tests: horizon-client, horizon-client-render | ✅ 2042 passed (43 s) | | doc tests | ✅ 0 passed (2 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 | ➖ 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) | The unit test above was run on its own with the vanilla data linked in, outside `pr_ready` (without the data it silently skips). 🤖 Generated with ZCode (GLM-5.3) --- <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:36 +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#6095
No description provided.