[PR #2013] [MERGED] Mod API: zoom the camera and take the mouse wheel (render, input) #3937

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

📋 Pull Request Information

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

Base: main ← Head: feat/mod-api-zoom


📝 Commits (3)

  • 48db367 Mod API: zoom the camera, take the mouse wheel (render, input)
  • 1e317cf Merge branch 'feat/mod-api-extras' into feat/mod-api-zoom
  • de294e3 rustfmt

📊 Changes

12 files changed (+282 additions, -24 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+2 -0)
📝 crates/horizon-client/src/game/extras.rs (+22 -9)
📝 crates/horizon-client/src/game/mod_input.rs (+60 -2)
📝 crates/horizon-client/src/game/mods.rs (+4 -0)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+24 -1)
📝 crates/horizon-mods/src/manifest.rs (+2 -2)
📝 crates/horizon-mods/src/runtime.rs (+67 -1)
📝 crates/horizon-mods/tests/sandbox.rs (+50 -0)
📝 crates/horizon-mods/tests/ui_guest/src/lib.rs (+24 -2)
📝 docs/api/mods-reference.md (+14 -3)
📝 docs/api/stability.md (+11 -2)
📝 docs/mods.md (+2 -2)

📄 Description

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

Stacked on #1963 (the calls the official HUD mods use), itself on #1944. Review only the last commit (Mod API: zoom the camera, take the mouse wheel). Until those merge, the diff also shows their commits.

