[PR #5146] [MERGED] Native mods: the server level's random (API next) #6099

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/5146
Author: @levzzz5154
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @levzzz5154

Base: main ← Head: mods/native-level-random


📝 Commits (4)

  • ce12d07 Native mods: the server level's random (native_level_random)
  • 93d78e0 Merge remote-tracking branch 'hr/main' into mods/native-level-random
  • 5c7cf4f Merge remote-tracking branch 'hr/main' into mods/native-level-random
  • 6e09a5d Merge fix: close native_level_random

📊 Changes

3 files changed (+42 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game/levels.rs (+5 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+31 -1)
📝 docs/native-mods.md (+6 -0)

📄 Description

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

What and why

Fixes #5145. Part of #4953 and #3911 (Mods). NATIVE_HOOKS_API 40 → 41 (API next: the number is set at merge; #5140 also asks for the next one).

One server-level helper (not a hook point, so it has no catalog entry):

  • native_level_random(dimension) -> Option<&mut horizon_core::random::LegacyRandom> returns the level's own random, vanilla's Level.random (level.getRandom() in a Java mod). Horizon's ports of vanilla draw from this same World::random: an explosion's Util.shuffle(list, level.random), /bossbar add's Mth.createInsecureUUID(level.random), the initial spawn's shuffles. So a mod's draws move vanilla's later ones exactly as a Java mod's do. Mods draw with RandomSource (next_int_bound, next_float…).
  • It covers the level in place and a parked one (new Levels::parked_world_mut).
  • It is None on a client of a server, for an unknown dimension, and for a level that isn't open. In Horizon the Nether and the End open when someone first goes there and close after 300 empty ticks (close_idle_levels).

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

Level.random (protected final RandomSource random = RandomSource.create();) and Level.getRandom() in 26.3. Horizon keeps it as World::random, one per level. This PR draws nothing itself, so vanilla's draw order is unchanged until a mod draws.

Other projects' code

none

Tested in the game

A throwaway native_tick probe (removed before the commit) runs on each Game's 20th and 400th tick. For the three dimensions and minecraft:nope, it calls the helper, draws next_int_bound(100), prints the random's state before and after, and checks that the level in place gets self.world.random itself. Fresh mktemp -d homes, HORIZON_NO_AUDIO=1, --profile fast.

Run Result
Single player, overworld Server thread: overworld Some, is the world's random, state 423fe13c1ff9 → 009352df5310. Nether/End (not open yet) and nope: None. The window's own Game (a client of its server thread): None for all four
Single player, /execute in minecraft:the_nether run tp @s 0 80 0 Nether (in place) Some, is the world's random. The overworld (parked) is Some too: 7d615ba5313e → 8dfd98bbab71, and 380 ticks later it starts again from 8dfd98bbab71, so the draw stayed in the level's stream. The End stays None
Dedicated (--dedicated --nogui) with two horizon-ctl clients Server: overworld Some, is the world's random (a22e6ab1131b → 0af48b73648a), the others None. Both clients: None for all four

Unit: native_hooks::tests pass. hook_points_stay_hookable caught a matches! in the first version; the commit uses a plain match.

Self-check

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

Check Result
Scope ✅ 3 files, +42 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (24 s)
rustfmt ✅ (5 s)
clippy ✅ (5 s)
tests: horizon-client ✅ 1340 passed (9 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/5146 **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-level-random` --- ### 📝 Commits (4) - [`ce12d07`](https://github.com/horizon-rust/horizon/commit/ce12d07965e337040611534577834438be58c65c) Native mods: the server level's random (native_level_random) - [`93d78e0`](https://github.com/horizon-rust/horizon/commit/93d78e0c53ca5a57cce8c779746ab28f1e6309f8) Merge remote-tracking branch 'hr/main' into mods/native-level-random - [`5c7cf4f`](https://github.com/horizon-rust/horizon/commit/5c7cf4f4c1e9d7dcf579b6291f084700b46134dd) Merge remote-tracking branch 'hr/main' into mods/native-level-random - [`6e09a5d`](https://github.com/horizon-rust/horizon/commit/6e09a5d817c9244652bd04ab8c2d661c3d7c6df8) Merge fix: close native_level_random ### 📊 Changes **3 files changed** (+42 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/levels.rs` (+5 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+31 -1) 📝 `docs/native-mods.md` (+6 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. ## What and why Fixes #5145. Part of #4953 and #3911 (Mods). `NATIVE_HOOKS_API` 40 → 41 (**API next**: the number is set at merge; #5140 also asks for the next one). One server-level helper (not a hook point, so it has no catalog entry): - **`native_level_random(dimension) -> Option<&mut horizon_core::random::LegacyRandom>`** returns the level's own random, vanilla's `Level.random` (`level.getRandom()` in a Java mod). Horizon's ports of vanilla draw from this same `World::random`: an explosion's `Util.shuffle(list, level.random)`, `/bossbar add`'s `Mth.createInsecureUUID(level.random)`, the initial spawn's shuffles. So a mod's draws move vanilla's later ones exactly as a Java mod's do. Mods draw with `RandomSource` (`next_int_bound`, `next_float`…). - It covers the level in place and a parked one (new `Levels::parked_world_mut`). - It is `None` on a client of a server, for an unknown dimension, and for a level that isn't open. In Horizon the Nether and the End open when someone first goes there and close after 300 empty ticks (`close_idle_levels`). ## 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 `Level.random` (`protected final RandomSource random = RandomSource.create();`) and `Level.getRandom()` in 26.3. Horizon keeps it as `World::random`, one per level. This PR draws nothing itself, so vanilla's draw order is unchanged until a mod draws. ## Other projects' code none ## Tested in the game A throwaway `native_tick` probe (removed before the commit) runs on each `Game`'s 20th and 400th tick. For the three dimensions and `minecraft:nope`, it calls the helper, draws `next_int_bound(100)`, prints the random's state before and after, and checks that the level in place gets `self.world.random` itself. Fresh `mktemp -d` homes, `HORIZON_NO_AUDIO=1`, `--profile fast`. | Run | Result | |---|---| | Single player, overworld | Server thread: overworld `Some`, is the world's random, state `423fe13c1ff9 → 009352df5310`. Nether/End (not open yet) and `nope`: `None`. The window's own `Game` (a client of its server thread): `None` for all four | | Single player, `/execute in minecraft:the_nether run tp @s 0 80 0` | Nether (in place) `Some`, is the world's random. The overworld (parked) is `Some` too: `7d615ba5313e → 8dfd98bbab71`, and 380 ticks later it starts again from `8dfd98bbab71`, so the draw stayed in the level's stream. The End stays `None` | | Dedicated (`--dedicated --nogui`) with two `horizon-ctl` clients | Server: overworld `Some`, is the world's random (`a22e6ab1131b → 0af48b73648a`), the others `None`. Both clients: `None` for all four | Unit: `native_hooks::tests` pass. `hook_points_stay_hookable` caught a `matches!` in the first version; the commit uses a plain `match`. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at 01bbb4c65, 44 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +42 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (24 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (5 s) | | tests: horizon-client | ✅ 1340 passed (9 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#6099
No description provided.