[PR #6253] [MERGED] Mod API: trait entries for pending hook fragments, item-use and menu slot-rule hooks #6745

Closed
opened 2026-11-03 06:26:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6253
Author: @arismoko
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @levzzz5154

Base: main ← Head: v2/ses_01M6C18WAJKS3HWAKR2EKX5REX-u9b


📝 Commits (4)

  • 8d9a75e Mod API: trait methods for every hook
  • 0cc0fd1 Mod API: client-library hooks through NativeClientHooks
  • c73dbb7 xtask mod-api fills new hooks' dispatch placeholders
  • 121c848 Docs: native mod trait hooks

📊 Changes

37 files changed (+7038 additions, -1798 deletions)

View changed files

📝 crates/horizon-client/src/breathing.rs (+1 -1)
📝 crates/horizon-client/src/client_lib.rs (+1 -0)
📝 crates/horizon-client/src/crafting.rs (+1 -1)
📝 crates/horizon-client/src/entry.rs (+47 -0)
📝 crates/horizon-client/src/game.rs (+10 -0)
📝 crates/horizon-client/src/game/maps.rs (+0 -1)
📝 crates/horizon-client/src/game/mod_api_host_generated.rs (+109 -0)
📝 crates/horizon-client/src/game/native_block_entity_draw.rs (+0 -2)
📝 crates/horizon-client/src/game/native_claimed_items.rs (+15 -18)
📝 crates/horizon-client/src/game/native_data_maps.rs (+3 -3)
📝 crates/horizon-client/src/game/native_falling.rs (+1 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+344 -162)
📝 crates/horizon-client/src/game/native_mob_draw.rs (+0 -2)
📝 crates/horizon-client/src/game/native_server.rs (+1 -2)
📝 crates/horizon-client/src/game/native_world_columns.rs (+7 -6)
📝 crates/horizon-client/src/game/native_world_edit.rs (+13 -14)
📝 crates/horizon-client/src/menu.rs (+26 -1)
📝 crates/horizon-client/src/mod_api.rs (+15 -1)
📝 crates/horizon-client/src/mod_api/generated.rs (+5103 -1445)
📝 crates/horizon-client/src/mod_api/generated_host.rs (+161 -0)

...and 17 more files

📄 Description

🤖 Opened by Aria's agent swarm, Dyna, not by Aria.

Gives every native hook a trait method, so a trait mod can answer any hook in the catalog or the pending fragments through Hooks, and lets cargo run -p xtask -- mod-api fill a new hook's dispatch call.

What it does

  • Every hook gets a trait method. The generator now reads the pending fragments as well as native-hooks.json, and rejects duplicate names. The 91 hooks that had none get a mod_api entry that follows the NeoForge counterpart and the existing entries. Every hook now needs one: the check fails naming any hook without it. The game's hook bodies call mod_api::dispatch_<hook>(self, mod_api::mods(), …).
  • Client-library hooks. menu_slot_rules, living_breathe and ingredient are free functions in horizon-client-lib, which can't see the mod list. One NativeClientHooks struct of callbacks is installed once from the executable's entry point, as horizon-world's NativeLoadHooks is.
  • Host helpers. The new hooks' helpers on Host, such as edit_blocks, surface_heights, raycast, view_hit, claim_items and mod_screen_open.
  • Docs. "Adding a hook" in docs/native-mods.md.

Hooks

Contract Hooks
cancel block_highlight, entity_mount, entity_tick_pre, experience_orb_merge, experience_orb_pickup, gui_layer_pre, interaction_key, item_damaged, living_entity_use_item_start, living_entity_use_item_stop, living_entity_use_item_tick, living_knockback, mob_submit, mouse_button_pre, mouse_scrolling, perform_console_command, player_command, player_fish, player_game_mode_changed, player_submit, player_toggle_flight, projectile_impact, render_hand, screen_char_typed_pre, screen_key_pressed_pre, screen_key_released_pre, screen_mouse_dragged_pre, screen_mouse_scrolled_pre, sign_changed
listen (values written back) biome_colors, camera_distance, camera_shake, can_eat, client_level_load, client_level_unload, client_resources_reloaded, compute_fog_color, compute_fov, difficulty_changed, entity_tick_post, experience_orb_can_merge, framerate_limit, gui_layer_post, input_key, item_crafted, item_decorations, level_load, level_unload, living_breathe, living_entity_use_item_finish, living_equipment_change, mending_repair, menu_slot_rules, mob_layer, mod_container_viewers, mouse_button_post, music, on_use_tick, player_changed_dimension, player_container_close, player_container_open, player_respawned, player_start_tracking, player_stop_tracking, recipes_received, release_using, render_fog, server_data_loaded, shader_params, use_animation, use_duration
collect blocks, data_map_types, data_pack_files, datapack_sync, entity_tick_listened, experience_orb_pickup_listened, hears_projectile_impacts, ingredient, items, living_equipment_listened, loot_condition, loot_function, map_decorations, music_layers, player_render_listened, standalone_models
replace block_entity_energy, fire_odds, item_fluid_tank, smoke_source

cancel stops later mods with Flow::Cancel; listen passes the hook's mutable values through mods in order; collect passes one shared list; replace lets a mod supply the result.

New hooks: placeholder fill

Every hook needs a mod_api entry; the check fails naming any hook without one. A new Game hook can start with the placeholder body let _ = (every, parameter);: cargo run -p xtask -- mod-api replaces it with mod_api::dispatch_<hook>(self, mod_api::mods(), …), and --check reports a placeholder still to fill. Any other body without the dispatch call is an error, named and never changed. Free-function hooks stay wired by hand.

For open hook PRs

Once this merges, an open hook PR fails generated_output_is_current until it merges main and runs cargo run -p xtask -- mod-api. A placeholder body gets its dispatch filled, and a hook without a mod_api entry adds one line. Conflicts in generated.rs (#6724, #6732, #6728, #6612) are fixed by regenerating, not by hand.

Tested in game

Run on the server thread with a throwaway trait mod built through the launcher, at cda126efbc, which has the same game code as this head (later commits changed only xtask, fragments and docs). These are the three hooks this change rewires through NativeClientHooks:

Hook Result
menu_slot_rules PASS: on a throwaway mod menu machine_sample:proof, the mod capped slot 0 at 16. Inserting 64 cobblestone left 16 in the server-side container and 48 on the cursor
ingredient PASS: the mod filled the custom kind proofmod:aspect with dirt (log INGREDIENT_PROOF proofmod:aspect -> ["minecraft:dirt"]), and a shapeless recipe using it crafted a diamond from dirt in a crafting table
living_breathe PASS: with a survival player underwater, the hook fired for the player (log BREATHE_PROOF entity=2 kind=minecraft:player can_breathe=false consume=1 refill=0) and air kept falling as vanilla's does; the mod only logged

Test route: https://github.com/arismoko/horizon-machine-sample (used, with a throwaway trait mod)

Checks

All at this head:

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings, and -p horizon-client --no-default-features
  • cargo test -p xtask (19 passed), cargo run -p xtask -- mod-api --check
  • cargo test -p horizon-client --lib native_ (100 passed), -p horizon-client-lib --lib native_, crafting and installed_slot_rules (12, 18 and 1 passed)
  • cargo check --workspace
  • cargo test -p horizon-world --test native_load_hooks (1 passed)

pr_ready at 121c848cff (tools/pr_ready.py --quick --base f31198cbf7 on f2196cc12001, against f31198cbf7 at f31198cbf, 2 min 6 s)

Check Result
Scope ⚠️ 37 files, +7038 −1798; 8799 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 602 passed (32 s)
rustfmt ✅ (7 s)
clippy ✅ (1 s)
tests: horizon-client, horizon-client-lib, horizon-world, xtask ✅ 2382 passed (57 s)
doc tests ✅ 0 passed (19 s)
content root tests ➖ content root untouched
mod API up to date ✅ (10 s)
tokens.css up to date ✅
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)

Most of the diff is the regenerated crates/horizon-client/src/mod_api/generated.rs; cargo run -p xtask -- mod-api --check verifies it.

Please merge with a merge commit rather than squash, so commit authorship is kept.

🤖 Generated with Dyna.


🔄 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/6253 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `v2/ses_01M6C18WAJKS3HWAKR2EKX5REX-u9b` --- ### 📝 Commits (4) - [`8d9a75e`](https://github.com/horizon-rust/horizon/commit/8d9a75e8ef6b1751619edbe672768bda8c94603d) Mod API: trait methods for every hook - [`0cc0fd1`](https://github.com/horizon-rust/horizon/commit/0cc0fd1510efc7101edfa7a30760f741b73cd3de) Mod API: client-library hooks through NativeClientHooks - [`c73dbb7`](https://github.com/horizon-rust/horizon/commit/c73dbb7b7d090ec743ed91bfc28a7383c61365c6) xtask mod-api fills new hooks' dispatch placeholders - [`121c848`](https://github.com/horizon-rust/horizon/commit/121c848cff0917acb0dd5cf955085c66a12f0c82) Docs: native mod trait hooks ### 📊 Changes **37 files changed** (+7038 additions, -1798 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/breathing.rs` (+1 -1) 📝 `crates/horizon-client/src/client_lib.rs` (+1 -0) 📝 `crates/horizon-client/src/crafting.rs` (+1 -1) 📝 `crates/horizon-client/src/entry.rs` (+47 -0) 📝 `crates/horizon-client/src/game.rs` (+10 -0) 📝 `crates/horizon-client/src/game/maps.rs` (+0 -1) 📝 `crates/horizon-client/src/game/mod_api_host_generated.rs` (+109 -0) 📝 `crates/horizon-client/src/game/native_block_entity_draw.rs` (+0 -2) 📝 `crates/horizon-client/src/game/native_claimed_items.rs` (+15 -18) 📝 `crates/horizon-client/src/game/native_data_maps.rs` (+3 -3) 📝 `crates/horizon-client/src/game/native_falling.rs` (+1 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+344 -162) 📝 `crates/horizon-client/src/game/native_mob_draw.rs` (+0 -2) 📝 `crates/horizon-client/src/game/native_server.rs` (+1 -2) 📝 `crates/horizon-client/src/game/native_world_columns.rs` (+7 -6) 📝 `crates/horizon-client/src/game/native_world_edit.rs` (+13 -14) 📝 `crates/horizon-client/src/menu.rs` (+26 -1) 📝 `crates/horizon-client/src/mod_api.rs` (+15 -1) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+5103 -1445) 📝 `crates/horizon-client/src/mod_api/generated_host.rs` (+161 -0) _...and 17 more files_ </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Gives every native hook a trait method, so a trait mod can answer any hook in the catalog or the pending fragments through `Hooks`, and lets `cargo run -p xtask -- mod-api` fill a new hook's dispatch call. ## What it does - **Every hook gets a trait method.** The generator now reads the pending fragments as well as `native-hooks.json`, and rejects duplicate names. The 91 hooks that had none get a `mod_api` entry that follows the NeoForge counterpart and the existing entries. Every hook now needs one: the check fails naming any hook without it. The game's hook bodies call `mod_api::dispatch_<hook>(self, mod_api::mods(), …)`. - **Client-library hooks.** `menu_slot_rules`, `living_breathe` and `ingredient` are free functions in horizon-client-lib, which can't see the mod list. One `NativeClientHooks` struct of callbacks is installed once from the executable's entry point, as horizon-world's `NativeLoadHooks` is. - **Host helpers.** The new hooks' helpers on `Host`, such as `edit_blocks`, `surface_heights`, `raycast`, `view_hit`, `claim_items` and `mod_screen_open`. - **Docs.** "Adding a hook" in `docs/native-mods.md`. ## Hooks | Contract | Hooks | |---|---| | `cancel` | `block_highlight`, `entity_mount`, `entity_tick_pre`, `experience_orb_merge`, `experience_orb_pickup`, `gui_layer_pre`, `interaction_key`, `item_damaged`, `living_entity_use_item_start`, `living_entity_use_item_stop`, `living_entity_use_item_tick`, `living_knockback`, `mob_submit`, `mouse_button_pre`, `mouse_scrolling`, `perform_console_command`, `player_command`, `player_fish`, `player_game_mode_changed`, `player_submit`, `player_toggle_flight`, `projectile_impact`, `render_hand`, `screen_char_typed_pre`, `screen_key_pressed_pre`, `screen_key_released_pre`, `screen_mouse_dragged_pre`, `screen_mouse_scrolled_pre`, `sign_changed` | | `listen` (values written back) | `biome_colors`, `camera_distance`, `camera_shake`, `can_eat`, `client_level_load`, `client_level_unload`, `client_resources_reloaded`, `compute_fog_color`, `compute_fov`, `difficulty_changed`, `entity_tick_post`, `experience_orb_can_merge`, `framerate_limit`, `gui_layer_post`, `input_key`, `item_crafted`, `item_decorations`, `level_load`, `level_unload`, `living_breathe`, `living_entity_use_item_finish`, `living_equipment_change`, `mending_repair`, `menu_slot_rules`, `mob_layer`, `mod_container_viewers`, `mouse_button_post`, `music`, `on_use_tick`, `player_changed_dimension`, `player_container_close`, `player_container_open`, `player_respawned`, `player_start_tracking`, `player_stop_tracking`, `recipes_received`, `release_using`, `render_fog`, `server_data_loaded`, `shader_params`, `use_animation`, `use_duration` | | `collect` | `blocks`, `data_map_types`, `data_pack_files`, `datapack_sync`, `entity_tick_listened`, `experience_orb_pickup_listened`, `hears_projectile_impacts`, `ingredient`, `items`, `living_equipment_listened`, `loot_condition`, `loot_function`, `map_decorations`, `music_layers`, `player_render_listened`, `standalone_models` | | `replace` | `block_entity_energy`, `fire_odds`, `item_fluid_tank`, `smoke_source` | `cancel` stops later mods with `Flow::Cancel`; `listen` passes the hook's mutable values through mods in order; `collect` passes one shared list; `replace` lets a mod supply the result. ## New hooks: placeholder fill Every hook needs a `mod_api` entry; the check fails naming any hook without one. A new `Game` hook can start with the placeholder body `let _ = (every, parameter);`: `cargo run -p xtask -- mod-api` replaces it with `mod_api::dispatch_<hook>(self, mod_api::mods(), …)`, and `--check` reports a placeholder still to fill. Any other body without the dispatch call is an error, named and never changed. Free-function hooks stay wired by hand. ## For open hook PRs Once this merges, an open hook PR fails `generated_output_is_current` until it merges main and runs `cargo run -p xtask -- mod-api`. A placeholder body gets its dispatch filled, and a hook without a `mod_api` entry adds one line. Conflicts in `generated.rs` (#6724, #6732, #6728, #6612) are fixed by regenerating, not by hand. ## Tested in game Run on the server thread with a throwaway trait mod built through the launcher, at cda126efbc, which has the same game code as this head (later commits changed only xtask, fragments and docs). These are the three hooks this change rewires through `NativeClientHooks`: | Hook | Result | |---|---| | `menu_slot_rules` | PASS: on a throwaway mod menu `machine_sample:proof`, the mod capped slot 0 at 16. Inserting 64 cobblestone left 16 in the server-side container and 48 on the cursor | | `ingredient` | PASS: the mod filled the custom kind `proofmod:aspect` with dirt (log `INGREDIENT_PROOF proofmod:aspect -> ["minecraft:dirt"]`), and a shapeless recipe using it crafted a diamond from dirt in a crafting table | | `living_breathe` | PASS: with a survival player underwater, the hook fired for the player (log `BREATHE_PROOF entity=2 kind=minecraft:player can_breathe=false consume=1 refill=0`) and air kept falling as vanilla's does; the mod only logged | Test route: https://github.com/arismoko/horizon-machine-sample (used, with a throwaway trait mod) ## Checks All at this head: - `cargo fmt --all -- --check` - `cargo clippy --workspace --all-targets -- -D warnings`, and `-p horizon-client --no-default-features` - `cargo test -p xtask` (19 passed), `cargo run -p xtask -- mod-api --check` - `cargo test -p horizon-client --lib native_` (100 passed), `-p horizon-client-lib --lib native_`, `crafting` and `installed_slot_rules` (12, 18 and 1 passed) - `cargo check --workspace` - `cargo test -p horizon-world --test native_load_hooks` (1 passed) **pr_ready** at 121c848cff (`tools/pr_ready.py --quick --base f31198cbf7` on f2196cc12001, against f31198cbf7 at f31198cbf, 2 min 6 s) | Check | Result | | --- | --- | | Scope | ⚠️ 37 files, +7038 −1798; 8799 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 602 passed (32 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 s) | | tests: horizon-client, horizon-client-lib, horizon-world, xtask | ✅ 2382 passed (57 s) | | doc tests | ✅ 0 passed (19 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (10 s) | | tokens.css up to date | ✅ | | 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) | Most of the diff is the regenerated `crates/horizon-client/src/mod_api/generated.rs`; `cargo run -p xtask -- mod-api --check` verifies it. Please merge with a merge commit rather than squash, so commit authorship is kept. 🤖 Generated with Dyna. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:26:02 +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#6745
No description provided.