[PR #1895] [MERGED] Mod API 0.3: capability world for server mods (blocks, biomes) #3846

Closed
opened 2026-11-03 04:12:44 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1895
Author: @ludovic111
Created: 10/25/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ludovic111

Base: main ← Head: feat/server-mods-world


📝 Commits (8)

  • 35a89ea Mod API 0.3: capability world for server mods (blocks, biomes)
  • 94d8130 Merge branch 'feat/server-mods-game' into feat/server-mods-world
  • aed8b57 Merge remote-tracking branch 'origin/main' into feat/server-mods-world
  • c3f5e9f Merge remote-tracking branch 'origin/feat/mod-run-quiet' into feat/server-mods-world
  • 8bb27b4 Merge origin/feat/mod-run-quiet into feat/server-mods-world; world at API level 4
  • 9698430 mods: the UI guest's level is 3 now that world is level 4
  • 61ff050 mods: drop the sandbox test's unused LEVEL import
  • 8ec47d6 Merge remote-tracking branch 'origin/main' into feat/server-mods-world

📊 Changes

22 files changed (+667 additions, -56 deletions)

View changed files

📝 Cargo.lock (+7 -0)
📝 Cargo.toml (+1 -1)
📝 crates/cargo-horizon-mod/src/check.rs (+5 -0)
📝 crates/horizon-client/src/game/levels.rs (+15 -0)
📝 crates/horizon-client/src/game/mods.rs (+13 -2)
📝 crates/horizon-client/src/game/render_control.rs (+34 -27)
📝 crates/horizon-client/src/game/server_mods.rs (+151 -3)
➕ crates/horizon-mod-sdk/examples/beacons/Cargo.toml (+16 -0)
➕ crates/horizon-mod-sdk/examples/beacons/horizon-mod.toml (+8 -0)
➕ crates/horizon-mod-sdk/examples/beacons/src/lib.rs (+87 -0)
➕ crates/horizon-mod-sdk/examples/beacons/tests/beacons.toml (+22 -0)
📝 crates/horizon-mod-sdk/src/lib.rs (+1 -0)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+28 -0)
📝 crates/horizon-mods/src/api_level.rs (+5 -2)
📝 crates/horizon-mods/src/manifest.rs (+12 -2)
📝 crates/horizon-mods/src/runtime.rs (+95 -3)
📝 crates/horizon-mods/src/testing.rs (+89 -3)
📝 crates/horizon-mods/tests/sandbox.rs (+30 -5)
📝 docs/api/mods-reference.md (+23 -1)
📝 docs/api/mods.md (+7 -5)

...and 2 more files

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Built on #1894 (server mods run in the game), now merged, and on #2171 (command.run-quiet, API level 3), which it includes until that merges. The world functions take API level 4.

What

Server mods (API 0.3, experimental) get capability world, designed once for server mods and later client mods:

  • get-block(dimension, x, y, z): a loaded chunk's block state as minecraft:oak_log[axis=y], none where no chunk is loaded.
  • get-biome(dimension, x, y, z): minecraft:plains, ...
  • set-blocks(dimension, changes): up to 4096 per call, every state checked at once (an error queues nothing), made as /setblock makes them (place_state: neighbours, shapes, light, block entities, the block log to every client) after the call, before that dimension's next tick.

How it works without cost:

  • Reads copy nothing. For a mod call the game lends Mods the levels' chunk maps: they are moved out with mem::take, put back after the call, and taken back with an Any downcast. This happens only while a running mod has world. A read is a map lookup.
  • Writes go through the code the parity harnesses test. They are queued as Output::SetBlocks and applied in tick_server_mods, after a command, and on each level's pass in levels.rs tick_server.
  • Writes for a level that isn't ticking wait for it (another dimension, or in-frame), up to 65,536. A change in a chunk that isn't loaded is skipped, as /setblock refuses one.
  • No server mod, no cost: lend_world checks one flag and apply_mod_block_writes checks is_empty.

Also:

  • Test scripts: blocks (setup) and expect.blocks. The script world is air with the dimension's plainest biome.
  • cargo horizon-mod check reports a trial run's block writes.
  • Example beacons: /beacon builds a glowstone pillar beside the player, /ground reads the block underfoot and the biome. It has a unit test, scripts, and a sandbox test for a mod given no world.
  • parse_state is now a free function, shared with the mod path.
  • Docs: docs/mods.md (the capability, script keys), docs/api/mods.md, the regenerated reference.

How tested

beacons built with this branch's cargo horizon-mod build and given as --dev-mod. A scratch driver over horizon-ctl ran each game with fresh HORIZON_HOME, launcher home and XDG folders, and HORIZON_NO_AUDIO=1. 34/34 checks pass:

