[PR #4538] [CLOSED] The mod capability stack on the hook points (API 8): net channel, server events, mobs, fluids, effects, redstone, displays, inter-mod #5682

Closed
opened 2026-11-03 05:14:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4538
Author: @Qwerner88880
Created: 10/30/2026
Status: ❌ Closed

Base: main ← Head: native-all


📝 Commits (10+)

  • 15fd992 Mod API: block entities for server mods (capability block-entities)
  • b3dfae0 Mod API: shared energy buffers on block entities (capability energy)
  • fe5e71f Mod API: chest menus for server mods (capability menus)
  • a43b219 Mod API: server mods take the use of their blocks (block-use-events)
  • 4712955 Mod API: display entities for server mods (capability displays)
  • 3964813 Mod API: shared inventories on block entities and inventory menus (capability items)
  • c50f1e0 Mod API: machine recipe types for server mods (capability machine-recipes)
  • 044253b Fix the cells grinding scenario's slot counts
  • 9837fbe Make the port tools' tests pass on Windows
  • 34e7b5a Report the server mod outputs the trial run dropped

📊 Changes

188 files changed (+42713 additions, -267 deletions)

View changed files

📝 Cargo.lock (+295 -1)
📝 Cargo.toml (+24 -0)
📝 crates/cargo-horizon-mod/Cargo.toml (+2 -2)
📝 crates/cargo-horizon-mod/src/check.rs (+217 -18)
📝 crates/cargo-horizon-mod/src/main.rs (+210 -38)
➕ crates/cargo-horizon-mod/template/Cargo.toml.in (+24 -0)
➕ crates/cargo-horizon-mod/template/horizon-mod.toml (+12 -0)
➕ crates/cargo-horizon-mod/template/src/lib.rs (+19 -0)
➕ crates/cargo-horizon-mod/template/tests/hello.toml (+14 -0)
📝 crates/horizon-client-render/src/hud.rs (+78 -9)
📝 crates/horizon-client-render/src/mod_list.rs (+4 -0)
📝 crates/horizon-client-render/src/options_ui.rs (+16 -4)
📝 crates/horizon-client-render/src/ui.rs (+50 -10)
📝 crates/horizon-client/Cargo.toml (+13 -0)
📝 crates/horizon-client/src/game.rs (+128 -2)
📝 crates/horizon-client/src/game/agent.rs (+1 -0)
📝 crates/horizon-client/src/game/chat.rs (+33 -18)
📝 crates/horizon-client/src/game/command_blocks.rs (+7 -7)
📝 crates/horizon-client/src/game/commands.rs (+1 -1)
📝 crates/horizon-client/src/game/commands/extra.rs (+13 -0)

...and 80 more files

📄 Description

🤖 Opened by Tree's AI agent (ZCode, GLM-5.3), not by Tree himself.

The mod capability stack on the hook points (API 8): net channel, server events, mobs, fluids, effects, redstone, displays, inter-mod

Kind: feature (roadmap:mods, #3911)
Vanilla reference: NeoForge 26.3's event bus (the hooks mirror its events; no vanilla code is used — this is original Rust written against vanilla behaviour)

What and why

This is the single integration PR agreed with levzzz ("не нарезать, лучше 1 пр, и в стиле хук поинтов", NATIVE/DECISIONS.md): the working capability stack of the native-all branch — the compiled-in mod runtime that replaced the removed WebAssembly one — re-expressed as hook points and helpers in native_hooks.rs, additive on top of APIs 1–7, NATIVE_HOOKS_API 7 → 8 (the number is the next free one; shift it at merge as you see fit).

The branch keeps the compiled-in runtime (horizon-mods, horizon-mod-sdk: 34 sandbox tests + the cells example's 12 scenarios, 150 steps, green) exactly as it was: the game's entry points now call the new hook points first, in both feature configurations, and the compiled-in mods answer next with what the hooks left. A horizon-mixins bundle can therefore hook the same events and use the same services the compiled-in mods do — one wire, one budget, shared state (fluid tanks, displays, redstone emitters, the inter-mod bus).

Yes, this is over the ~500-line rule (~1.5k lines with the catalog and docs); that is the shape levzzz asked for — one branch he adapts himself instead of ~40 small PRs.

The per-capability design, signatures and seating table are in NATIVE/hook-design.md (attached to this PR's description in the repo folder of the same name).

Capability → hooks → helpers

Capability Hook points (all additive, catalog + docs each) Helpers
Network (the message channel) net_from_client (server; untrusted data), net_from_server (window) native_net_send_to_player, native_net_send_to_server — work in every build, with or without the mods feature
Rich events (cancellable) player_hurt (amount/cancel, before armour), entity_hurt (amount/cancel), block_breaking (cancel: no drop, no wear, no statistic), item_picked_up (cancel), entity_interact (claimed) native_acting_player (the UUID the event hooks name players by)
Game events (observational) player_died, mob_spawned, mob_killed, item_dropped —
Mobs (fed through entity_hurt / entity_interact) native_spawn_entity (the entities.spawn options, Tags marks, the same 1024 budget), native_entity_teleport, native_entity_push, native_entity_set_health, native_remove_entity
Effects — native_spawn_particle, native_play_sound, native_play_sound_to (the same caps as the compiled-in effects)
Redstone — (the ask hook is deferred, see below) native_redstone_set_output (six faces, DUNSWE order, strong powers through; the game updates the neighbours)
Displays — native_show_text_display, native_show_block_display, native_show_item_display, native_move_display, native_hide_display
Fluids — native_fluid_tanks, native_fluid_insert, native_fluid_extract (millibuckets, the shared saved tanks)
Inter-mod — native_mod_publish (onto the compiled-in mods' bus, delivered in the tick's last round)
Machine recipes, multiblocks — deliberately none (see below)

Limits, as the branch's own design already had them: a channel is 1–64 bytes outside minecraft:/horizon:; payloads ≤ 30 000 bytes; ≤ 32 messages per player per tick each way (one shared counter with the compiled-in mods'); server→client only to brand-horizon clients — vanilla clients are sent nothing.

Catalog: the eleven new entries also carry side, cancellable and the NeoForge event they mirror in neoforge (fields horizon-mixins ignores); the sixteen existing entries are untouched, as the hook-points contract requires. Everything but the net helpers needs the mods feature (a build without it has none of the state they touch); that is stated in docs/native-mods.md.

Deliberately not in this PR, and why:

  • block_signal ask-hook (a mod answering "what does this block emit?"): the ask site is a borrowed level read (Level::mod_signal); plumbing &mut Game through the signal graph deserves its own PR with the redstone parity harnesses around it. The write direction (native_redstone_set_output) is here.
  • Machine recipes / multiblocks services: those tables are the compiled-in mods' own data files; a hooked bundle carries its own tables, as a datapack does.
  • Block-entities / items / menus / gui-screens — see the overlap note below.

What was verified live (step 4, artifacts in NATIVE/verify-artifacts/)

  • A live game with the cells + cells-ui example pair compiled in: every /cells command driven through horizon-ctl (host-ctl.log), energy cells charging, sharing, holograms (shot-cell-hologram.png), the Mods page (shot-mods-page.png), mod config honoured (host-config-cells.toml).
  • A world restart with the mod data intact.
  • A second client over TCP (--server HOST:PORT) against the LAN host, seeing the mod's world (guest-ctl.log, shot-guest-tcp-view.png) — the first time this was ever checked.
  • A crash this surfaced (/cellui's scrollbar, min > max) was found live and fixed (e8a378df9).

What was not verified (and is not claimed):

  • The full parity harness suite (tools/pr_ready.py complete, tools/test_*_parity.py) — that is CI's job; the quick gate output is below.
  • A vanilla client beside the host (the brand check keeps them out of the sends by code; not run live).
  • A dedicated server build (per docs/native-mods.md native mods are not built there yet), sound by ear, load with hundreds of machines/mobs.

Automated, after the change: cargo clippy clean with and without the mods feature; the sandbox suite 34 passed / 1 ignored; the cells scenarios 12/12 (150 steps) through native-test; cargo test --workspace green except the pre-existing Windows title test (title::tests::each_world_preset_writes_its_own_generator, fails identically on the branch before this change).

Overlaps with the other stacks

  • Sylviromi (#3996 block-entities, #4055 items, #4072/#4289 menus/gui-screens): the branch carries its own working base implementation of those four from the pre-removal fork; in this PR they stay as the branch's runtime plumbing and are not re-exposed as hook points — our lane above does not overlap them. Happy to rebase onto Sylviromi's stack once it merges and drop the duplicated base.
  • ludovicthenot (#4302, #4284 item use/tooltip): the branch's item-hooks (blows, held tick, armour, data on stacks) stays compiled-in as it was; no hook points were added for it here.

Question for levzzz on the form

You asked for "какое-то общее API" for the channel: is hook points + helpers (this PR: native_net_from_client/native_net_from_server + the two send helpers, one wire with the compiled-in mods) the shape you want as that general API — or should the typed side live in a crate both the game and a mod depend on (which #3964's dependency direction currently forbids)? Also: are the mods-feature-only helpers acceptable for the heavy services, and should energy/fluids wait for a shared standard (per #4088) before they grow hooks? We did not build any of that ahead of your answer.

tools/pr_ready.py --quick --base origin/main

**pr_ready** (`tools/pr_ready.py --quick` on DESKTOP-H7P5E7K, against origin/main at d2186eb9a, 2 min 21 s)

| Check | Result |
| --- | --- |
| Scope | ⚠️ 188 files, +42713 −267; 35947 lines of code: over 500, split it if it can ship in parts |
| Cargo.lock | ✅ changes with a Cargo.toml |
| Public tree | ✅ |
| Python tests | ✅ 480 passed (57 s) |
| rustfmt | ✅ (8 s) |
| clippy | ✅ (16 s) |
| tests: workspace | ❌ 778 passed, 1 failed (39 s) |
| doc tests | ✅ 0 passed (7 s) |
| content root tests | ✅ 5 passed |
| tokens.css up to date | ➖ theme untouched |
| launcher rustfmt | ✅ (1 s) |
| launcher clippy | ✅ (1 s) |
| launcher tests | ✅ 272 passed (8 s) |
| Parity | ➖ 354 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 342 more |
| Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) |

The scope warning is the whole integration branch (this PR is deliberately
one, per levzzz's decision, instead of ~40 small ones). The one red,
title::tests::each_world_preset_writes_its_own_generator, is a pre-existing
Windows path failure, failing identically on the branch before these commits;
the parity harnesses are left to CI as the tool itself notes.

🤖 Generated with ZCode (GLM-5.3)


🔄 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/4538 **Author:** [@Qwerner88880](https://github.com/Qwerner88880) **Created:** 10/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `native-all` --- ### 📝 Commits (10+) - [`15fd992`](https://github.com/horizon-rust/horizon/commit/15fd992f0110c269430d7efb767c29a2ca6c9a9e) Mod API: block entities for server mods (capability block-entities) - [`b3dfae0`](https://github.com/horizon-rust/horizon/commit/b3dfae0581bc12810535478618d4fb98c779875c) Mod API: shared energy buffers on block entities (capability energy) - [`fe5e71f`](https://github.com/horizon-rust/horizon/commit/fe5e71f92bf24ffe4e531b7302fa5c4e2650f50b) Mod API: chest menus for server mods (capability menus) - [`a43b219`](https://github.com/horizon-rust/horizon/commit/a43b21961cb860d6748289ed5e5983d1f73f09b0) Mod API: server mods take the use of their blocks (block-use-events) - [`4712955`](https://github.com/horizon-rust/horizon/commit/4712955a8731a5afa88ac98af0bd58d5d0048cd4) Mod API: display entities for server mods (capability displays) - [`3964813`](https://github.com/horizon-rust/horizon/commit/396481320ede5c94b8e95031e63d88339f929e3d) Mod API: shared inventories on block entities and inventory menus (capability items) - [`c50f1e0`](https://github.com/horizon-rust/horizon/commit/c50f1e018d987a52203e5542901babf9d8562270) Mod API: machine recipe types for server mods (capability machine-recipes) - [`044253b`](https://github.com/horizon-rust/horizon/commit/044253b0690beae354796bfc9f3422ffe0adfe66) Fix the cells grinding scenario's slot counts - [`9837fbe`](https://github.com/horizon-rust/horizon/commit/9837fbe780860d22edf1ca15b09eeec87b6bedf9) Make the port tools' tests pass on Windows - [`34e7b5a`](https://github.com/horizon-rust/horizon/commit/34e7b5a5e3a45faea362544f9e840ab37175c3eb) Report the server mod outputs the trial run dropped ### 📊 Changes **188 files changed** (+42713 additions, -267 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+295 -1) 📝 `Cargo.toml` (+24 -0) 📝 `crates/cargo-horizon-mod/Cargo.toml` (+2 -2) 📝 `crates/cargo-horizon-mod/src/check.rs` (+217 -18) 📝 `crates/cargo-horizon-mod/src/main.rs` (+210 -38) ➕ `crates/cargo-horizon-mod/template/Cargo.toml.in` (+24 -0) ➕ `crates/cargo-horizon-mod/template/horizon-mod.toml` (+12 -0) ➕ `crates/cargo-horizon-mod/template/src/lib.rs` (+19 -0) ➕ `crates/cargo-horizon-mod/template/tests/hello.toml` (+14 -0) 📝 `crates/horizon-client-render/src/hud.rs` (+78 -9) 📝 `crates/horizon-client-render/src/mod_list.rs` (+4 -0) 📝 `crates/horizon-client-render/src/options_ui.rs` (+16 -4) 📝 `crates/horizon-client-render/src/ui.rs` (+50 -10) 📝 `crates/horizon-client/Cargo.toml` (+13 -0) 📝 `crates/horizon-client/src/game.rs` (+128 -2) 📝 `crates/horizon-client/src/game/agent.rs` (+1 -0) 📝 `crates/horizon-client/src/game/chat.rs` (+33 -18) 📝 `crates/horizon-client/src/game/command_blocks.rs` (+7 -7) 📝 `crates/horizon-client/src/game/commands.rs` (+1 -1) 📝 `crates/horizon-client/src/game/commands/extra.rs` (+13 -0) _...and 80 more files_ </details> ### 📄 Description > 🤖 Opened by Tree's AI agent (ZCode, GLM-5.3), not by Tree himself. # The mod capability stack on the hook points (API 8): net channel, server events, mobs, fluids, effects, redstone, displays, inter-mod **Kind:** feature (`roadmap:mods`, #3911) **Vanilla reference:** NeoForge 26.3's event bus (the hooks mirror its events; no vanilla code is used — this is original Rust written against vanilla behaviour) ## What and why This is the single integration PR agreed with levzzz ("не нарезать, лучше 1 пр, и в стиле хук поинтов", `NATIVE/DECISIONS.md`): the working capability stack of the `native-all` branch — the compiled-in mod runtime that replaced the removed WebAssembly one — re-expressed as **hook points and helpers** in `native_hooks.rs`, additive on top of APIs 1–7, `NATIVE_HOOKS_API` 7 → 8 (**the number is the next free one; shift it at merge as you see fit**). The branch keeps the compiled-in runtime (`horizon-mods`, `horizon-mod-sdk`: 34 sandbox tests + the cells example's 12 scenarios, 150 steps, green) exactly as it was: the game's entry points now call the new hook points first, in **both** feature configurations, and the compiled-in mods answer next with what the hooks left. A horizon-mixins bundle can therefore hook the same events and use the same services the compiled-in mods do — one wire, one budget, shared state (fluid tanks, displays, redstone emitters, the inter-mod bus). Yes, this is over the ~500-line rule (~1.5k lines with the catalog and docs); that is the shape levzzz asked for — one branch he adapts himself instead of ~40 small PRs. The per-capability design, signatures and seating table are in `NATIVE/hook-design.md` (attached to this PR's description in the repo folder of the same name). ## Capability → hooks → helpers | Capability | Hook points (all additive, catalog + docs each) | Helpers | |---|---|---| | Network (the message channel) | `net_from_client` (server; untrusted data), `net_from_server` (window) | `native_net_send_to_player`, `native_net_send_to_server` — **work in every build**, with or without the `mods` feature | | Rich events (cancellable) | `player_hurt` (amount/cancel, before armour), `entity_hurt` (amount/cancel), `block_breaking` (cancel: no drop, no wear, no statistic), `item_picked_up` (cancel), `entity_interact` (claimed) | `native_acting_player` (the UUID the event hooks name players by) | | Game events (observational) | `player_died`, `mob_spawned`, `mob_killed`, `item_dropped` | — | | Mobs | (fed through `entity_hurt` / `entity_interact`) | `native_spawn_entity` (the `entities.spawn` options, Tags marks, the same 1024 budget), `native_entity_teleport`, `native_entity_push`, `native_entity_set_health`, `native_remove_entity` | | Effects | — | `native_spawn_particle`, `native_play_sound`, `native_play_sound_to` (the same caps as the compiled-in `effects`) | | Redstone | — (the *ask* hook is deferred, see below) | `native_redstone_set_output` (six faces, DUNSWE order, strong powers through; the game updates the neighbours) | | Displays | — | `native_show_text_display`, `native_show_block_display`, `native_show_item_display`, `native_move_display`, `native_hide_display` | | Fluids | — | `native_fluid_tanks`, `native_fluid_insert`, `native_fluid_extract` (millibuckets, the shared saved tanks) | | Inter-mod | — | `native_mod_publish` (onto the compiled-in mods' bus, delivered in the tick's last round) | | Machine recipes, multiblocks | — | deliberately none (see below) | Limits, as the branch's own design already had them: a channel is 1–64 bytes outside `minecraft:`/`horizon:`; payloads ≤ 30 000 bytes; ≤ 32 messages per player per tick each way (one shared counter with the compiled-in mods'); server→client only to brand-`horizon` clients — **vanilla clients are sent nothing**. Catalog: the eleven new entries also carry `side`, `cancellable` and the NeoForge event they mirror in `neoforge` (fields horizon-mixins ignores); the sixteen existing entries are untouched, as the hook-points contract requires. Everything but the net helpers needs the `mods` feature (a build without it has none of the state they touch); that is stated in `docs/native-mods.md`. Deliberately not in this PR, and why: - **`block_signal` ask-hook** (a mod answering "what does this block emit?"): the ask site is a borrowed level read (`Level::mod_signal`); plumbing `&mut Game` through the signal graph deserves its own PR with the redstone parity harnesses around it. The write direction (`native_redstone_set_output`) is here. - **Machine recipes / multiblocks services**: those tables are the compiled-in mods' own data files; a hooked bundle carries its own tables, as a datapack does. - **Block-entities / items / menus / gui-screens** — see the overlap note below. ## What was verified live (step 4, artifacts in `NATIVE/verify-artifacts/`) - A live game with the `cells` + `cells-ui` example pair compiled in: every `/cells` command driven through `horizon-ctl` (`host-ctl.log`), energy cells charging, sharing, holograms (`shot-cell-hologram.png`), the Mods page (`shot-mods-page.png`), mod config honoured (`host-config-cells.toml`). - A **world restart** with the mod data intact. - A **second client over TCP** (`--server HOST:PORT`) against the LAN host, seeing the mod's world (`guest-ctl.log`, `shot-guest-tcp-view.png`) — the first time this was ever checked. - A crash this surfaced (`/cellui`'s scrollbar, `min > max`) was found live and fixed (`e8a378df9`). What was **not** verified (and is not claimed): - The full parity harness suite (`tools/pr_ready.py` complete, `tools/test_*_parity.py`) — that is CI's job; the quick gate output is below. - A vanilla client beside the host (the brand check keeps them out of the sends by code; not run live). - A dedicated server build (per `docs/native-mods.md` native mods are not built there yet), sound by ear, load with hundreds of machines/mobs. Automated, after the change: `cargo clippy` clean **with and without** the `mods` feature; the sandbox suite 34 passed / 1 ignored; the cells scenarios 12/12 (150 steps) through `native-test`; `cargo test --workspace` green except the pre-existing Windows title test (`title::tests::each_world_preset_writes_its_own_generator`, fails identically on the branch before this change). ## Overlaps with the other stacks - **Sylviromi** (#3996 block-entities, #4055 items, #4072/#4289 menus/gui-screens): the branch carries its **own working** base implementation of those four from the pre-removal fork; in this PR they stay as the branch's runtime plumbing and are **not** re-exposed as hook points — our lane above does not overlap them. Happy to rebase onto Sylviromi's stack once it merges and drop the duplicated base. - **ludovicthenot** (#4302, #4284 item use/tooltip): the branch's `item-hooks` (blows, held tick, armour, data on stacks) stays compiled-in as it was; no hook points were added for it here. ## Question for levzzz on the form You asked for "какое-то общее API" for the channel: is **hook points + helpers** (this PR: `native_net_from_client`/`native_net_from_server` + the two send helpers, one wire with the compiled-in mods) the shape you want as that general API — or should the typed side live in a crate both the game and a mod depend on (which #3964's dependency direction currently forbids)? Also: are the `mods`-feature-only helpers acceptable for the heavy services, and should energy/fluids wait for a shared standard (per #4088) before they grow hooks? We did not build any of that ahead of your answer. ## `tools/pr_ready.py --quick --base origin/main` ``` **pr_ready** (`tools/pr_ready.py --quick` on DESKTOP-H7P5E7K, against origin/main at d2186eb9a, 2 min 21 s) | Check | Result | | --- | --- | | Scope | ⚠️ 188 files, +42713 −267; 35947 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ✅ 480 passed (57 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (16 s) | | tests: workspace | ❌ 778 passed, 1 failed (39 s) | | doc tests | ✅ 0 passed (7 s) | | content root tests | ✅ 5 passed | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (1 s) | | launcher tests | ✅ 272 passed (8 s) | | Parity | ➖ 354 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 342 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ``` The scope warning is the whole integration branch (this PR is deliberately one, per levzzz's decision, instead of ~40 small ones). The one red, `title::tests::each_world_preset_writes_its_own_generator`, is a pre-existing Windows path failure, failing identically on the branch before these commits; the parity harnesses are left to CI as the tool itself notes. 🤖 Generated with ZCode (GLM-5.3) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:14:18 +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#5682
No description provided.