[PR #6884] [MERGED] Native mods: a mod container routes shift-clicks (native_menu_quick_move) #7171

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

📋 Pull Request Information

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

Base: main ← Head: native/menu-quick-move


📝 Commits (3)

  • c200620 Native mods: a mod container routes shift-clicks (native_menu_quick_move)
  • d2c99b0 Quick-move hook: review fixes
  • dd98a7b Merge branch 'main' into native/menu-quick-move

📊 Changes

8 files changed (+508 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+2 -0)
📝 crates/horizon-client/src/game/lan_crafting.rs (+1 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+45 -1)
➕ crates/horizon-client/src/game/native_quick_move.rs (+353 -0)
📝 crates/horizon-client/src/mod_api/generated.rs (+66 -0)
📝 docs/native-mods.md (+23 -0)
➕ tools/native-hook-fragments/menu_quick_move.json (+17 -0)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally.

What and why

Fixes #6562, part of #4953 (Registration and data: "Shift-click in a mod container's menu"). Does not close #4953.

native_menu_quick_move(pos, entity, container_slots, slot, stack, handled) is a mod container's AbstractContainerMenu.quickMoveStack, the method a Java menu overrides to decide where a shift-clicked stack goes. It runs on the server before the game's own routing, for a mod block entity's menu on a vanilla menu type (minecraft:generic_9x1...) or on the mod's own menu type.

  • slot is the menu's index (below container_slots the block's own slot, then the 27 main inventory slots, then the hotbar); stack a copy of what it holds.
  • The mod takes what it moves out of stack (into entity.items, or another block via native_insert_item) and sets handled (Flow::Cancel in the trait API): the clicked slot holds what is left, the game's routing is skipped, and the client gets the whole menu again (sendAllDataToRemote). A removed block closes the menu and resends the inventory.
  • Unhandled: entity.items goes back to what it held (so nothing moved without taking the click can be duplicated) and the game routes the stack as before.
  • Not asked: an empty slot, a slot the mod's screen hides, another click type or button, a spectator or dead player, an invalid menu, a shift-click during a drag (it only ends the drag, as vanilla's doClick). The player is swapped in (native_acting_player); entity is out of the world during the call, as in native_menu_button.

This is what the issue's storage terminal needs: its screen hides the container slots, so the game's routing had nowhere to put a shift-clicked stack and nothing happened. A machine can also send fuel to its fuel slot and ores to its input.

Code: game/native_quick_move.rs (new: the server glue and the write-back), one new first ContainerClick arm in game/lan_actions.rs, the hook point in native_hooks.rs, fragment tools/native-hook-fragments/menu_quick_move.json (cancel contract, out handled; no API number taken), regenerated mod_api/generated.rs, docs in docs/native-mods.md.

Kind

  • feature: something new for players

Vanilla reference

AbstractContainerMenu.doClick (QUICK_MOVE: mayPickup, the quickMoveStack loop, resetQuickCraft for a click during a drag) and ServerGamePacketListenerImpl.handleContainerClick (spectator / dead / stillValid refusals, sendAllDataToRemote), pinned 26.3 sources. NeoForge has no event for this (a menu overrides the method), so the catalog entry says none. Vanilla calls quickMoveStack again while the same item keeps moving; this hook is asked once per click (documented).

Other projects' code

None.

Tests

  • Unit (5, game::native_quick_move::tests): menu slot → container/inventory mapping, independent of the code (vanilla ChestMenu layout); non-quick-move clicks, buttons, hidden slots; write-back: remainder in the clicked slot, all taken empties it, a taken container slot gets the remainder over the mod's write, an untaken click restores the block's items.
  • Real game, server thread (single player) and dedicated server (horizon-client --dedicated, a client joined with connect), each driven by horizon-ctl in a nested headless KWin, with a throwaway trait mod in main.rs (not committed): a code-declared qmtest:box (barrel template, native_block_entity, 9 slots, generic_9x1) whose hook takes half of a shift-clicked cobblestone stack from the inventory into its slot 8, and for dirt writes a copy into slot 7 without taking the click. Both runs PASS:
    • shift-click 64 cobblestone in the hotbar → box slot 8 = 32, hotbar keeps 32, game routing did not also run (slot 0 empty);
    • shift-click 10 dirt → hook heard, not taken → the game routes it to box slot 0, and the mod's slot-7 copy is gone (no duplication);
    • shift-click the box's slot 8 → hook heard, not taken → back to the inventory the game's way (64 cobblestone total, nothing lost or made);
    • closing and reopening shows the same contents from the server.
    • The hook's log line shows slot=36/37 for hotbar 0/1 and slot=8 for the container, container_slots=9, the right pos.
  • Not run in game: a content mod's own menu type (data/<id>/horizon/menu/, the Kind::Mod engine path; same entry point, and the cached engine menu is dropped after a taken click) and a screen hiding the container's slots (covered by the unit test of the gate). Vanilla parity harnesses: not run locally (--quick); CI's parity job picks them.
  • Independent review (Claude Opus subagent) found no definite bug; its contract risks (unhandled edits to entity.items, clicked-slot overwrite, removed block resync, drag, dead player, docs) are fixed in the second commit.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at b2e71aca0, 1 min 54 s)

