[PR #7044] [MERGED] Mod API: the Mods switch, mod keys, settings and level sounds and particles in Host #7292

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

📋 Pull Request Information

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

Base: main ← Head: v2/ses_01M6DMWRZSPA9JSD7HP0ZN2DNJ-de547a67e904


📝 Commits (4)

  • df7afc3 xtask: let Host expose receiverless helpers as &self methods
  • 1cd6ba0 mod API: expose on, mod_key, settings, set_block_property and config_dir in Host
  • 8c7a495 Add play_sound and send_particles to LevelWriteHost
  • 292df3c Format the play_sound delegation

📊 Changes

8 files changed (+163 additions, -8 deletions)

View changed files

📝 crates/horizon-client/src/game/mod_api_host.rs (+25 -0)
📝 crates/horizon-client/src/game/mod_api_host_generated.rs (+27 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+2 -2)
📝 crates/horizon-client/src/mod_api.rs (+20 -0)
📝 crates/horizon-client/src/mod_api/generated_host.rs (+39 -0)
📝 docs/native-mods.md (+4 -2)
📝 native-hooks.json (+28 -0)
📝 xtask/src/mod_api.rs (+18 -4)

📄 Description

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

Part of #6452 (the item "Host helpers that need no new types").

What it does

A trait mod could not honour the player's Options > Mods switch, read its own key binding, keep a setting, or play a sound or send particles from a level hook. The Game helpers that do these things already exist and take only primitive types, but they were in neither Host nor the docs' list of exclusions.

  • Host gains on, mod_key, setting, set_setting, set_block_property, set_block_property_with and config_dir. Each is a catalog helpers entry, and the generated Host and its implementation were regenerated with cargo run -p xtask -- mod-api. Each keeps its helper's documentation.
  • The generator now accepts a helper without self (native_config_dir): in Host it takes &self and calls Game::native_config_dir(). A test covers the mapping, and a by-value self is still rejected.
  • LevelWriteHost (the host of random_tick, tick_block and perform_bonemeal) gains play_sound and send_particles, delegating to GameLevel::native_play_sound and native_send_particles. mod_api re-exports the existing ParticleOptions and ParticleType so a trait mod can build the argument.
  • docs/native-mods.md says which host has what.

No new types, hooks or behaviour, and no NATIVE_HOOKS_API change. refresh_biome_colors, also named in the issue, is already in Host on main.

Counterparts

  • mod_key reads the binding of a key a mod lists through the mods hook. NeoForge: KeyMapping, registered with RegisterKeyMappingsEvent (key mappings).
  • setting, set_setting and config_dir are the mod's own stored settings and the shared config/ folder. NeoForge: ModConfigSpec files in config/ (configuration).
  • play_sound and send_particles are vanilla 26.3's Level.playSound and ServerLevel.sendParticles. They go on the ServerLevel-like LevelWriteHost only.

Tested in game

https://github.com/arismoko/horizon-machine-sample (the recommended end-to-end route, used here): its trait API example on a throwaway branch pinned to this head (292df3c604), run through horizon-ctl with --dev-mod in a creative world, on the server thread.

Check Result
key hook reads on, mod_key, setting, config_dir ✅ pressing Z logged on=true lens=key.keyboard.z match=true and the game's config folder
set_block_property_with from a server hook ✅ a stick on an unpowered redstone lamp logged server on=true, lit=true, and the block became redstone_lamp[lit=true]
play_sound and send_particles from random_tick ✅ with random_tick_speed 1000 over wheat, level sound=true particles=true at x y z lines, and green sparkles on the crops
The Mods switch and a rebound key ✅ restarted with mod.machine_sample:false and the key on K in horizon-mods.txt: K logged on=false … match=true, Z match=false, and the server hook saw on=false
Dedicated server (--dedicated --nogui, one client joined) ✅ level sound=true particles=true lines from the level host

The key row needed one local change that this PR doesn't make: on main, mod_api has pub use winit::event::KeyEvent (mod_api.rs:53), which shadows the generated KeyEvent<'_> that Hooks::key takes, so a mod crate can't implement key (E0107/E0053). The test build dropped that re-export. It is a separate bug, from #6216; a fix follows in its own PR.

pr_ready

pr_ready (tools/pr_ready.py --quick --base cabe8b5de7d0b45541c923c4a6b3c5cb3e3686c7 at 292df3c604, 13 min 28 s)

Check Result
Scope ✅ 8 files, +163 −8
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 610 run, FAILED (failures=1, skipped=1) (40 s)
rustfmt ✅ (10 s)
clippy ✅ (1 min 51 s)
tests: horizon-client, horizon-client-lib, xtask ✅ 2049 passed (8 min 36 s)
doc tests ✅ 0 passed (1 min 42 s)
content root tests ➖ content root untouched
mod API up to date ✅ (27 s)
tokens.css up to date ✅
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 377 affected, to run in CI (--quick)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The one Python failure, test_world_input_capture.test_native_split_mouse_turns_only_its_owner, fails the same way at the base cabe8b5de and passes on current main; this PR touches no Python or input code.

🤖 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/7044 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `v2/ses_01M6DMWRZSPA9JSD7HP0ZN2DNJ-de547a67e904` --- ### 📝 Commits (4) - [`df7afc3`](https://github.com/horizon-rust/horizon/commit/df7afc32e972fdc8616f64e8c6481e7706e93ae6) xtask: let Host expose receiverless helpers as &self methods - [`1cd6ba0`](https://github.com/horizon-rust/horizon/commit/1cd6ba0960b16afb04f1550fc8fd9ef88e27bf92) mod API: expose on, mod_key, settings, set_block_property and config_dir in Host - [`8c7a495`](https://github.com/horizon-rust/horizon/commit/8c7a49575f64613f4ae0cc2064642b27bff4a470) Add play_sound and send_particles to LevelWriteHost - [`292df3c`](https://github.com/horizon-rust/horizon/commit/292df3c60443746c9f22e77bfc4fb5d4722426b2) Format the play_sound delegation ### 📊 Changes **8 files changed** (+163 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/mod_api_host.rs` (+25 -0) 📝 `crates/horizon-client/src/game/mod_api_host_generated.rs` (+27 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+2 -2) 📝 `crates/horizon-client/src/mod_api.rs` (+20 -0) 📝 `crates/horizon-client/src/mod_api/generated_host.rs` (+39 -0) 📝 `docs/native-mods.md` (+4 -2) 📝 `native-hooks.json` (+28 -0) 📝 `xtask/src/mod_api.rs` (+18 -4) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Part of #6452 (the item "`Host` helpers that need no new types"). ## What it does A trait mod could not honour the player's Options > Mods switch, read its own key binding, keep a setting, or play a sound or send particles from a level hook. The `Game` helpers that do these things already exist and take only primitive types, but they were in neither `Host` nor the docs' list of exclusions. - **`Host` gains** `on`, `mod_key`, `setting`, `set_setting`, `set_block_property`, `set_block_property_with` and `config_dir`. Each is a catalog `helpers` entry, and the generated `Host` and its implementation were regenerated with `cargo run -p xtask -- mod-api`. Each keeps its helper's documentation. - **The generator** now accepts a helper without `self` (`native_config_dir`): in `Host` it takes `&self` and calls `Game::native_config_dir()`. A test covers the mapping, and a by-value `self` is still rejected. - **`LevelWriteHost`** (the host of `random_tick`, `tick_block` and `perform_bonemeal`) gains `play_sound` and `send_particles`, delegating to `GameLevel::native_play_sound` and `native_send_particles`. `mod_api` re-exports the existing `ParticleOptions` and `ParticleType` so a trait mod can build the argument. - **`docs/native-mods.md`** says which host has what. No new types, hooks or behaviour, and no `NATIVE_HOOKS_API` change. `refresh_biome_colors`, also named in the issue, is already in `Host` on main. ## Counterparts - `mod_key` reads the binding of a key a mod lists through the `mods` hook. NeoForge: `KeyMapping`, registered with `RegisterKeyMappingsEvent` ([key mappings](https://docs.neoforged.net/docs/misc/keymappings/)). - `setting`, `set_setting` and `config_dir` are the mod's own stored settings and the shared `config/` folder. NeoForge: `ModConfigSpec` files in `config/` ([configuration](https://docs.neoforged.net/docs/misc/config/)). - `play_sound` and `send_particles` are vanilla 26.3's `Level.playSound` and `ServerLevel.sendParticles`. They go on the `ServerLevel`-like `LevelWriteHost` only. ## Tested in game https://github.com/arismoko/horizon-machine-sample (the recommended end-to-end route, used here): its trait API example on a throwaway branch pinned to this head (292df3c604), run through `horizon-ctl` with `--dev-mod` in a creative world, on the server thread. | Check | Result | | --- | --- | | `key` hook reads `on`, `mod_key`, `setting`, `config_dir` | ✅ pressing Z logged `on=true lens=key.keyboard.z match=true` and the game's `config` folder | | `set_block_property_with` from a server hook | ✅ a stick on an unpowered redstone lamp logged `server on=true`, `lit=true`, and the block became `redstone_lamp[lit=true]` | | `play_sound` and `send_particles` from `random_tick` | ✅ with `random_tick_speed` 1000 over wheat, `level sound=true particles=true at x y z` lines, and green sparkles on the crops | | The Mods switch and a rebound key | ✅ restarted with `mod.machine_sample:false` and the key on K in `horizon-mods.txt`: K logged `on=false … match=true`, Z `match=false`, and the server hook saw `on=false` | | Dedicated server (`--dedicated --nogui`, one client joined) | ✅ `level sound=true particles=true` lines from the level host | The `key` row needed one local change that this PR doesn't make: on main, `mod_api` has `pub use winit::event::KeyEvent` (`mod_api.rs:53`), which shadows the generated `KeyEvent<'_>` that `Hooks::key` takes, so a mod crate can't implement `key` (E0107/E0053). The test build dropped that re-export. It is a separate bug, from #6216; a fix follows in its own PR. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base cabe8b5de7d0b45541c923c4a6b3c5cb3e3686c7` at 292df3c604, 13 min 28 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +163 −8 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 610 run, FAILED (failures=1, skipped=1) (40 s) | | rustfmt | ✅ (10 s) | | clippy | ✅ (1 min 51 s) | | tests: horizon-client, horizon-client-lib, xtask | ✅ 2049 passed (8 min 36 s) | | doc tests | ✅ 0 passed (1 min 42 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (27 s) | | tokens.css up to date | ✅ | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 377 affected, to run in CI (--quick) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The one Python failure, `test_world_input_capture.test_native_split_mouse_turns_only_its_owner`, fails the same way at the base cabe8b5de and passes on current main; this PR touches no Python or input code. 🤖 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:37:15 +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#7292
No description provided.