[PR #1677] [MERGED] Mod API: capability command, and a Predator Missile example #3681

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

📋 Pull Request Information

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

Base: main ← Head: feat/mod-command-capability


📝 Commits (7)

  • d4b2e24 Add mod command capability and Predator Missile example
  • f08546f Merge main into the mod command capability
  • c2c8df4 Mods: run a mod's commands on the next tick
  • 5262eff cargo horizon-mod check: list the commands a mod runs
  • 39904c8 docs/mods.md: the contract lists the command interface
  • a9e6818 Merge main (workspace: main's registry exclude + this branch's predator-missile example)
  • eec2e87 Merge main: command beside main's ui capability

📊 Changes

16 files changed (+314 additions, -15 deletions)

View changed files

📝 AGENTS.md (+1 -1)
📝 Cargo.lock (+7 -0)
📝 Cargo.toml (+1 -1)
📝 crates/cargo-horizon-mod/src/check.rs (+1 -0)
📝 crates/horizon-client/src/game/mods.rs (+23 -0)
➕ crates/horizon-mod-sdk/examples/predator-missile/Cargo.toml (+16 -0)
➕ crates/horizon-mod-sdk/examples/predator-missile/horizon-mod.toml (+8 -0)
➕ crates/horizon-mod-sdk/examples/predator-missile/src/lib.rs (+161 -0)
📝 crates/horizon-mod-sdk/src/lib.rs (+2 -2)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+9 -0)
📝 crates/horizon-mods/src/manifest.rs (+11 -1)
📝 crates/horizon-mods/src/runtime.rs (+16 -1)
📝 crates/horizon-mods/tests/sandbox.rs (+41 -4)
📝 docs/api/mods-reference.md (+13 -2)
📝 docs/api/stability.md (+1 -1)
📝 docs/mods.md (+3 -2)

📄 Description

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

What and why

Client mods can read the player and draw text, and nothing else. This adds one capability, command: a mod may run vanilla commands as the player, with the player's permissions, which opens up everything commands can do (summon, tp, effect, particle, fill) without new per-feature interfaces.

/// Capability `command`: vanilla commands run as the player, with the
/// player's permissions, after the hook call returns (8 per call). A mod's
/// own commands are not run this way.
interface command {
    run: func(line: string);
}
 command.run(line)             # host, runtime.rs
+  queue Output::Command { line } (at most 8 per call, clipped like chat)
 show_mod_output               # game/mods.rs, after the hook returns
+  Output::Command:
+    vanilla command name?  no → dropped (a mod calling a mod command could loop)
+    remote?  send_chat("/line")  else  run_command(line)

The player reads "May run commands as you, with your permissions" before turning the mod on. A player without permission gets vanilla's error, as if they had typed the command.

Example: examples/predator-missile. /missile turns the player into a guided missile 60 blocks up (spectator, glowing on every mob as the "thermal camera"). Each tick it moves the player along their own look, so the mouse steers. execute … unless block ^ ^ ^1.5 #minecraft:air run tellraw prints an impact line that the mod hears through its chat hook, and it sets off 4 primed TNT. Two seconds later the player is put back where they launched, in their game mode. About 160 lines of Rust and vanilla commands only.

This branch doesn't depend on the #1602 fix to build, but the example only runs in default single player once that fix is in (--in-frame works without it).

