[PR #4534] [MERGED] Native mods: server menus and an atomic item exchange (API 10) #5681

Closed
opened 2026-11-03 05:14:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: feat/smp-server-menus


📝 Commits (5)

  • 076c41f Native mods: server commands and players (API 8)
  • 768d20d Native mods: a server player's game mode
  • b070f41 Native mods: the acting player's plain items for server mods (API 9)
  • 396f456 Native mods: the items test follows getFreeSlot's empty off hand
  • e23b4b7 Native mods: server menus and an atomic item exchange (API 10)

📊 Changes

13 files changed (+1378 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+2 -0)
📝 crates/horizon-client/src/game/lan.rs (+13 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+21 -2)
📝 crates/horizon-client/src/game/native_hooks.rs (+56 -2)
➕ crates/horizon-client/src/game/native_menus.rs (+365 -0)
➕ crates/horizon-client/src/game/native_server.rs (+697 -0)
📝 crates/horizon-client/src/lan/commands.rs (+5 -0)
📝 crates/horizon-client/src/lan/containers.rs (+83 -2)
📝 crates/horizon-client/src/lan/guest.rs (+3 -0)
📝 crates/horizon-client/src/lan/hub.rs (+19 -0)
📝 crates/horizon-client/src/lan/menu.rs (+33 -1)
📝 docs/native-mods.md (+61 -0)
📝 native-hooks.json (+20 -0)

📄 Description

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

Stacked on #4519 (API 9) and #4514 (API 8): review only the last commit.

What and why

Server menus for native mods (API 10): what a safe player-to-player trade needs, without any client mod. It is used by the official server's /trade (docs/smp.md, #4494; the mod is horizon-rust/horizon-mods#57). It is general: shops, kits and voting menus can be built on it too.

  • A vanilla chest menu, display only. native_open_menu(uuid, rows, title, items) opens a generic_9x1..9x6 menu filled with ordinary items, so a stock client shows it. native_set_menu_items and native_close_menu change and close it.
  • No click moves anything. The hub's container click sees Slots::Native and queues a NativeMenuEvent::Click. It then sends the menu, the inventory and the cursor back as they were, the same path as a click the server refuses. That covers every click mode: shift, number keys, drags, double click.
  • The clicks and the closing reach the mod. native_menu_clicked(uuid, window, slot, button, mode) and native_menu_closed(uuid, window) cover the player closing it, another menu opening, or the player leaving (remove_guest). They run from tick_lan once the hub is back in self.lan, with no player's state swapped in.
  • native_menu_inventory_slot(size, slot) maps a click below the menu to the player's inventory slot. native_player_stacks(uuid) returns the player's 36 slots.
  • native_exchange_items(a, a_offer, b, b_offer) swaps two players' offers in one step, or nothing. Each offer is a list of inventory slots, each with the exact stack it must still hold. The swap is refused, with nothing moved, if an offer changed, a stack doesn't fit whole on the other side, a player is gone or dead, or a player's state is swapped in. A trade built on this keeps the offered stacks in their owners' inventories until that step, so no way out (close, leave, die) has anything to return or to duplicate.
  • NATIVE_HOOKS_API 9 → 10, native-hooks.json, docs/native-mods.md ("Server menus").

With no mod opening one nothing changes: no Slots::Native menu exists, the event list stays empty (one is_empty per tick), and the new match arms are never taken.

Kind

  • extra: Horizon-only, off by default

Vanilla reference

ChestMenu (MenuType.GENERIC_9x1..9x6): the slot layout (menu, then 27 inventory slots, then the hotbar) as ChestMenu's constructor adds them. A refused click is answered as AbstractContainerMenu.broadcastFullState after a failed click.

Proof

native/tools/native.py proof smp on this head (e23b4b7), in horizon-mods' feat/smp-trade (horizon-rust/horizon-mods#57): a dedicated server built with the SMP mod, two real clients (horizon-ctl --offscreen, fresh folders) clicking the server's trade menu as a player does (click-slot), every item counted from each player's own client:

  • closing the menu: Alex offered 10 diamonds; Steve's menu showed them; Alex still held them; Alex closed it. Steve's menu closed and he saw "Trade cancelled: Alex closed the trade. Nothing was exchanged."; nothing moved.
  • a full inventory: both confirmed while Steve had no room. "The trade didn't go through: the second player has no room.", nothing moved, and both confirmations were cleared.
  • the cancel button: the trade ended and nothing moved.
  • a change clears the other's confirmation: Steve's /trade money 35 after Alex confirmed turned Alex's button back to "Confirm".
  • through: Alex's 10 diamonds for Steve's 5 emeralds and 35 coins. The clients counted (Alex 0 diamonds, 5 emeralds; Steve 10 diamonds, 0 emeralds), and the balances were 415 / 400.
  • dying (keep_inventory on, so a duplicate would show): "Trade cancelled: Alex is gone.", and the counts were unchanged after he respawned.
  • leaving: Steve quit mid-trade with his diamonds offered. Alex's menu closed and nothing moved; Steve came back with his 10 diamonds.
  • the files: economy.json held 415 / 400 after a restart, and audit.log ended trade, trade_failed, trade, trade_money.

Unit tests: the slot mapping; an exchange that swaps both sides (merged onto stacks, then into empty slots, with totals kept); an exchange that can't complete moving nothing (a changed offer, an empty or out-of-range slot, no room, the same slot offered twice).

Self-check

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at f6a757ac2, 8 min 16 s)

