[PR #1944] [MERGED] Mod API: capability input (experimental): claimed items' use, mod keys #3880

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

📋 Pull Request Information

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

Base: main ← Head: feat/mod-input


📝 Commits (2)

  • fada660 Mod API: capability input (experimental): claimed items' use, mod keys
  • b7b7cd6 Merge main into feat/mod-input: input beside command and render

📊 Changes

15 files changed (+459 additions, -10 deletions)

View changed files

📝 crates/cargo-horizon-mod/src/check.rs (+1 -0)
📝 crates/horizon-client/src/game.rs (+6 -0)
📝 crates/horizon-client/src/game/control.rs (+5 -0)
➕ crates/horizon-client/src/game/mod_input.rs (+92 -0)
📝 crates/horizon-client/src/game/mods.rs (+5 -0)
📝 crates/horizon-mod-sdk/src/lib.rs (+1 -1)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+44 -0)
📝 crates/horizon-mods/src/manifest.rs (+12 -2)
📝 crates/horizon-mods/src/runtime.rs (+153 -0)
📝 crates/horizon-mods/tests/sandbox.rs (+64 -3)
📝 crates/horizon-mods/tests/ui_guest/src/lib.rs (+29 -1)
📝 docs/api/mods-reference.md (+42 -2)
📝 docs/api/mods.md (+2 -0)
📝 docs/api/stability.md (+1 -0)
📝 docs/mods.md (+2 -1)

📄 Description

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

Stacked on #1929 (render), itself on #1864 (ui). Review only the last commit, fada66031. Until those merge, the diff also shows their commits.

What a modder can do now

A mod takes over the use button on its own items and adds keys. Experimental: experimental = ["input"] beside capabilities = ["input"].

input::claim_items(&["mymod:wand".into()]);
input::register_key("wheel", "Open the spell wheel", "key.keyboard.r")?;
// each tick:
for event in input::poll() {
    match event {
        Event::UseStart(u) => start_aiming(),
        Event::UseStop(u) => fire(u.ticks),
        Event::KeyDown(k) if k == "wheel" => open_wheel(),
        _ => {}
    }
}
  • claim-items(ids) (at most 64): a right-click with a claimed item in the main hand is the mod's use-start. The game does nothing else with the click: no placing, no eating, no swing. use-stop gives the ticks held. It comes when the button comes up, the item leaves the hand (slot switch, dropped) or a screen opens, as vanilla's release does.
  • register-key(name, label, key) (at most 16): key.keyboard.r as options.txt writes keys. While playing with no screen open, the key is heard as key-down / key-up with the mod's own name. The game's mapping on the same key still runs. A key that isn't in that form is an error.
  • held(): the main hand's stack (id, count, slot), as of this tick.
  • poll(): the events since the last call, oldest first, at most 256 kept.

This is what Orbital Laser needs from input: its designator and remote items, and its wheel key.

How it works

  • horizon-mods: per-mod InputState (claims, keys, event queue). Mods::use_start, use_stop and key push to the mods that claimed the item or own the key. claims, claims_any, has_keys and mod_keys serve the game. Snapshot::held is new.
  • game/mod_input.rs:
    • play_mouse asks mod_use first, which covers local and remote windows (server thread, LAN guest, multiplayer).
    • tick_mod_use ends a use whose item left the hand or under a screen.
    • The keyboard and horizon-ctl's key send the physical key to mod_key, so an agent's keys reach mods as a player's do.
  • No claim and no key, no cost: mod_use returns after claims_any(), mod_key after has_keys(), tick_mod_use after using.is_none(). Without the mods feature they're empty functions.

How tested

  • cargo test -p horizon-mods --features runtime,pack: new input_claims_keys_and_events. It covers claims, a refused key, mod_keys, events in order (use-start 0, key-down, key-up, use-stop 12, and an unregistered key ignored), and held from the snapshot. manifest: input needs the opt-in.
  • In game (--features mods, fresh HORIZON_HOME and XDG folders, HORIZON_NO_AUDIO=1), in-frame and on the server thread, 7/7 each:
    • /input_claim registers R and refuses "R".
    • /input_held answers minecraft:stick x3.
    • A right-click (window mouse event) with the claimed stick gives use-start minecraft:stick 0 and use-stop.
    • R gives key-down wheel and key-up wheel.
    • No panic.
  • Clippy -D warnings, with and without mods. The API reference is regenerated.

