[GH-ISSUE #5543] Native mods: draw over and take input from existing screens (render post, mouse and key events) #1724

Open
opened 2026-11-02 15:49:12 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Sylviromi on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5543

Originally assigned to: @Sylviromi on GitHub.

🤖 Filed by Sylviromi's AI agent (Claude Code, claude-sonnet-5-5), not by Sylviromi personally.

Part of #4953 (Client: overlays and input on existing container screens). Label: feature.

What a mod cannot do. A native mod cannot draw over a screen it did not open, nor take input from one. A recipe viewer has to draw a panel over the inventory and every container screen, and receive its clicks, scroll and keys, each consumable so the screen underneath does not also act on it. Today none of that is reachable.

Why the existing hooks do not reach it. Line numbers are origin/main at a4873dec4.

  • screen_draw (native_hooks.rs:1012), screen_click (:1026), screen_tooltip (:1039) and screen (:1002) are keyed by the mod block whose menu opens; with no such block they are never called. screen_click also sees presses only and cannot consume one (call site game.rs:9118).
  • key (native_hooks.rs:876) fires on any screen but has no canceled, so the screen still sees the key. Mouse buttons reach a mod only while playing (native_mouse_event, :3034).
  • wheel (native_hooks.rs:880) is claimable but called only inside if self.screen == Screen::Playing (game.rs:15639, call at :15643).
  • panel_event (native_hooks.rs:921) is scoped to the game's own panel beside container screens (native_panel.rs:1-8); a mod cannot draw outside it.
  • Nothing tells a mod which screen is open: native_playing() (:2004) and native_screen_title() (:2073) only, no screen kind or rectangle.

Proposed hooks. Six client-only hooks, named after NeoForge's ScreenEvents and fired where the vanilla screen method runs. All take canceled: &mut bool except the first, and take &self (read-only, as screen_draw does). Payload NativeScreenView { id: &'static str, title: Option<String>, rect: [f32; 4], slots: usize }, with id from a new Game::screen_id (one per Screen arm).

hook NeoForge fires
native_screen_render_post(batch, screen) ScreenEvent.Render.Post once per frame after the screen's own drawing and tooltips, at the end of hud_layers' match screen (game.rs:7816-7854); the Win and Options early returns move into that match. Not cancellable.
native_screen_mouse_button_pressed_pre(screen, at, button, canceled) ScreenEvent.MouseButtonPressed.Pre handle_window_event WindowEvent::MouseInput (game.rs:15806), after the container hotkey and sort buttons (:15822), before match self.screen.
native_screen_mouse_button_released_pre(...) ScreenEvent.MouseButtonReleased.Pre same site on the release edge (:15874), so a drag cannot stick.
native_screen_mouse_scrolled_pre(screen, at, delta, canceled) ScreenEvent.MouseScrolled.Pre WindowEvent::MouseWheel (game.rs:15606), with the scaled deltas, before the hotbar (:15639) and every screen's scroll.
native_screen_key_pressed_pre(screen, key, repeat, canceled) ScreenEvent.KeyPressed.Pre game.rs:15372, after the window shortcuts and narrator_hotkey, before every screen arm.
native_screen_char_typed_pre(screen, c, canceled) ScreenEvent.CharacterTyped.Pre per character of KeyEvent.text at the same site while a screen is open, before the text boxes (:15984-16188). Consumes that character only.

With no mod installed each hook body is empty and nothing is skipped, so vanilla behaviour is unchanged. Cancellation only removes vanilla handling, and only for a true a mod wrote. API next; each hook ships as a fragment in tools/native-hook-fragments/ and in native-hooks.json.

Known limit: the mouse hooks do not see the prompt screens that take the mouse in their own arms above the call site (link prompt, code of conduct, pack prompt, dialog, connect, Win, Options, book, sign, title; game.rs:15696-15805). Out of scope here; the key and character hooks do reach them.

Not proposed: Render.Pre, MouseButtonPressed.Post, a tooltip-suppression hook.

Plan. Four PRs, one behaviour each, each under ~500 lines:

  1. screen_render_post + NativeScreenView + Game::screen_id.
  2. screen_mouse_button_pressed_pre + screen_mouse_button_released_pre.
  3. screen_mouse_scrolled_pre.
  4. screen_key_pressed_pre + screen_char_typed_pre.

PR 1 is independent; 2-4 build on its NativeScreenView.

Who already wants it. Recipe viewers on NeoForge hook exactly these events. No open issue or PR covers it; #4953 lists it unchecked with no linked issue.

Workaround. None. A mod can only draw and click on a screen for a block it declared itself.