Mode /ground (block and biome) /beacon broadcast 4 glowstone, nothing above, seen by log
single player, server thread ✅ minecraft:stone in minecraft:forest ✅ ✅ the window no panic
single player, --in-frame ✅ ✅ ✅ the window no panic
LAN, host in-frame, the guest types ✅ ✅ ✅ guest and host no panic
LAN, host on its server thread, the guest types ✅ ✅ ✅ guest and host no panic
--dedicated + a guest ✅ ✅ (and in the server log) ✅ guest no panic, clean stop

cargo test -p horizon-mods --features runtime,pack: 17 sandbox tests, the beacons scripts among them. The api_reference test passes. Clippy is clean with and without mods.

A/B: the hooks this PR adds cost one branch each with no mod: a flag (mods.world) and Vec::is_empty. #1894 measured the whole server-mods path with no mod loaded: equal within noise (MSPT 3.40 vs 3.39, frame median 0.719 vs 0.714 ms).

Self-check: pr_ready --quick on this branch (its scope line counts the whole stack against main):

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 6a065fa48, 25 min 53 s)

Check Result
Scope ⚠️ 39 files, +3119 −177; 2629 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (10 s)
clippy ✅ (36 s)
tests: workspace ✅ 2064 passed (18 min 8 s)
doc tests ✅ 2 passed (1 min 57 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (2 s)
launcher clippy ✅ (2 min 19 s)
launcher tests ✅ 119 passed (2 min 40 s)
Parity ➖ 331 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 319 more

Parity: parity.py --changed-files over the whole stack's files (#1894, #1895, #1901) on its top commit c5bb51bb0: 110 passed, 0 failed (42 min, Mac mini).

Label skip-release: experimental API 0.3. Nothing changes for players without a server mod.

Leftovers

  • world for client mods (raycast, single player and LAN hosts), which Orbital Laser's crater needs. The same interface, lent from the client's world.
  • Block entities, scheduled ticks for a mod's blocks.

🤖 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/1895 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/server-mods-world` --- ### 📝 Commits (8) - [`35a89ea`](https://github.com/horizon-rust/horizon/commit/35a89eaebe28921c12c9b5a05072d3b3f31ab00a) Mod API 0.3: capability world for server mods (blocks, biomes) - [`94d8130`](https://github.com/horizon-rust/horizon/commit/94d8130193f789c81ab47ba33242f93d3ac7b8d9) Merge branch 'feat/server-mods-game' into feat/server-mods-world - [`aed8b57`](https://github.com/horizon-rust/horizon/commit/aed8b571c473bc8d60429a32d347c731004c9956) Merge remote-tracking branch 'origin/main' into feat/server-mods-world - [`c3f5e9f`](https://github.com/horizon-rust/horizon/commit/c3f5e9f79cbfa897766f8a17115a2a746eeb455f) Merge remote-tracking branch 'origin/feat/mod-run-quiet' into feat/server-mods-world - [`8bb27b4`](https://github.com/horizon-rust/horizon/commit/8bb27b44cabeb3c89cb5393793db87d5c9ba130e) Merge origin/feat/mod-run-quiet into feat/server-mods-world; world at API level 4 - [`9698430`](https://github.com/horizon-rust/horizon/commit/96984300d380c7dffba31cdc991bde8e332502f3) mods: the UI guest's level is 3 now that world is level 4 - [`61ff050`](https://github.com/horizon-rust/horizon/commit/61ff050927187a07dc52c5083ac46e24d58ef230) mods: drop the sandbox test's unused LEVEL import - [`8ec47d6`](https://github.com/horizon-rust/horizon/commit/8ec47d6419accbb1ede02b0e60b5659ae59ace5f) Merge remote-tracking branch 'origin/main' into feat/server-mods-world ### 📊 Changes **22 files changed** (+667 additions, -56 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+7 -0) 📝 `Cargo.toml` (+1 -1) 📝 `crates/cargo-horizon-mod/src/check.rs` (+5 -0) 📝 `crates/horizon-client/src/game/levels.rs` (+15 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+13 -2) 📝 `crates/horizon-client/src/game/render_control.rs` (+34 -27) 📝 `crates/horizon-client/src/game/server_mods.rs` (+151 -3) ➕ `crates/horizon-mod-sdk/examples/beacons/Cargo.toml` (+16 -0) ➕ `crates/horizon-mod-sdk/examples/beacons/horizon-mod.toml` (+8 -0) ➕ `crates/horizon-mod-sdk/examples/beacons/src/lib.rs` (+87 -0) ➕ `crates/horizon-mod-sdk/examples/beacons/tests/beacons.toml` (+22 -0) 📝 `crates/horizon-mod-sdk/src/lib.rs` (+1 -0) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+28 -0) 📝 `crates/horizon-mods/src/api_level.rs` (+5 -2) 📝 `crates/horizon-mods/src/manifest.rs` (+12 -2) 📝 `crates/horizon-mods/src/runtime.rs` (+95 -3) 📝 `crates/horizon-mods/src/testing.rs` (+89 -3) 📝 `crates/horizon-mods/tests/sandbox.rs` (+30 -5) 📝 `docs/api/mods-reference.md` (+23 -1) 📝 `docs/api/mods.md` (+7 -5) _...and 2 more files_ </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Built on #1894 (server mods run in the game), now merged, and on #2171 (`command.run-quiet`, API level 3), which it includes until that merges. The `world` functions take API level 4. ## What Server mods (API 0.3, experimental) get capability **`world`**, designed once for server mods and later client mods: - `get-block(dimension, x, y, z)`: a loaded chunk's block state as `minecraft:oak_log[axis=y]`, none where no chunk is loaded. - `get-biome(dimension, x, y, z)`: `minecraft:plains`, ... - `set-blocks(dimension, changes)`: up to 4096 per call, every state checked at once (an error queues nothing), made **as `/setblock` makes them** (`place_state`: neighbours, shapes, light, block entities, the block log to every client) after the call, before that dimension's next tick. How it works without cost: - **Reads copy nothing.** For a mod call the game lends `Mods` the levels' chunk maps: they are moved out with `mem::take`, put back after the call, and taken back with an `Any` downcast. This happens only while a running mod has `world`. A read is a map lookup. - **Writes go through the code the parity harnesses test.** They are queued as `Output::SetBlocks` and applied in `tick_server_mods`, after a command, and on each level's pass in `levels.rs` `tick_server`. - **Writes for a level that isn't ticking wait for it** (another dimension, or in-frame), up to 65,536. A change in a chunk that isn't loaded is skipped, as `/setblock` refuses one. - **No server mod, no cost:** `lend_world` checks one flag and `apply_mod_block_writes` checks `is_empty`. Also: - **Test scripts:** `blocks` (setup) and `expect.blocks`. The script world is air with the dimension's plainest biome. - **`cargo horizon-mod check`** reports a trial run's block writes. - **Example `beacons`:** `/beacon` builds a glowstone pillar beside the player, `/ground` reads the block underfoot and the biome. It has a unit test, scripts, and a sandbox test for a mod given no world. - `parse_state` is now a free function, shared with the mod path. - Docs: docs/mods.md (the capability, script keys), docs/api/mods.md, the regenerated reference. ## How tested `beacons` built with this branch's `cargo horizon-mod build` and given as `--dev-mod`. A scratch driver over horizon-ctl ran each game with fresh `HORIZON_HOME`, launcher home and XDG folders, and `HORIZON_NO_AUDIO=1`. 34/34 checks pass: | Mode | `/ground` (block and biome) | `/beacon` broadcast | 4 glowstone, nothing above, seen by | log | | --- | --- | --- | --- | --- | | single player, server thread | ✅ `minecraft:stone in minecraft:forest` | ✅ | ✅ the window | no panic | | single player, `--in-frame` | ✅ | ✅ | ✅ the window | no panic | | LAN, host in-frame, the guest types | ✅ | ✅ | ✅ guest and host | no panic | | LAN, host on its server thread, the guest types | ✅ | ✅ | ✅ guest and host | no panic | | `--dedicated` + a guest | ✅ | ✅ (and in the server log) | ✅ guest | no panic, clean stop | `cargo test -p horizon-mods --features runtime,pack`: 17 sandbox tests, the beacons scripts among them. The `api_reference` test passes. Clippy is clean with and without `mods`. **A/B:** the hooks this PR adds cost one branch each with no mod: a flag (`mods.world`) and `Vec::is_empty`. #1894 measured the whole server-mods path with no mod loaded: equal within noise (MSPT 3.40 vs 3.39, frame median 0.719 vs 0.714 ms). **Self-check:** `pr_ready --quick` on this branch (its scope line counts the whole stack against main): **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 6a065fa48, 25 min 53 s) | Check | Result | | --- | --- | | Scope | ⚠️ 39 files, +3119 −177; 2629 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (10 s) | | clippy | ✅ (36 s) | | tests: workspace | ✅ 2064 passed (18 min 8 s) | | doc tests | ✅ 2 passed (1 min 57 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (2 s) | | launcher clippy | ✅ (2 min 19 s) | | launcher tests | ✅ 119 passed (2 min 40 s) | | Parity | ➖ 331 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 319 more | Parity: `parity.py --changed-files` over the whole stack's files (#1894, #1895, #1901) on its top commit c5bb51bb0: **110 passed, 0 failed** (42 min, Mac mini). Label `skip-release`: experimental API 0.3. Nothing changes for players without a server mod. ## Leftovers - `world` for client mods (raycast, single player and LAN hosts), which Orbital Laser's crater needs. The same interface, lent from the client's world. - Block entities, scheduled ticks for a mod's blocks. 🤖 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 04:12:44 +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#3846
No description provided.