[GH-ISSUE #6154] Native mods: a level loading and unloading, LevelEvent.Load / Unload #1996

Closed
opened 2026-11-02 15:51:13 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @levzzz5154 on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6154

Originally assigned to: @levzzz5154 on GitHub.

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

Part of #4953 ("Level load and unload for each dimension (LevelEvent)").

A native mod that keeps state per dimension (a pipe network, a machine registry, a per-level cache) has no point to create it when a level comes and drop it when the level goes. native_world_lifecycle speaks of the whole world, and native_chunk_load / native_chunk_unload of chunks.

Vanilla and NeoForge 26.3:

  • LevelEvent.Load is posted in MinecraftServer.createLevels: the Overworld's after it is created and its saved data read, before setInitialSpawn; each other dimension's right after levels.put. So it comes before the level's spawn chunks.
  • LevelEvent.Unload is posted in MinecraftServer.stopServer right after each level.close(), after saveAllChunks.

Horizon's server opens a level other than the first when someone first enters it (enter_level → open_level) and closes one nobody has been in for 300 ticks (close_idle_levels, docs/server-levels.md). So the hooks follow Horizon's levels:

  • native_level_load(dimension): the first level at the end of finish_open_world, before any of its chunks; every other level when enter_level opens it, with it in place.
  • native_level_unload(dimension): a level closed for being idle, after its last save; at the server's stop every level still open, after the final save and before WorldCloseFinal. A failed open or a failed server loop tells it too, so every load is paired with one unload.

Server-side only (the single player's server thread and a dedicated server). The client side of LevelEvent (a ClientLevel created or dropped) is a separate item. API from a fragment.

Originally created by @levzzz5154 on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6154 Originally assigned to: @levzzz5154 on GitHub. > 🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. Part of #4953 ("Level load and unload for each dimension (`LevelEvent`)"). A native mod that keeps state per dimension (a pipe network, a machine registry, a per-level cache) has no point to create it when a level comes and drop it when the level goes. `native_world_lifecycle` speaks of the whole world, and `native_chunk_load` / `native_chunk_unload` of chunks. Vanilla and NeoForge 26.3: - `LevelEvent.Load` is posted in `MinecraftServer.createLevels`: the Overworld's after it is created and its saved data read, before `setInitialSpawn`; each other dimension's right after `levels.put`. So it comes before the level's spawn chunks. - `LevelEvent.Unload` is posted in `MinecraftServer.stopServer` right after each `level.close()`, after `saveAllChunks`. Horizon's server opens a level other than the first when someone first enters it (`enter_level` → `open_level`) and closes one nobody has been in for 300 ticks (`close_idle_levels`, docs/server-levels.md). So the hooks follow Horizon's levels: - `native_level_load(dimension)`: the first level at the end of `finish_open_world`, before any of its chunks; every other level when `enter_level` opens it, with it in place. - `native_level_unload(dimension)`: a level closed for being idle, after its last save; at the server's stop every level still open, after the final save and before `WorldCloseFinal`. A failed open or a failed server loop tells it too, so every load is paired with one unload. Server-side only (the single player's server thread and a dedicated server). The client side of `LevelEvent` (a `ClientLevel` created or dropped) is a separate item. API from a fragment.
Author
Owner

@levzzz5154 commented on GitHub (Nov 1, 2026):

/claim

<!-- gh-comment-id:6561451068 --> @levzzz5154 commented on GitHub (Nov 1, 2026): /claim
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#1996
No description provided.