Check Result
Scope ⚠️ 13 files, +1378 −7; 1324 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 2 s)
rustfmt ✅ (8 s)
clippy ✅ (2 min 11 s)
tests: horizon-client ✅ 1072 passed (4 min 25 s)
doc tests ✅ 0 passed (2 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 ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The scope counts #4514 and #4519 too (stacked); this PR's own commit is the last.

🤖 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/4534 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/smp-server-menus` --- ### 📝 Commits (5) - [`076c41f`](https://github.com/horizon-rust/horizon/commit/076c41fc27336c8ba886471bf3a1ced1b76c9b3d) Native mods: server commands and players (API 8) - [`768d20d`](https://github.com/horizon-rust/horizon/commit/768d20d9980c2e04cc76951d18ec6c72ccef0176) Native mods: a server player's game mode - [`b070f41`](https://github.com/horizon-rust/horizon/commit/b070f41ddae470df36694dff7f176bdda2a3ad90) Native mods: the acting player's plain items for server mods (API 9) - [`396f456`](https://github.com/horizon-rust/horizon/commit/396f456556dd423454fc93cca65463716e1e1976) Native mods: the items test follows getFreeSlot's empty off hand - [`e23b4b7`](https://github.com/horizon-rust/horizon/commit/e23b4b7d8ff3318da3f96f9e0f11ba961ffefe99) Native mods: server menus and an atomic item exchange (API 10) ### 📊 Changes **13 files changed** (+1378 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+2 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+13 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+21 -2) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+56 -2) ➕ `crates/horizon-client/src/game/native_menus.rs` (+365 -0) ➕ `crates/horizon-client/src/game/native_server.rs` (+697 -0) 📝 `crates/horizon-client/src/lan/commands.rs` (+5 -0) 📝 `crates/horizon-client/src/lan/containers.rs` (+83 -2) 📝 `crates/horizon-client/src/lan/guest.rs` (+3 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+19 -0) 📝 `crates/horizon-client/src/lan/menu.rs` (+33 -1) 📝 `docs/native-mods.md` (+61 -0) 📝 `native-hooks.json` (+20 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Stacked on #4519 (API 9) and #4514 (API 8): review only the last commit.** ## What and why Server menus for native mods (API 10): what a safe player-to-player trade needs, without any client mod. It is used by the official server's `/trade` ([docs/smp.md](https://github.com/horizon-rust/horizon/blob/feat/smp-design/docs/smp.md), #4494; the mod is horizon-rust/horizon-mods#57). It is general: shops, kits and voting menus can be built on it too. - **A vanilla chest menu, display only.** `native_open_menu(uuid, rows, title, items)` opens a `generic_9x1`..`9x6` menu filled with ordinary items, so a stock client shows it. `native_set_menu_items` and `native_close_menu` change and close it. - **No click moves anything.** The hub's container click sees `Slots::Native` and queues a `NativeMenuEvent::Click`. It then sends the menu, the inventory and the cursor back as they were, the same path as a click the server refuses. That covers every click mode: shift, number keys, drags, double click. - **The clicks and the closing reach the mod.** `native_menu_clicked(uuid, window, slot, button, mode)` and `native_menu_closed(uuid, window)` cover the player closing it, another menu opening, or the player leaving (`remove_guest`). They run from `tick_lan` once the hub is back in `self.lan`, with no player's state swapped in. - `native_menu_inventory_slot(size, slot)` maps a click below the menu to the player's inventory slot. `native_player_stacks(uuid)` returns the player's 36 slots. - **`native_exchange_items(a, a_offer, b, b_offer)`** swaps two players' offers in one step, or nothing. Each offer is a list of inventory slots, each with the exact stack it must still hold. The swap is refused, with nothing moved, if an offer changed, a stack doesn't fit whole on the other side, a player is gone or dead, or a player's state is swapped in. A trade built on this keeps the offered stacks in their owners' inventories until that step, so no way out (close, leave, die) has anything to return or to duplicate. - `NATIVE_HOOKS_API` 9 → 10, `native-hooks.json`, docs/native-mods.md ("Server menus"). **With no mod opening one nothing changes**: no `Slots::Native` menu exists, the event list stays empty (one `is_empty` per tick), and the new match arms are never taken. ## Kind - [x] extra: Horizon-only, off by default ## Vanilla reference `ChestMenu` (`MenuType.GENERIC_9x1`..`9x6`): the slot layout (menu, then 27 inventory slots, then the hotbar) as `ChestMenu`'s constructor adds them. A refused click is answered as `AbstractContainerMenu.broadcastFullState` after a failed click. ## Proof `native/tools/native.py proof smp` on this head (e23b4b7), in horizon-mods' `feat/smp-trade` (horizon-rust/horizon-mods#57): a dedicated server built with the SMP mod, two real clients (`horizon-ctl --offscreen`, fresh folders) clicking the server's trade menu as a player does (`click-slot`), every item counted from each player's own client: - **closing the menu**: Alex offered 10 diamonds; Steve's menu showed them; Alex still held them; Alex closed it. Steve's menu closed and he saw "Trade cancelled: Alex closed the trade. Nothing was exchanged."; nothing moved. - **a full inventory**: both confirmed while Steve had no room. "The trade didn't go through: the second player has no room.", nothing moved, and both confirmations were cleared. - **the cancel button**: the trade ended and nothing moved. - **a change clears the other's confirmation**: Steve's `/trade money 35` after Alex confirmed turned Alex's button back to "Confirm". - **through**: Alex's 10 diamonds for Steve's 5 emeralds and 35 coins. The clients counted (Alex 0 diamonds, 5 emeralds; Steve 10 diamonds, 0 emeralds), and the balances were 415 / 400. - **dying** (`keep_inventory` on, so a duplicate would show): "Trade cancelled: Alex is gone.", and the counts were unchanged after he respawned. - **leaving**: Steve quit mid-trade with his diamonds offered. Alex's menu closed and nothing moved; Steve came back with his 10 diamonds. - **the files**: `economy.json` held 415 / 400 after a restart, and `audit.log` ended `trade, trade_failed, trade, trade_money`. Unit tests: the slot mapping; an exchange that swaps both sides (merged onto stacks, then into empty slots, with totals kept); an exchange that can't complete moving nothing (a changed offer, an empty or out-of-range slot, no room, the same slot offered twice). ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at f6a757ac2, 8 min 16 s) | Check | Result | | --- | --- | | Scope | ⚠️ 13 files, +1378 −7; 1324 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 2 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (2 min 11 s) | | tests: horizon-client | ✅ 1072 passed (4 min 25 s) | | doc tests | ✅ 0 passed (2 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 | ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The scope counts #4514 and #4519 too (stacked); this PR's own commit is the last. 🤖 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 05:14:18 +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#5681
No description provided.