Originally created by @Sylviromi on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5543 Originally assigned to: @Sylviromi on GitHub. > 🤖 Filed by Sylviromi's AI agent (Claude Code, claude-sonnet-5-5), not by Sylviromi personally. Part of #4953 (Client: overlays and input on existing container screens). Label: feature. **What a mod cannot do.** A native mod cannot draw over a screen it did not open, nor take input from one. A recipe viewer has to draw a panel over the inventory and every container screen, and receive its clicks, scroll and keys, each consumable so the screen underneath does not also act on it. Today none of that is reachable. **Why the existing hooks do not reach it.** Line numbers are `origin/main` at a4873dec4. - `screen_draw` (`native_hooks.rs:1012`), `screen_click` (`:1026`), `screen_tooltip` (`:1039`) and `screen` (`:1002`) are keyed by the mod block whose menu opens; with no such block they are never called. `screen_click` also sees presses only and cannot consume one (call site `game.rs:9118`). - `key` (`native_hooks.rs:876`) fires on any screen but has no `canceled`, so the screen still sees the key. Mouse buttons reach a mod only while playing (`native_mouse_event`, `:3034`). - `wheel` (`native_hooks.rs:880`) is claimable but called only inside `if self.screen == Screen::Playing` (`game.rs:15639`, call at `:15643`). - `panel_event` (`native_hooks.rs:921`) is scoped to the game's own panel beside container screens (`native_panel.rs:1-8`); a mod cannot draw outside it. - Nothing tells a mod which screen is open: `native_playing()` (`:2004`) and `native_screen_title()` (`:2073`) only, no screen kind or rectangle. **Proposed hooks.** Six client-only hooks, named after NeoForge's `ScreenEvent`s and fired where the vanilla screen method runs. All take `canceled: &mut bool` except the first, and take `&self` (read-only, as `screen_draw` does). Payload `NativeScreenView { id: &'static str, title: Option<String>, rect: [f32; 4], slots: usize }`, with `id` from a new `Game::screen_id` (one per `Screen` arm). | hook | NeoForge | fires | |---|---|---| | `native_screen_render_post(batch, screen)` | `ScreenEvent.Render.Post` | once per frame after the screen's own drawing and tooltips, at the end of `hud_layers`' `match screen` (`game.rs:7816-7854`); the Win and Options early returns move into that match. Not cancellable. | | `native_screen_mouse_button_pressed_pre(screen, at, button, canceled)` | `ScreenEvent.MouseButtonPressed.Pre` | `handle_window_event` `WindowEvent::MouseInput` (`game.rs:15806`), after the container hotkey and sort buttons (`:15822`), before `match self.screen`. | | `native_screen_mouse_button_released_pre(...)` | `ScreenEvent.MouseButtonReleased.Pre` | same site on the release edge (`:15874`), so a drag cannot stick. | | `native_screen_mouse_scrolled_pre(screen, at, delta, canceled)` | `ScreenEvent.MouseScrolled.Pre` | `WindowEvent::MouseWheel` (`game.rs:15606`), with the scaled deltas, before the hotbar (`:15639`) and every screen's scroll. | | `native_screen_key_pressed_pre(screen, key, repeat, canceled)` | `ScreenEvent.KeyPressed.Pre` | `game.rs:15372`, after the window shortcuts and `narrator_hotkey`, before every screen arm. | | `native_screen_char_typed_pre(screen, c, canceled)` | `ScreenEvent.CharacterTyped.Pre` | per character of `KeyEvent.text` at the same site while a screen is open, before the text boxes (`:15984-16188`). Consumes that character only. | With no mod installed each hook body is empty and nothing is skipped, so vanilla behaviour is unchanged. Cancellation only removes vanilla handling, and only for a `true` a mod wrote. API next; each hook ships as a fragment in `tools/native-hook-fragments/` and in `native-hooks.json`. Known limit: the mouse hooks do not see the prompt screens that take the mouse in their own arms above the call site (link prompt, code of conduct, pack prompt, dialog, connect, Win, Options, book, sign, title; `game.rs:15696-15805`). Out of scope here; the key and character hooks do reach them. Not proposed: `Render.Pre`, `MouseButtonPressed.Post`, a tooltip-suppression hook. **Plan.** Four PRs, one behaviour each, each under ~500 lines: 1. `screen_render_post` + `NativeScreenView` + `Game::screen_id`. 2. `screen_mouse_button_pressed_pre` + `screen_mouse_button_released_pre`. 3. `screen_mouse_scrolled_pre`. 4. `screen_key_pressed_pre` + `screen_char_typed_pre`. PR 1 is independent; 2-4 build on its `NativeScreenView`. **Who already wants it.** Recipe viewers on NeoForge hook exactly these events. No open issue or PR covers it; #4953 lists it unchecked with no linked issue. **Workaround.** None. A mod can only draw and click on a screen for a block it declared itself.
Author
Owner

@Sylviromi commented on GitHub (Oct 31, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6549997582 --> @Sylviromi commented on GitHub (Oct 31, 2026): 🤖 Agent: /claim
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#1724
No description provided.