[PR #6201] [MERGED] Native mods: the client's level made and dropped (LevelEvent on the client) #6713

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

📋 Pull Request Information

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

Base: main ← Head: mods/native-client-level-events


📝 Commits (1)

  • ba04f50 Native mods: the client's level made and dropped (LevelEvent on the client)

📊 Changes

3 files changed (+55 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game/native_hooks.rs (+18 -0)
📝 crates/horizon-client/src/game/remote.rs (+17 -0)
➕ tools/native-hook-fragments/client_level_events.json (+20 -0)

📄 Description

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

What and why

The client half of #6154 (part of #4953, "Level load and unload for each dimension (LevelEvent)"); #6163 is the server half. NeoForge posts LevelEvent on both sides, and client mods use it to set up and drop what they keep per level (render caches, a minimap's data). Independent of #6163: each has its own fragment.

Two client hook points, API from tools/native-hook-fragments/client_level_events.json:

  • native_client_level_load(dimension): in enter_remote_dimension once a new client level is made: on joining a server (single player's own server thread included) and on a dimension change. A respawn in the same dimension keeps the level and fires nothing.
  • native_client_level_unload(dimension): the old level, right after the new one's load (as NeoForge's Minecraft.setLevel patch tells it after the ClientLevel constructor's Load), and in leave_server before the connection goes (Minecraft.disconnect).

Remote keeps the dimension it told, so each load has one unload. Quitting the game outright doesn't tell it (said in the doc comment).

Kind

  • feature: something new for players (mod authors)

Vanilla reference

NeoForge's patches: ClientLevel's constructor posts LevelEvent.Load; Minecraft.setLevel posts LevelEvent.Unload for the level it replaces, and Minecraft.disconnect / clearClientLevel for the one it drops. Horizon's ports: ClientPacketListener.handleLogin / handleRespawn → enter_remote_dimension, Minecraft.disconnect → leave_server.

Other projects' code

None.

Proof in the real game

Engine from this branch with throwaway eprintln!s in the two hooks (not in this PR). Joined, execute in minecraft:the_nether run tp, then horizon-ctl disconnect.

Single player on the server thread (horizon-ctl launch --world L --offscreen; back on the title screen after the disconnect):

TESTHOOK client_level_load minecraft:overworld
TESTHOOK client_level_load minecraft:the_nether
TESTHOOK client_level_unload minecraft:overworld
TESTHOOK client_level_unload minecraft:the_nether

A client of a dedicated server, the same steps (the server's console ran the tp): the same four lines on the client, none on the server.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at 9f683428a, 2 min 40 s)

Check Result
Scope ✅ 3 files, +55 −0
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 586 passed (44 s)
rustfmt ✅ (12 s)
clippy ✅ (42 s)
tests: horizon-client ✅ 1803 passed (1 min 0 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

🤖 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/6201 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `mods/native-client-level-events` --- ### 📝 Commits (1) - [`ba04f50`](https://github.com/horizon-rust/horizon/commit/ba04f50325eab2c3045518f6808ca1f858a27b56) Native mods: the client's level made and dropped (LevelEvent on the client) ### 📊 Changes **3 files changed** (+55 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/native_hooks.rs` (+18 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+17 -0) ➕ `tools/native-hook-fragments/client_level_events.json` (+20 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. ## What and why The client half of #6154 (part of #4953, "Level load and unload for each dimension (`LevelEvent`)"); #6163 is the server half. NeoForge posts `LevelEvent` on both sides, and client mods use it to set up and drop what they keep per level (render caches, a minimap's data). Independent of #6163: each has its own fragment. Two client hook points, API from `tools/native-hook-fragments/client_level_events.json`: - `native_client_level_load(dimension)`: in `enter_remote_dimension` once a new client level is made: on joining a server (single player's own server thread included) and on a dimension change. A respawn in the same dimension keeps the level and fires nothing. - `native_client_level_unload(dimension)`: the old level, right after the new one's load (as NeoForge's `Minecraft.setLevel` patch tells it after the `ClientLevel` constructor's `Load`), and in `leave_server` before the connection goes (`Minecraft.disconnect`). `Remote` keeps the dimension it told, so each load has one unload. Quitting the game outright doesn't tell it (said in the doc comment). ## Kind - [x] feature: something new for players (mod authors) ## Vanilla reference NeoForge's patches: `ClientLevel`'s constructor posts `LevelEvent.Load`; `Minecraft.setLevel` posts `LevelEvent.Unload` for the level it replaces, and `Minecraft.disconnect` / `clearClientLevel` for the one it drops. Horizon's ports: `ClientPacketListener.handleLogin` / `handleRespawn` → `enter_remote_dimension`, `Minecraft.disconnect` → `leave_server`. ## Other projects' code None. ## Proof in the real game Engine from this branch with throwaway `eprintln!`s in the two hooks (not in this PR). Joined, `execute in minecraft:the_nether run tp`, then `horizon-ctl disconnect`. Single player on the server thread (`horizon-ctl launch --world L --offscreen`; back on the title screen after the disconnect): ``` TESTHOOK client_level_load minecraft:overworld TESTHOOK client_level_load minecraft:the_nether TESTHOOK client_level_unload minecraft:overworld TESTHOOK client_level_unload minecraft:the_nether ``` A client of a dedicated server, the same steps (the server's console ran the `tp`): the same four lines on the client, none on the server. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at 9f683428a, 2 min 40 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +55 −0 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 586 passed (44 s) | | rustfmt | ✅ (12 s) | | clippy | ✅ (42 s) | | tests: horizon-client | ✅ 1803 passed (1 min 0 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 | 🤖 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:25:21 +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#6713
No description provided.