[PR #7564] Native mods: a level's seed, difficulty, game rules and weather through LevelRef (#7387) #7673

Open
opened 2026-11-03 07:21:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7564
Author: @levzzz5154
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: modapi/level-world


📝 Commits (4)

  • b21901f Native mods: entity and level handles, and an entity's position, type, UUID and level (#7387)
  • 7b77a5e Merge main into modapi/entity-handles
  • b978111 Native mods: a level's blocks and time through LevelRef (#7387)
  • 25d9cc8 Native mods: a level's seed, difficulty, game rules and weather through LevelRef (#7387)

📊 Changes

14 files changed (+945 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+3 -0)
📝 crates/horizon-client/src/game/mod_api_host_generated.rs (+63 -0)
📝 crates/horizon-client/src/game/native_entities.rs (+5 -5)
➕ crates/horizon-client/src/game/native_entity_refs.rs (+114 -0)
➕ crates/horizon-client/src/game/native_level_refs.rs (+97 -0)
➕ crates/horizon-client/src/game/native_level_world.rs (+68 -0)
📝 crates/horizon-client/src/game/native_lifecycle.rs (+6 -0)
📝 crates/horizon-client/src/mod_api.rs (+54 -1)
📝 crates/horizon-client/src/mod_api/generated_host.rs (+242 -0)
📝 docs/native-mods.md (+23 -0)
➕ tools/native-hook-fragments/entity_handles.json (+48 -0)
➕ tools/native-hook-fragments/level_reads.json (+45 -0)
➕ tools/native-hook-fragments/level_world.json (+40 -0)
📝 xtask/src/mod_api.rs (+137 -1)

📄 Description

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

Stacked on #7454 and #7559 (draft until they merge; review only the last commit).

Part of #7387, on top of the LevelRef block reads (#7559): more of the world, time and rules line, taken in the tracker.

What it adds

LevelRef methods:

  • seed(host): the world's seed, as /seed shows it.
  • difficulty(host): "peaceful", "easy", "normal" or "hard", as /difficulty names it.
  • game_rule(host, name): a rule's value as /gamerule queries it. It takes keep_inventory or minecraft:keep_inventory and returns GameRuleValue (Bool or Int, now re-exported from mod_api), or None for an unknown rule.
  • weather(host): the rain and thunder levels (Level.getRainLevel / getThunderLevel, 0.0 to 1.0). Both are 0 in a level with no weather, such as the Nether and the End.
  • is_raining, is_thundering: vanilla's thresholds (rain above 0.2, thunder above 0.9).

Like the block reads, they answer any level the server has loaded and are None on a client or with a handle of an earlier open. native_level_world in native_level_refs.rs becomes pub(super) for them.

Proof

A probe bundle (HEAD injection at Game::tick_mobs) reads the Overworld and the Nether every 100 server ticks. It ran on this branch's fast build, server thread, offscreen, scratch homes. After tick 150 it ran these commands: forceload a Nether chunk, /difficulty hard, /gamerule keep_inventory true, /gamerule random_tick_speed 7 and /weather thunder.

LVLPROBE tick=50 minecraft:overworld seed=Some(0) difficulty=Some("normal") keep_inventory=Some(Bool(false)) random_tick_speed=Some(Int(3)) nope=None weather=Some((0.0, 0.0)) raining=Some(false) thundering=Some(false)
LVLPROBE tick=50 minecraft:the_nether not loaded
LVLPROBE tick=150 minecraft:overworld seed=Some(0) difficulty=Some("normal") keep_inventory=Some(Bool(false)) random_tick_speed=Some(Int(3)) nope=None weather=Some((0.0, 0.0)) raining=Some(false) thundering=Some(false)
LVLPROBE tick=150 minecraft:the_nether not loaded
LVLPROBE tick=250 minecraft:overworld seed=Some(0) difficulty=Some("hard") keep_inventory=Some(Bool(true)) random_tick_speed=Some(Int(7)) nope=None weather=Some((0.32999995, 0.108899966)) raining=Some(true) thundering=Some(false)
LVLPROBE tick=250 minecraft:the_nether seed=Some(0) difficulty=Some("hard") keep_inventory=Some(Bool(true)) random_tick_speed=Some(Int(7)) nope=None weather=Some((0.0, 0.0)) raining=Some(false) thundering=Some(false)
LVLPROBE tick=450 minecraft:overworld seed=Some(0) difficulty=Some("hard") keep_inventory=Some(Bool(true)) random_tick_speed=Some(Int(7)) nope=None weather=Some((1.0, 1.0)) raining=Some(true) thundering=Some(true)
LVLPROBE tick=450 minecraft:the_nether seed=Some(0) difficulty=Some("hard") keep_inventory=Some(Bool(true)) random_tick_speed=Some(Int(7)) nope=None weather=Some((0.0, 0.0)) raining=Some(false) thundering=Some(false)
  • The rules and the difficulty change with the commands.
  • The rain and thunder levels ramp up as vanilla's do, and is_thundering turns on only past 0.9.
  • The parked Nether has no weather.
  • seed is 0 because a world horizon-ctl makes has seed 0; /seed prints Seed: [0] in the same run.

pr_ready (tools/pr_ready.py --quick --base modapi/level-reads on cachyos-x8664, against modapi/level-reads at b978111dd, 3 min 21 s)

Check Result
Scope ✅ 8 files, +201 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (32 s)
rustfmt ✅ (6 s)
clippy ✅ (1 min 17 s)
tests: horizon-client, horizon-client-lib ✅ 2159 passed (1 min 11 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
mod API up to date ✅ (11 s)
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)

🤖 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/7564 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `modapi/level-world` --- ### 📝 Commits (4) - [`b21901f`](https://github.com/horizon-rust/horizon/commit/b21901f67698b54bb46148a0409769ce9e24c8d5) Native mods: entity and level handles, and an entity's position, type, UUID and level (#7387) - [`7b77a5e`](https://github.com/horizon-rust/horizon/commit/7b77a5ec989f448298572d44dee9ab84fe38cb50) Merge main into modapi/entity-handles - [`b978111`](https://github.com/horizon-rust/horizon/commit/b978111dddea704a7cf7d1e7cf7129a2ca445fbf) Native mods: a level's blocks and time through LevelRef (#7387) - [`25d9cc8`](https://github.com/horizon-rust/horizon/commit/25d9cc84c260ac604b93b09a3bd6e51ef71a4268) Native mods: a level's seed, difficulty, game rules and weather through LevelRef (#7387) ### 📊 Changes **14 files changed** (+945 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+3 -0) 📝 `crates/horizon-client/src/game/mod_api_host_generated.rs` (+63 -0) 📝 `crates/horizon-client/src/game/native_entities.rs` (+5 -5) ➕ `crates/horizon-client/src/game/native_entity_refs.rs` (+114 -0) ➕ `crates/horizon-client/src/game/native_level_refs.rs` (+97 -0) ➕ `crates/horizon-client/src/game/native_level_world.rs` (+68 -0) 📝 `crates/horizon-client/src/game/native_lifecycle.rs` (+6 -0) 📝 `crates/horizon-client/src/mod_api.rs` (+54 -1) 📝 `crates/horizon-client/src/mod_api/generated_host.rs` (+242 -0) 📝 `docs/native-mods.md` (+23 -0) ➕ `tools/native-hook-fragments/entity_handles.json` (+48 -0) ➕ `tools/native-hook-fragments/level_reads.json` (+45 -0) ➕ `tools/native-hook-fragments/level_world.json` (+40 -0) 📝 `xtask/src/mod_api.rs` (+137 -1) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. **Stacked on #7454 and #7559** (draft until they merge; review only the last commit). Part of #7387, on top of the LevelRef block reads (#7559): more of the **world, time and rules** line, taken in the tracker. ## What it adds `LevelRef` methods: - `seed(host)`: the world's seed, as `/seed` shows it. - `difficulty(host)`: `"peaceful"`, `"easy"`, `"normal"` or `"hard"`, as `/difficulty` names it. - `game_rule(host, name)`: a rule's value as `/gamerule` queries it. It takes `keep_inventory` or `minecraft:keep_inventory` and returns `GameRuleValue` (`Bool` or `Int`, now re-exported from `mod_api`), or `None` for an unknown rule. - `weather(host)`: the rain and thunder levels (`Level.getRainLevel` / `getThunderLevel`, 0.0 to 1.0). Both are 0 in a level with no weather, such as the Nether and the End. - `is_raining`, `is_thundering`: vanilla's thresholds (rain above 0.2, thunder above 0.9). Like the block reads, they answer any level the server has loaded and are `None` on a client or with a handle of an earlier open. `native_level_world` in `native_level_refs.rs` becomes `pub(super)` for them. ## Proof A probe bundle (HEAD injection at `Game::tick_mobs`) reads the Overworld and the Nether every 100 server ticks. It ran on this branch's fast build, server thread, offscreen, scratch homes. After tick 150 it ran these commands: `forceload` a Nether chunk, `/difficulty hard`, `/gamerule keep_inventory true`, `/gamerule random_tick_speed 7` and `/weather thunder`. ``` LVLPROBE tick=50 minecraft:overworld seed=Some(0) difficulty=Some("normal") keep_inventory=Some(Bool(false)) random_tick_speed=Some(Int(3)) nope=None weather=Some((0.0, 0.0)) raining=Some(false) thundering=Some(false) LVLPROBE tick=50 minecraft:the_nether not loaded LVLPROBE tick=150 minecraft:overworld seed=Some(0) difficulty=Some("normal") keep_inventory=Some(Bool(false)) random_tick_speed=Some(Int(3)) nope=None weather=Some((0.0, 0.0)) raining=Some(false) thundering=Some(false) LVLPROBE tick=150 minecraft:the_nether not loaded LVLPROBE tick=250 minecraft:overworld seed=Some(0) difficulty=Some("hard") keep_inventory=Some(Bool(true)) random_tick_speed=Some(Int(7)) nope=None weather=Some((0.32999995, 0.108899966)) raining=Some(true) thundering=Some(false) LVLPROBE tick=250 minecraft:the_nether seed=Some(0) difficulty=Some("hard") keep_inventory=Some(Bool(true)) random_tick_speed=Some(Int(7)) nope=None weather=Some((0.0, 0.0)) raining=Some(false) thundering=Some(false) LVLPROBE tick=450 minecraft:overworld seed=Some(0) difficulty=Some("hard") keep_inventory=Some(Bool(true)) random_tick_speed=Some(Int(7)) nope=None weather=Some((1.0, 1.0)) raining=Some(true) thundering=Some(true) LVLPROBE tick=450 minecraft:the_nether seed=Some(0) difficulty=Some("hard") keep_inventory=Some(Bool(true)) random_tick_speed=Some(Int(7)) nope=None weather=Some((0.0, 0.0)) raining=Some(false) thundering=Some(false) ``` - The rules and the difficulty change with the commands. - The rain and thunder levels ramp up as vanilla's do, and `is_thundering` turns on only past 0.9. - The parked Nether has no weather. - `seed` is 0 because a world horizon-ctl makes has seed 0; `/seed` prints `Seed: [0]` in the same run. **pr_ready** (`tools/pr_ready.py --quick --base modapi/level-reads` on cachyos-x8664, against modapi/level-reads at b978111dd, 3 min 21 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +201 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (32 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (1 min 17 s) | | tests: horizon-client, horizon-client-lib | ✅ 2159 passed (1 min 11 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (11 s) | | 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) | 🤖 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>
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#7673
No description provided.