Self-check (against #1929's head):

pr_ready (tools/pr_ready.py --quick --base 61c44c22e on ludovics-mac-mini, against 61c44c22e at 61c44c22e, 13 min 46 s)

Check Result
Scope ✅ 15 files, +459 −10
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (9 s)
clippy ✅ (40 s)
tests: cargo-horizon-mod, horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest ✅ 1283 passed (10 min 19 s)
doc tests ✅ 1 passed (1 min 19 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (5 s)
launcher clippy ✅ (9 s)
launcher tests ✅ 126 passed (33 s)
Parity ➖ 107 affected, run in CI; locally interaction_input, local_input, menu_click, sprint_input, toggle_keys, use_item_on: 6 passed

Label skip-release: experimental, opt-in. No player sees a change without such a mod.

Leftovers

  • Mods' keys aren't listed in Options > Controls yet, so they can't be rebound there. Mods::mod_keys() has what that page needs.
  • held has no components (custom name, custom data) yet.

🤖 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/1944 **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/mod-input` --- ### 📝 Commits (2) - [`fada660`](https://github.com/horizon-rust/horizon/commit/fada660310d4dcc8b407219efef987a040b3805c) Mod API: capability input (experimental): claimed items' use, mod keys - [`b7b7cd6`](https://github.com/horizon-rust/horizon/commit/b7b7cd6c502c203f097af28621115c6327f1ec97) Merge main into feat/mod-input: input beside command and render ### 📊 Changes **15 files changed** (+459 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/cargo-horizon-mod/src/check.rs` (+1 -0) 📝 `crates/horizon-client/src/game.rs` (+6 -0) 📝 `crates/horizon-client/src/game/control.rs` (+5 -0) ➕ `crates/horizon-client/src/game/mod_input.rs` (+92 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+5 -0) 📝 `crates/horizon-mod-sdk/src/lib.rs` (+1 -1) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+44 -0) 📝 `crates/horizon-mods/src/manifest.rs` (+12 -2) 📝 `crates/horizon-mods/src/runtime.rs` (+153 -0) 📝 `crates/horizon-mods/tests/sandbox.rs` (+64 -3) 📝 `crates/horizon-mods/tests/ui_guest/src/lib.rs` (+29 -1) 📝 `docs/api/mods-reference.md` (+42 -2) 📝 `docs/api/mods.md` (+2 -0) 📝 `docs/api/stability.md` (+1 -0) 📝 `docs/mods.md` (+2 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Stacked on #1929** (`render`), itself on #1864 (`ui`). Review only the last commit, fada66031. Until those merge, the diff also shows their commits. ## What a modder can do now A mod takes over the use button on its own items and adds keys. **Experimental:** `experimental = ["input"]` beside `capabilities = ["input"]`. ```rust input::claim_items(&["mymod:wand".into()]); input::register_key("wheel", "Open the spell wheel", "key.keyboard.r")?; // each tick: for event in input::poll() { match event { Event::UseStart(u) => start_aiming(), Event::UseStop(u) => fire(u.ticks), Event::KeyDown(k) if k == "wheel" => open_wheel(), _ => {} } } ``` - **`claim-items(ids)`** (at most 64): a right-click with a claimed item in the main hand is the mod's `use-start`. The game does nothing else with the click: no placing, no eating, no swing. `use-stop` gives the ticks held. It comes when the button comes up, the item leaves the hand (slot switch, dropped) or a screen opens, as vanilla's release does. - **`register-key(name, label, key)`** (at most 16): `key.keyboard.r` as options.txt writes keys. While playing with no screen open, the key is heard as `key-down` / `key-up` with the mod's own name. The game's mapping on the same key still runs. A key that isn't in that form is an error. - **`held()`**: the main hand's stack (id, count, slot), as of this tick. - **`poll()`**: the events since the last call, oldest first, at most 256 kept. This is what Orbital Laser needs from `input`: its designator and remote items, and its wheel key. ## How it works - `horizon-mods`: per-mod `InputState` (claims, keys, event queue). `Mods::use_start`, `use_stop` and `key` push to the mods that claimed the item or own the key. `claims`, `claims_any`, `has_keys` and `mod_keys` serve the game. `Snapshot::held` is new. - `game/mod_input.rs`: - `play_mouse` asks `mod_use` first, which covers local and remote windows (server thread, LAN guest, multiplayer). - `tick_mod_use` ends a use whose item left the hand or under a screen. - The keyboard and horizon-ctl's `key` send the physical key to `mod_key`, so an agent's keys reach mods as a player's do. - **No claim and no key, no cost:** `mod_use` returns after `claims_any()`, `mod_key` after `has_keys()`, `tick_mod_use` after `using.is_none()`. Without the `mods` feature they're empty functions. ## How tested - `cargo test -p horizon-mods --features runtime,pack`: new `input_claims_keys_and_events`. It covers claims, a refused key, `mod_keys`, events in order (use-start 0, key-down, key-up, use-stop 12, and an unregistered key ignored), and `held` from the snapshot. `manifest`: `input` needs the opt-in. - In game (`--features mods`, fresh `HORIZON_HOME` and XDG folders, `HORIZON_NO_AUDIO=1`), in-frame and on the server thread, 7/7 each: - `/input_claim` registers R and refuses `"R"`. - `/input_held` answers `minecraft:stick x3`. - A right-click (window mouse event) with the claimed stick gives `use-start minecraft:stick 0` and `use-stop`. - R gives `key-down wheel` and `key-up wheel`. - No panic. - Clippy `-D warnings`, with and without `mods`. The API reference is regenerated. **Self-check** (against #1929's head): **pr_ready** (`tools/pr_ready.py --quick --base 61c44c22e` on ludovics-mac-mini, against 61c44c22e at 61c44c22e, 13 min 46 s) | Check | Result | | --- | --- | | Scope | ✅ 15 files, +459 −10 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (9 s) | | clippy | ✅ (40 s) | | tests: cargo-horizon-mod, horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest | ✅ 1283 passed (10 min 19 s) | | doc tests | ✅ 1 passed (1 min 19 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (5 s) | | launcher clippy | ✅ (9 s) | | launcher tests | ✅ 126 passed (33 s) | | Parity | ➖ 107 affected, run in CI; locally `interaction_input`, `local_input`, `menu_click`, `sprint_input`, `toggle_keys`, `use_item_on`: 6 passed | Label `skip-release`: experimental, opt-in. No player sees a change without such a mod. ## Leftovers - Mods' keys aren't listed in Options > Controls yet, so they can't be rebound there. `Mods::mod_keys()` has what that page needs. - `held` has no components (custom name, custom data) yet. 🤖 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:59 +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#3880
No description provided.