This is the API the official Zoom mod needs: zoom is the next extra to move to the mod browser, after the FPS counter and Keystrokes (#1982, #1995).

What a modder can do now

  • render.set-zoom(zoom { factor, smooth, turn }) zooms the camera until the next call:
    • factor divides the field of view: 1 is none, at most 10.
    • smooth eases in and out through the game's own field-of-view easing (Camera.tickFov), as the spyglass does. Otherwise the zoom applies at once.
    • turn scales mouse turning while zoomed: 1 keeps the player's sensitivity, at least 0.05.
    • It applies only while playing: with a screen open, or through a spyglass (the spyglass wins), the camera is vanilla's. With several mods zooming, the strongest counts. The built-in zoom keeps working beside it until its removal PR.
  • input.claim-wheel(on) takes the mouse wheel while playing. Its steps become the mod's wheel(f32) events (positive away from the player, one per notch), and the hotbar doesn't move. The game gives the wheel back when the mod stops.
  • A screen opening lets the mod's held keys up (key-up), so a mod never stays zoomed behind the inventory. Keys bound to mouse buttons (key.mouse.4, which register-key already accepted) are now heard.

The consume choice (docs/api/stability.md)

claim-wheel is the one input a mod consumes. claim-items takes the use button only on the items it names, and a mod's keys never consume: vanilla's mapping on the same key still runs. This is written down in docs/api/stability.md ("The experimental mod APIs' choices"), as agreed, together with the note that input's new wheel event breaks input mods built before it that call poll. That's allowed because input is experimental.

How tested

  • Sandbox tests (crates/horizon-mods/tests/sandbox.rs):
    • zoom clamping (over 10, a turn under 0.05, NaN) and the strongest zoom;
    • the wheel only while claimed;
    • held keys let go once when a screen opens, and the release that follows isn't sent again.
  • In game, with the test guest as a --dev-mod, in-frame and on the server thread, fresh HORIZON_HOME/XDG folders and HORIZON_NO_AUDIO=1. 11 checks in each mode, 22/22:
    • zoom ×4 changes the view, and the smooth zoom settles on the same view as the instant one;
    • mouse-move 400 0 turns exactly 0.25 as far while zoomed with turn 0.25;
    • factor 1 is vanilla again (compared with the HUD hidden, the time of day fixed, and after the ~15 s brightening that follows joining a world, which isn't zoom's);
    • through a spyglass the mod's zoom changes nothing;
    • unclaimed, the wheel moves the hotbar; claimed, the hotbar stays and the mod hears wheel -1, wheel 1, wheel 1; given back, the hotbar moves again;
    • holding the mod's key, opening chat sends its key-up;
    • no panic and no stopped mod in the log.

Self-check against #1963's head:

pr_ready (tools/pr_ready.py --quick --base 50c54098e on Ludovics-Mac-mini, against 50c54098e at 50c54098e, 6 min 10 s)

Check Result
Scope ✅ 12 files, +273 −24
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (fixed in rustfmt after this run; cargo fmt --all --check passes)
clippy ✅ (41 s)
tests: horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest ✅ 1300 passed (3 min 50 s)
doc tests ✅ 1 passed (39 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (11 s)
launcher tests ✅ 128 passed (17 s)
Parity ➖ 111 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 99 more

skip-release: API only, players see no change until the Zoom mod ships.

🤖 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/2013 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-api-zoom` --- ### 📝 Commits (3) - [`48db367`](https://github.com/horizon-rust/horizon/commit/48db367d4a32e7ad5ee6bfa51765052c375d25d9) Mod API: zoom the camera, take the mouse wheel (render, input) - [`1e317cf`](https://github.com/horizon-rust/horizon/commit/1e317cff5ef90781b50e24c0dec8980d77823426) Merge branch 'feat/mod-api-extras' into feat/mod-api-zoom - [`de294e3`](https://github.com/horizon-rust/horizon/commit/de294e34bbddb7bb2e8dc48c86efe1c662421e53) rustfmt ### 📊 Changes **12 files changed** (+282 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+2 -0) 📝 `crates/horizon-client/src/game/extras.rs` (+22 -9) 📝 `crates/horizon-client/src/game/mod_input.rs` (+60 -2) 📝 `crates/horizon-client/src/game/mods.rs` (+4 -0) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+24 -1) 📝 `crates/horizon-mods/src/manifest.rs` (+2 -2) 📝 `crates/horizon-mods/src/runtime.rs` (+67 -1) 📝 `crates/horizon-mods/tests/sandbox.rs` (+50 -0) 📝 `crates/horizon-mods/tests/ui_guest/src/lib.rs` (+24 -2) 📝 `docs/api/mods-reference.md` (+14 -3) 📝 `docs/api/stability.md` (+11 -2) 📝 `docs/mods.md` (+2 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Stacked on #1963** (the calls the official HUD mods use), itself on #1944. Review only the last commit (`Mod API: zoom the camera, take the mouse wheel`). Until those merge, the diff also shows their commits. This is the API the official Zoom mod needs: zoom is the next extra to move to the mod browser, after the FPS counter and Keystrokes (#1982, #1995). ## What a modder can do now - **`render.set-zoom(zoom { factor, smooth, turn })`** zooms the camera until the next call: - `factor` divides the field of view: 1 is none, at most 10. - `smooth` eases in and out through the game's own field-of-view easing (`Camera.tickFov`), as the spyglass does. Otherwise the zoom applies at once. - `turn` scales mouse turning while zoomed: 1 keeps the player's sensitivity, at least 0.05. - It applies only while playing: with a screen open, or through a spyglass (the spyglass wins), the camera is vanilla's. With several mods zooming, the strongest counts. The built-in zoom keeps working beside it until its removal PR. - **`input.claim-wheel(on)`** takes the mouse wheel while playing. Its steps become the mod's `wheel(f32)` events (positive away from the player, one per notch), and the hotbar doesn't move. The game gives the wheel back when the mod stops. - **A screen opening lets the mod's held keys up** (`key-up`), so a mod never stays zoomed behind the inventory. Keys bound to mouse buttons (`key.mouse.4`, which `register-key` already accepted) are now heard. ## The consume choice (docs/api/stability.md) `claim-wheel` is the one input a mod consumes. `claim-items` takes the use button only on the items it names, and a mod's keys never consume: vanilla's mapping on the same key still runs. This is written down in `docs/api/stability.md` ("The experimental mod APIs' choices"), as agreed, together with the note that `input`'s new `wheel` event breaks `input` mods built before it that call `poll`. That's allowed because `input` is experimental. ## How tested - **Sandbox tests** (`crates/horizon-mods/tests/sandbox.rs`): - zoom clamping (over 10, a turn under 0.05, NaN) and the strongest zoom; - the wheel only while claimed; - held keys let go once when a screen opens, and the release that follows isn't sent again. - **In game**, with the test guest as a `--dev-mod`, in-frame and on the server thread, fresh `HORIZON_HOME`/XDG folders and `HORIZON_NO_AUDIO=1`. 11 checks in each mode, 22/22: - zoom ×4 changes the view, and the smooth zoom settles on the same view as the instant one; - `mouse-move 400 0` turns exactly 0.25 as far while zoomed with `turn` 0.25; - `factor` 1 is vanilla again (compared with the HUD hidden, the time of day fixed, and after the ~15 s brightening that follows joining a world, which isn't zoom's); - through a spyglass the mod's zoom changes nothing; - unclaimed, the wheel moves the hotbar; claimed, the hotbar stays and the mod hears `wheel -1`, `wheel 1`, `wheel 1`; given back, the hotbar moves again; - holding the mod's key, opening chat sends its `key-up`; - no panic and no stopped mod in the log. **Self-check** against #1963's head: **pr_ready** (`tools/pr_ready.py --quick --base 50c54098e` on Ludovics-Mac-mini, against 50c54098e at 50c54098e, 6 min 10 s) | Check | Result | | --- | --- | | Scope | ✅ 12 files, +273 −24 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (fixed in `rustfmt` after this run; `cargo fmt --all --check` passes) | | clippy | ✅ (41 s) | | tests: horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest | ✅ 1300 passed (3 min 50 s) | | doc tests | ✅ 1 passed (39 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (11 s) | | launcher tests | ✅ 128 passed (17 s) | | Parity | ➖ 111 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 99 more | `skip-release`: API only, players see no change until the Zoom mod ships. 🤖 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:13:24 +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#3937
No description provided.