[PR #5713] [MERGED] feat(mods): mod menu types with their own slot count and data slots #6455

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

📋 Pull Request Information

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

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


📝 Commits (1)

  • 9a47759 feat(mods): mod menu types with their own slot count and data slots

📊 Changes

14 files changed (+484 additions, -25 deletions)

View changed files

📝 crates/horizon-client-render/src/containers.rs (+62 -0)
📝 crates/horizon-client/src/content_identity.rs (+31 -3)
📝 crates/horizon-client/src/game/lan_actions.rs (+6 -0)
📝 crates/horizon-client/src/game/mods.rs (+21 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+10 -5)
📝 crates/horizon-client/src/game/remote.rs (+27 -0)
📝 crates/horizon-client/src/lan/containers.rs (+24 -5)
📝 crates/horizon-client/src/lan/menu.rs (+119 -4)
📝 crates/horizon-client/src/mod_content.rs (+18 -3)
📝 crates/horizon-client/src/mod_content_tests.rs (+37 -0)
📝 crates/horizon-mods/src/content.rs (+102 -4)
📝 docs/api/stability.md (+1 -1)
📝 docs/mods.md (+21 -0)
➕ tools/native-hook-fragments/mod_menu_types.json (+5 -0)

📄 Description

What and why

Part of #5524

A mod block's menu had to be one of vanilla's menu types, so its slot count was vanilla's (3, 5, 9, 18 ... 54)
A content mod now declares its own menu type (vanilla's MenuType) in data/<id>/horizon/menu/<name>.json:

{ "slots": 9, "data_slots": 2, "results": [7, 8] }

slots is the container's slot count, 1 to 256
data_slots is its ContainerData count, 0 to 256 (0 by default)
results are slots players take from but never put into, as a furnace's result slot
Unknown keys, slots out of range and a result outside the slots or listed twice are refused at load
Per-slot rules can join later as a new optional key, without changing these three

The type <id>:<name> gets a minecraft:menu network id after vanilla's 25, in id order, in registries.json
The content identity now covers minecraft:menu, so two Horizons with different mod menu types refuse to join
A mod container's menu (native_block_entity_container) may name such a type when its slot count is the same
The block then opens it as it opens a vanilla menu, on the server thread, a LAN host and a dedicated server
The menu is its slots, then the player's 36
The data slots are the block entity's data, padded or cut to the declared count, all sent on open, then each change
A Horizon client builds the container from the type and shows it through the mod's native_screen
Without a mod screen it closes the window again
A client whose brand isn't horizon is never sent a mod menu type, so the block opens nothing for it
It still gets a locked container's message and sound first
A vanilla client reads the type with ByteBufCodecs.registry(Registries.MENU), and an unknown id disconnects it

A result slot refuses a click, a drag and a swap, and a shift-click never aims at it
A click with the same item takes what it holds onto the cursor, as doClick does for a slot that refuses the item
That take now applies to any guest menu slot that refuses the carried item (an armour or shulker box slot too), as vanilla's does
Shift-click is otherwise a chest's: the container to the inventory from the end, the inventory to the first slots with room

A data slot of -32768 now goes out on open too, as i16::MIN no longer stands for a slot not sent yet

The API fragment has no hooks: it numbers the wider menu contract, so a bundle can ask for it

Tests: the declaration and its refusals, the registry id in a full content root, the identity with a mod menu type, a unit test of menu_reaches (the brand check), and a result slot's clicks, swaps, drags and collects
Checked in real games with a small test mod (a 9-slot menu type with 2 data slots and results 7 and 8, and a test build answering the container, tick and screen hooks):
Server thread (default): the block opens the mod type, and horizon-ctl screen lists its 9 slots (300 to 308)
The client gets data[1] = 200 and data[0] climbing 0 to 199 and over again (printed by the test build)
In-frame (--in-frame): the block opens its container, but the window shows none of its slots
I think main does the same for every mod container there, as only a client of a server attaches mod screens (open_native_screen)
The runs were headless, so they made no clicks
--offscreen crashes on main at the first world frame (a separate issue)
LAN and dedicated servers share the server thread's code
They are untested

Left as is: per-slot accept rules beyond results (one item or a tag)
Left as is: hooks for shift-click routing (quickMoveStack) and stillValid
Left as is: opening with extra data (IContainerFactory, openMenu with a buffer)
Left as is: the client doesn't predict clicks in a mod menu type (the server's answer shows them)
Left as is: the in-frame path shows no mod screen
Left as is: a menu not opened from a block (an item's)

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/MenuType.java:11-57 (the type: a constructor, registered in BuiltInRegistries.MENU)
core/registries/BuiltInRegistries.java:210 (MENU is a static registry, not in RegistryDataLoader.SYNCHRONIZED_REGISTRIES)
network/protocol/game/ClientboundOpenScreenPacket.java:14-21 and core/IdMap.java:13-19 (an unknown id throws)
server/level/ServerPlayer.java:1415-1437 (openMenu: no menu, nothing opens)
server/level/ServerPlayer.java:320-327 (sendInitialData: the content, then every data slot)
world/inventory/AbstractContainerMenu.java:137-147 (addDataSlot, addDataSlots), :200-218 (broadcastChanges)
world/inventory/AbstractContainerMenu.java:444-469 (doClick PICKUP on a slot that refuses the carried item)
world/inventory/FurnaceResultSlot.java:19 (mayPlace false), world/inventory/AbstractFurnaceMenu.java:89-134
world/inventory/ChestMenu.java:75-97 (quickMoveStack)
client/gui/screens/MenuScreens.java:40-47 (no screen for the type, no window)

Other projects' code

none

Self-check

The one failure is a_replaced_binary_is_replaced_again_at_its_path (launcher/src/backend.rs)
It fails on main too with prepared data

Check Result
Scope ✅ 14 files, +484 −25
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed (1 min 0 s)
rustfmt ✅ (9 s)
clippy ✅ (2 min 11 s)
tests: horizon-client, horizon-client-render, horizon-mods ✅ 2516 passed (5 min 55 s)
doc tests ✅ 0 passed (2 s)
content root tests ✅ 21 passed (1 min 21 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (1 min 7 s)
launcher tests ❌ 359 passed, 1 failed (2 min 15 s)
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)

🔄 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/5713 **Author:** [@reservedbytes](https://github.com/reservedbytes) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `feat/mod-menu-types` --- ### 📝 Commits (1) - [`9a47759`](https://github.com/horizon-rust/horizon/commit/9a47759df3a604b881e58865af4d69db922bd1d9) feat(mods): mod menu types with their own slot count and data slots ### 📊 Changes **14 files changed** (+484 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/containers.rs` (+62 -0) 📝 `crates/horizon-client/src/content_identity.rs` (+31 -3) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+6 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+21 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+10 -5) 📝 `crates/horizon-client/src/game/remote.rs` (+27 -0) 📝 `crates/horizon-client/src/lan/containers.rs` (+24 -5) 📝 `crates/horizon-client/src/lan/menu.rs` (+119 -4) 📝 `crates/horizon-client/src/mod_content.rs` (+18 -3) 📝 `crates/horizon-client/src/mod_content_tests.rs` (+37 -0) 📝 `crates/horizon-mods/src/content.rs` (+102 -4) 📝 `docs/api/stability.md` (+1 -1) 📝 `docs/mods.md` (+21 -0) ➕ `tools/native-hook-fragments/mod_menu_types.json` (+5 -0) </details> ### 📄 Description ## What and why Part of #5524 A mod block's menu had to be one of vanilla's menu types, so its slot count was vanilla's (3, 5, 9, 18 ... 54) A content mod now declares its own menu type (vanilla's `MenuType`) in `data/<id>/horizon/menu/<name>.json`: ```json { "slots": 9, "data_slots": 2, "results": [7, 8] } ``` `slots` is the container's slot count, 1 to 256 `data_slots` is its `ContainerData` count, 0 to 256 (0 by default) `results` are slots players take from but never put into, as a furnace's result slot Unknown keys, slots out of range and a result outside the slots or listed twice are refused at load Per-slot rules can join later as a new optional key, without changing these three The type `<id>:<name>` gets a `minecraft:menu` network id after vanilla's 25, in id order, in `registries.json` The content identity now covers `minecraft:menu`, so two Horizons with different mod menu types refuse to join A mod container's `menu` (`native_block_entity_container`) may name such a type when its slot count is the same The block then opens it as it opens a vanilla menu, on the server thread, a LAN host and a dedicated server The menu is its slots, then the player's 36 The data slots are the block entity's `data`, padded or cut to the declared count, all sent on open, then each change A Horizon client builds the container from the type and shows it through the mod's `native_screen` Without a mod screen it closes the window again A client whose brand isn't `horizon` is never sent a mod menu type, so the block opens nothing for it It still gets a locked container's message and sound first A vanilla client reads the type with `ByteBufCodecs.registry(Registries.MENU)`, and an unknown id disconnects it A result slot refuses a click, a drag and a swap, and a shift-click never aims at it A click with the same item takes what it holds onto the cursor, as `doClick` does for a slot that refuses the item That take now applies to any guest menu slot that refuses the carried item (an armour or shulker box slot too), as vanilla's does Shift-click is otherwise a chest's: the container to the inventory from the end, the inventory to the first slots with room A data slot of -32768 now goes out on open too, as `i16::MIN` no longer stands for a slot not sent yet The API fragment has no hooks: it numbers the wider `menu` contract, so a bundle can ask for it Tests: the declaration and its refusals, the registry id in a full content root, the identity with a mod menu type, a unit test of `menu_reaches` (the brand check), and a result slot's clicks, swaps, drags and collects Checked in real games with a small test mod (a 9-slot menu type with 2 data slots and results 7 and 8, and a test build answering the container, tick and screen hooks): Server thread (default): the block opens the mod type, and `horizon-ctl screen` lists its 9 slots (300 to 308) The client gets `data[1] = 200` and `data[0]` climbing 0 to 199 and over again (printed by the test build) In-frame (`--in-frame`): the block opens its container, but the window shows none of its slots I think `main` does the same for every mod container there, as only a client of a server attaches mod screens (`open_native_screen`) The runs were headless, so they made no clicks `--offscreen` crashes on `main` at the first world frame (a separate issue) LAN and dedicated servers share the server thread's code They are untested Left as is: per-slot accept rules beyond `results` (one item or a tag) Left as is: hooks for shift-click routing (`quickMoveStack`) and `stillValid` Left as is: opening with extra data (`IContainerFactory`, `openMenu` with a buffer) Left as is: the client doesn't predict clicks in a mod menu type (the server's answer shows them) Left as is: the in-frame path shows no mod screen Left as is: a menu not opened from a block (an item's) ## 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/MenuType.java:11-57` (the type: a constructor, registered in `BuiltInRegistries.MENU`) `core/registries/BuiltInRegistries.java:210` (`MENU` is a static registry, not in `RegistryDataLoader.SYNCHRONIZED_REGISTRIES`) `network/protocol/game/ClientboundOpenScreenPacket.java:14-21` and `core/IdMap.java:13-19` (an unknown id throws) `server/level/ServerPlayer.java:1415-1437` (`openMenu`: no menu, nothing opens) `server/level/ServerPlayer.java:320-327` (`sendInitialData`: the content, then every data slot) `world/inventory/AbstractContainerMenu.java:137-147` (`addDataSlot`, `addDataSlots`), `:200-218` (`broadcastChanges`) `world/inventory/AbstractContainerMenu.java:444-469` (`doClick` PICKUP on a slot that refuses the carried item) `world/inventory/FurnaceResultSlot.java:19` (`mayPlace` false), `world/inventory/AbstractFurnaceMenu.java:89-134` `world/inventory/ChestMenu.java:75-97` (`quickMoveStack`) `client/gui/screens/MenuScreens.java:40-47` (no screen for the type, no window) ## Other projects' code none ## Self-check The one failure is `a_replaced_binary_is_replaced_again_at_its_path` (`launcher/src/backend.rs`) It fails on `main` too with prepared data | Check | Result | | --- | --- | | Scope | ✅ 14 files, +484 −25 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed (1 min 0 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (2 min 11 s) | | tests: horizon-client, horizon-client-render, horizon-mods | ✅ 2516 passed (5 min 55 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ✅ 21 passed (1 min 21 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (1 min 7 s) | | launcher tests | ❌ 359 passed, 1 failed (2 min 15 s) | | 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) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:20:56 +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#6455
No description provided.