[PR #5866] [MERGED] feat(mods): mod menu types on the vanilla menu engine, and a hook for their slot rules #6529

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5866
Author: @reservedbytes
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: feat/mod-menu-engine


📝 Commits (2)

  • 25e5dbb feat(mods): mod menu types on the vanilla menu engine, and a hook for their slot rules
  • 84bd812 docs(mods): a shift-click tops up a slot without asking may_place, as vanilla

📊 Changes

8 files changed (+253 additions, -130 deletions)

View changed files

📝 crates/horizon-client/src/game/lan_crafting.rs (+28 -5)
📝 crates/horizon-client/src/game/native_hooks.rs (+5 -0)
📝 crates/horizon-client/src/lan/containers.rs (+5 -13)
📝 crates/horizon-client/src/lan/menu.rs (+5 -106)
📝 crates/horizon-client/src/menu.rs (+181 -2)
📝 docs/mods.md (+5 -3)
📝 docs/native-mods.md (+16 -1)
➕ tools/native-hook-fragments/menu_slot_rules.json (+8 -0)

📄 Description

What and why

Part of #5524

A mod menu type's clicks (#5713) were answered by the guest click code in lan/menu.rs, which has its own take on each click mode
They now run on the server's vanilla menu engine (menu.rs), as a furnace's or a crafter's do
The menu is menu::Kind::Mod, with the type's slots, then the player's 36
A results slot is one whose Slot.mayPlace is false, and the others take anything
A slot the mod's screen leaves out takes no click and no shift-click
A shift-click goes as ChestMenu.quickMoveStack routes it, and tops up no result unless the hook below opens it
The menu writes back only the type's slots, and the block entity's slots past them stay as they were
The results code in lan/menu.rs goes, as nothing reaches it now

A native mod can decide what a slot takes in code with a new free hook in menu.rs:

pub fn native_menu_slot_rules(menu: &str, slot: usize, stack: &ItemStack, may_place: &mut bool, max_stack: &mut u32)

It gets the type's own answer (false on a result, true elsewhere, and 99) and may change both, as a NeoForge mod's own Slot overrides mayPlace and getMaxStackSize
NeoForge has no event for it, so it keeps a Horizon name
max_stack is kept to 1 to 99, and the item's own stack size still caps it
It runs on the server, for each click, drag and shift-click that puts an item in a mod menu type's slot
Its fragment is tools/native-hook-fragments/menu_slot_rules.json, and the catalog test reads menu.rs's free hooks beside the renderer's and the loot tables'

The empty hook costs nothing on vanilla's menus or on a mod's
It is #[inline(always)] with an empty body, and only a mod menu type's slots reach it, so a vanilla menu's mayPlace gains only one match arm
In a --profile fast build, nm finds no native_menu_slot_rules in the horizon-client rlib
For comparison, the #[inline(never)] native_loot_table_load is in the horizon-world one

Tests: a mod menu of three slots and a result, on the engine
The result takes nothing by a click, a drag, a hotbar key or a shift-click, not even a top-up of its own item
The carried ingots take the result's one, and a hotbar key, F and a double click take it out
A hidden slot takes neither a click nor a shift-click
It needs no game data, and it replaces the two lan/menu.rs tests of the removed code
No real-game run: a mod container needs a native mod build

Questions for levz:
Is a free hook in horizon_client::menu fine as a target, with side: "server"?
Should it also get the block entity's position or the player (vanilla's mayPlace gets neither), and is one hook for both answers right?

Left as is: declared per-slot rules (an item, a tag, a smaller stack) come next, on this engine
Left as is: a world played in-frame (--in-frame) clicks a mod container through the window's own container code, with no hook
I think nothing shows a mod menu type there yet
Left as is: no test drives lan_machine_click itself, as it needs a whole Game
Left as is: the client still predicts no click in a mod menu type

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

world/inventory/Slot.java:44 (mayPlace), :77 (getMaxStackSize(ItemStack))
world/inventory/ChestMenu.java:75-97 (quickMoveStack)
world/inventory/AbstractContainerMenu.java:477-512 (SWAP: no swap into a slot that refuses the item)
world/inventory/AbstractContainerMenu.java:660-720 (moveItemStackTo: an empty slot only when mayPlace)

Other projects' code

none

Self-check

Check Result
Scope ✅ 8 files, +251 −130
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 515 passed (1 min 3 s)
rustfmt ✅ (8 s)
clippy ✅ (2 min 22 s)
tests: horizon-client ✅ 1667 passed (5 min 48 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
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)