Also: the example joins the workspace (like coords-hud, and AGENTS.md's macOS --exclude list), docs/mods.md gets the capability row, and docs/api/mods-reference.md is regenerated.

The API stays at 0.1: an added import doesn't break existing mods, and a mod that imports command on an older game is refused by name ("imports horizon:mods/command@0.1.0, which Horizon does not offer"). Bump to 0.2 instead if you'd rather gate it by version. #1189 also adds a Capability variant, so whichever lands second rebases.

Evidence

  • cargo test -p horizon-mods --features runtime,pack: all pass, including the new predator_missile_runs_commands (loads the real example: /missile queues 6 launch commands, ticks queue the tp, the chat line Predator: impact queues 4 summon tnt) and the manifest check that an undeclared command import is refused.
  • In game (server thread, with the #1602 fix): launch, steer, impact and return all run; the impact point at y≈66 became air down to y=63.

Vanilla reference

Horizon-only (the mod system). The example uses only vanilla commands.

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on Simons-MacBook-Pro, against upstream/main at fe128948b, 3 min 50 s)

Check Result
Scope ✅ 14 files, +300 −12
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (3 s)
clippy ✅ (28 s)
tests: workspace ✅ 1949 passed (1 min 57 s)
doc tests ✅ 1 passed (28 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (2 s)
launcher clippy ✅ (22 s)
launcher tests ✅ 118 passed (30 s)
Parity ➖ 326 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 314 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Merge danger

Door: one-way for the API surface: once mods use command, removing it breaks them. Blast radius: mods that declare command. Nothing changes for other mods or for players without mods.

🤖 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/1677 **Author:** [@sdraeger](https://github.com/sdraeger) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-command-capability` --- ### 📝 Commits (7) - [`d4b2e24`](https://github.com/horizon-rust/horizon/commit/d4b2e24535111e7b8e1b839bcc16c4ef126fa663) Add mod command capability and Predator Missile example - [`f08546f`](https://github.com/horizon-rust/horizon/commit/f08546fd74de5a809aab02527e3306947e0b40b0) Merge main into the mod command capability - [`c2c8df4`](https://github.com/horizon-rust/horizon/commit/c2c8df4542b857911ec396e0430da5b46fdffdb1) Mods: run a mod's commands on the next tick - [`5262eff`](https://github.com/horizon-rust/horizon/commit/5262effa7e4b13cd4737563dabeda3dc03e2f8af) cargo horizon-mod check: list the commands a mod runs - [`39904c8`](https://github.com/horizon-rust/horizon/commit/39904c8051546efdb808f0fa9a8ccb68043f7dd2) docs/mods.md: the contract lists the command interface - [`a9e6818`](https://github.com/horizon-rust/horizon/commit/a9e6818d2a723b5379b262c3bfe49909b529b570) Merge main (workspace: main's registry exclude + this branch's predator-missile example) - [`eec2e87`](https://github.com/horizon-rust/horizon/commit/eec2e87a1578b44f30c1301adbcc5dae54a13ca3) Merge main: `command` beside main's `ui` capability ### 📊 Changes **16 files changed** (+314 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `AGENTS.md` (+1 -1) 📝 `Cargo.lock` (+7 -0) 📝 `Cargo.toml` (+1 -1) 📝 `crates/cargo-horizon-mod/src/check.rs` (+1 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+23 -0) ➕ `crates/horizon-mod-sdk/examples/predator-missile/Cargo.toml` (+16 -0) ➕ `crates/horizon-mod-sdk/examples/predator-missile/horizon-mod.toml` (+8 -0) ➕ `crates/horizon-mod-sdk/examples/predator-missile/src/lib.rs` (+161 -0) 📝 `crates/horizon-mod-sdk/src/lib.rs` (+2 -2) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+9 -0) 📝 `crates/horizon-mods/src/manifest.rs` (+11 -1) 📝 `crates/horizon-mods/src/runtime.rs` (+16 -1) 📝 `crates/horizon-mods/tests/sandbox.rs` (+41 -4) 📝 `docs/api/mods-reference.md` (+13 -2) 📝 `docs/api/stability.md` (+1 -1) 📝 `docs/mods.md` (+3 -2) </details> ### 📄 Description > 🤖 Opened by Simon's AI agent (Claude Code), not by Simon himself. ## What and why Client mods can read the player and draw text, and nothing else. This adds one capability, `command`: a mod may run vanilla commands as the player, with the player's permissions, which opens up everything commands can do (summon, tp, effect, particle, fill) without new per-feature interfaces. ```wit /// Capability `command`: vanilla commands run as the player, with the /// player's permissions, after the hook call returns (8 per call). A mod's /// own commands are not run this way. interface command { run: func(line: string); } ``` ```diff command.run(line) # host, runtime.rs + queue Output::Command { line } (at most 8 per call, clipped like chat) show_mod_output # game/mods.rs, after the hook returns + Output::Command: + vanilla command name? no → dropped (a mod calling a mod command could loop) + remote? send_chat("/line") else run_command(line) ``` The player reads "May run commands as you, with your permissions" before turning the mod on. A player without permission gets vanilla's error, as if they had typed the command. **Example: `examples/predator-missile`.** `/missile` turns the player into a guided missile 60 blocks up (spectator, glowing on every mob as the "thermal camera"). Each tick it moves the player along their own look, so the mouse steers. `execute … unless block ^ ^ ^1.5 #minecraft:air run tellraw` prints an impact line that the mod hears through its `chat` hook, and it sets off 4 primed TNT. Two seconds later the player is put back where they launched, in their game mode. About 160 lines of Rust and vanilla commands only. This branch doesn't depend on the #1602 fix to build, but the example only runs in default single player once that fix is in (`--in-frame` works without it). Also: the example joins the workspace (like coords-hud, and AGENTS.md's macOS `--exclude` list), `docs/mods.md` gets the capability row, and `docs/api/mods-reference.md` is regenerated. The API stays at 0.1: an added import doesn't break existing mods, and a mod that imports `command` on an older game is refused by name ("imports horizon:mods/command@0.1.0, which Horizon does not offer"). Bump to 0.2 instead if you'd rather gate it by version. #1189 also adds a `Capability` variant, so whichever lands second rebases. ## Evidence - `cargo test -p horizon-mods --features runtime,pack`: all pass, including the new `predator_missile_runs_commands` (loads the real example: `/missile` queues 6 launch commands, ticks queue the `tp`, the chat line `Predator: impact` queues 4 `summon tnt`) and the manifest check that an undeclared `command` import is refused. - In game (server thread, with the #1602 fix): launch, steer, impact and return all run; the impact point at y≈66 became air down to y=63. ## Vanilla reference Horizon-only (the mod system). The example uses only vanilla commands. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on Simons-MacBook-Pro, against upstream/main at fe128948b, 3 min 50 s) | Check | Result | | --- | --- | | Scope | ✅ 14 files, +300 −12 | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (3 s) | | clippy | ✅ (28 s) | | tests: workspace | ✅ 1949 passed (1 min 57 s) | | doc tests | ✅ 1 passed (28 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (2 s) | | launcher clippy | ✅ (22 s) | | launcher tests | ✅ 118 passed (30 s) | | Parity | ➖ 326 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 314 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## Merge danger **Door:** one-way for the API surface: once mods use `command`, removing it breaks them. **Blast radius:** mods that declare `command`. Nothing changes for other mods or for players without mods. 🤖 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:11:23 +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#3681
No description provided.