Check Result
Scope ✅ 8 files, +508 −2
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 609 passed (30 s)
rustfmt ✅ (6 s)
clippy ✅ (50 s)
tests: horizon-client, horizon-client-lib ✅ 1990 passed (15 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
mod API up to date ✅ (11 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/6884 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `native/menu-quick-move` --- ### 📝 Commits (3) - [`c200620`](https://github.com/horizon-rust/horizon/commit/c200620069a8d68366f69dc3ec17f63e71a0534d) Native mods: a mod container routes shift-clicks (native_menu_quick_move) - [`d2c99b0`](https://github.com/horizon-rust/horizon/commit/d2c99b0ae32967fea80c4af37c4aab6d2bbd31ef) Quick-move hook: review fixes - [`dd98a7b`](https://github.com/horizon-rust/horizon/commit/dd98a7bfa05630f8dc4d89fbf52dcc485ffa51c1) Merge branch 'main' into native/menu-quick-move ### 📊 Changes **8 files changed** (+508 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+2 -0) 📝 `crates/horizon-client/src/game/lan_crafting.rs` (+1 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+45 -1) ➕ `crates/horizon-client/src/game/native_quick_move.rs` (+353 -0) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+66 -0) 📝 `docs/native-mods.md` (+23 -0) ➕ `tools/native-hook-fragments/menu_quick_move.json` (+17 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. ## What and why Fixes #6562, part of #4953 (Registration and data: "Shift-click in a mod container's menu"). Does not close #4953. `native_menu_quick_move(pos, entity, container_slots, slot, stack, handled)` is a mod container's `AbstractContainerMenu.quickMoveStack`, the method a Java menu overrides to decide where a shift-clicked stack goes. It runs on the server before the game's own routing, for a mod block entity's menu on a vanilla menu type (`minecraft:generic_9x1`...) or on the mod's own menu type. - `slot` is the menu's index (below `container_slots` the block's own slot, then the 27 main inventory slots, then the hotbar); `stack` a copy of what it holds. - The mod takes what it moves out of `stack` (into `entity.items`, or another block via `native_insert_item`) and sets `handled` (`Flow::Cancel` in the trait API): the clicked slot holds what is left, the game's routing is skipped, and the client gets the whole menu again (`sendAllDataToRemote`). A removed block closes the menu and resends the inventory. - Unhandled: `entity.items` goes back to what it held (so nothing moved without taking the click can be duplicated) and the game routes the stack as before. - Not asked: an empty slot, a slot the mod's screen hides, another click type or button, a spectator or dead player, an invalid menu, a shift-click during a drag (it only ends the drag, as vanilla's `doClick`). The player is swapped in (`native_acting_player`); `entity` is out of the world during the call, as in `native_menu_button`. This is what the issue's storage terminal needs: its screen hides the container slots, so the game's routing had nowhere to put a shift-clicked stack and nothing happened. A machine can also send fuel to its fuel slot and ores to its input. Code: `game/native_quick_move.rs` (new: the server glue and the write-back), one new first `ContainerClick` arm in `game/lan_actions.rs`, the hook point in `native_hooks.rs`, fragment `tools/native-hook-fragments/menu_quick_move.json` (`cancel` contract, out `handled`; no API number taken), regenerated `mod_api/generated.rs`, docs in `docs/native-mods.md`. ## Kind - [x] feature: something new for players ## Vanilla reference `AbstractContainerMenu.doClick` (QUICK_MOVE: `mayPickup`, the `quickMoveStack` loop, `resetQuickCraft` for a click during a drag) and `ServerGamePacketListenerImpl.handleContainerClick` (spectator / dead / `stillValid` refusals, `sendAllDataToRemote`), pinned 26.3 sources. NeoForge has no event for this (a menu overrides the method), so the catalog entry says `none`. Vanilla calls `quickMoveStack` again while the same item keeps moving; this hook is asked once per click (documented). ## Other projects' code None. ## Tests - Unit (5, `game::native_quick_move::tests`): menu slot → container/inventory mapping, independent of the code (vanilla `ChestMenu` layout); non-quick-move clicks, buttons, hidden slots; write-back: remainder in the clicked slot, all taken empties it, a taken container slot gets the remainder over the mod's write, an untaken click restores the block's items. - Real game, server thread (single player) and dedicated server (`horizon-client --dedicated`, a client joined with `connect`), each driven by horizon-ctl in a nested headless KWin, with a throwaway trait mod in `main.rs` (not committed): a code-declared `qmtest:box` (barrel template, `native_block_entity`, 9 slots, `generic_9x1`) whose hook takes half of a shift-clicked cobblestone stack from the inventory into its slot 8, and for dirt writes a copy into slot 7 **without** taking the click. Both runs PASS: - shift-click 64 cobblestone in the hotbar → box slot 8 = 32, hotbar keeps 32, game routing did not also run (slot 0 empty); - shift-click 10 dirt → hook heard, not taken → the game routes it to box slot 0, and the mod's slot-7 copy is gone (no duplication); - shift-click the box's slot 8 → hook heard, not taken → back to the inventory the game's way (64 cobblestone total, nothing lost or made); - closing and reopening shows the same contents from the server. - The hook's log line shows `slot=36`/`37` for hotbar 0/1 and `slot=8` for the container, `container_slots=9`, the right `pos`. - Not run in game: a content mod's own menu **type** (`data/<id>/horizon/menu/`, the `Kind::Mod` engine path; same entry point, and the cached engine menu is dropped after a taken click) and a screen hiding the container's slots (covered by the unit test of the gate). Vanilla parity harnesses: not run locally (`--quick`); CI's parity job picks them. - Independent review (Claude Opus subagent) found no definite bug; its contract risks (unhandled edits to `entity.items`, clicked-slot overwrite, removed block resync, drag, dead player, docs) are fixed in the second commit. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at b2e71aca0, 1 min 54 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +508 −2 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 609 passed (30 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (50 s) | | tests: horizon-client, horizon-client-lib | ✅ 1990 passed (15 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (11 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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 06:35:13 +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#7171
No description provided.