Harnesses run with the vanilla jars: menu_click, storage_menu, crafter, simple_container, vehicle_container, container_screen, inventory_pickup, player_inventory and save_roundtrip (#5750): 9 passed, 0 failed


🔄 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/5866 **Author:** [@reservedbytes](https://github.com/reservedbytes) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-menu-engine` --- ### 📝 Commits (2) - [`25e5dbb`](https://github.com/horizon-rust/horizon/commit/25e5dbb3da8ad6b94c073efbcdb0ed9f207b6ab6) feat(mods): mod menu types on the vanilla menu engine, and a hook for their slot rules - [`84bd812`](https://github.com/horizon-rust/horizon/commit/84bd812ecd432846a9f5ce8be7739da1829c00cf) docs(mods): a shift-click tops up a slot without asking may_place, as vanilla ### 📊 Changes **8 files changed** (+253 additions, -130 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/lan_crafting.rs` (+28 -5) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+5 -0) 📝 `crates/horizon-client/src/lan/containers.rs` (+5 -13) 📝 `crates/horizon-client/src/lan/menu.rs` (+5 -106) 📝 `crates/horizon-client/src/menu.rs` (+181 -2) 📝 `docs/mods.md` (+5 -3) 📝 `docs/native-mods.md` (+16 -1) ➕ `tools/native-hook-fragments/menu_slot_rules.json` (+8 -0) </details> ### 📄 Description ## What and why Part of #5524 A mod menu type's clicks (#5713) were answered by the guest click code in `lan/menu.rs`, which has its own take on each click mode They now run on the server's vanilla menu engine (`menu.rs`), as a furnace's or a crafter's do The menu is `menu::Kind::Mod`, with the type's slots, then the player's 36 A `results` slot is one whose `Slot.mayPlace` is false, and the others take anything A slot the mod's screen leaves out takes no click and no shift-click A shift-click goes as `ChestMenu.quickMoveStack` routes it, and tops up no result unless the hook below opens it The menu writes back only the type's slots, and the block entity's slots past them stay as they were The `results` code in `lan/menu.rs` goes, as nothing reaches it now A native mod can decide what a slot takes in code with a new free hook in `menu.rs`: ```rust pub fn native_menu_slot_rules(menu: &str, slot: usize, stack: &ItemStack, may_place: &mut bool, max_stack: &mut u32) ``` It gets the type's own answer (false on a result, true elsewhere, and 99) and may change both, as a NeoForge mod's own `Slot` overrides `mayPlace` and `getMaxStackSize` NeoForge has no event for it, so it keeps a Horizon name `max_stack` is kept to 1 to 99, and the item's own stack size still caps it It runs on the server, for each click, drag and shift-click that puts an item in a mod menu type's slot Its fragment is `tools/native-hook-fragments/menu_slot_rules.json`, and the catalog test reads `menu.rs`'s free hooks beside the renderer's and the loot tables' The empty hook costs nothing on vanilla's menus or on a mod's It is `#[inline(always)]` with an empty body, and only a mod menu type's slots reach it, so a vanilla menu's `mayPlace` gains only one match arm In a `--profile fast` build, `nm` finds no `native_menu_slot_rules` in the `horizon-client` rlib For comparison, the `#[inline(never)]` `native_loot_table_load` is in the `horizon-world` one Tests: a mod menu of three slots and a result, on the engine The result takes nothing by a click, a drag, a hotbar key or a shift-click, not even a top-up of its own item The carried ingots take the result's one, and a hotbar key, F and a double click take it out A hidden slot takes neither a click nor a shift-click It needs no game data, and it replaces the two `lan/menu.rs` tests of the removed code No real-game run: a mod container needs a native mod build Questions for levz: Is a free hook in `horizon_client::menu` fine as a target, with `side: "server"`? Should it also get the block entity's position or the player (vanilla's `mayPlace` gets neither), and is one hook for both answers right? Left as is: declared per-slot rules (an item, a tag, a smaller stack) come next, on this engine Left as is: a world played in-frame (`--in-frame`) clicks a mod container through the window's own container code, with no hook I think nothing shows a mod menu type there yet Left as is: no test drives `lan_machine_click` itself, as it needs a whole `Game` Left as is: the client still predicts no click in a mod menu type ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [x] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `world/inventory/Slot.java:44` (`mayPlace`), `:77` (`getMaxStackSize(ItemStack)`) `world/inventory/ChestMenu.java:75-97` (`quickMoveStack`) `world/inventory/AbstractContainerMenu.java:477-512` (SWAP: no swap into a slot that refuses the item) `world/inventory/AbstractContainerMenu.java:660-720` (`moveItemStackTo`: an empty slot only when `mayPlace`) ## Other projects' code none ## Self-check | Check | Result | | --- | --- | | Scope | ✅ 8 files, +251 −130 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 515 passed (1 min 3 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (2 min 22 s) | | tests: horizon-client | ✅ 1667 passed (5 min 48 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | 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) | Harnesses run with the vanilla jars: `menu_click`, `storage_menu`, `crafter`, `simple_container`, `vehicle_container`, `container_screen`, `inventory_pickup`, `player_inventory` and `save_roundtrip` (#5750): 9 passed, 0 failed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:22:28 +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#6529
No description provided.