[GH-ISSUE #6557] native_acting_player is None and native_give_stack reaches no one inside native_menu_button_v2 #2132

Closed
opened 2026-11-02 15:52:21 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @JuanLuci on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6557

Summary

Inside native_menu_button_v2, on the server, even in single player:

  • native_acting_player() returns None.
  • native_acting_id() returns a UUID that isn't the clicking player's.
  • native_give_stack hands the stack back for every UUID, the player's real one included.

The same calls work from native_right_click_block, and native_give_stack with the player's real UUID works from native_block_entity_tick.

Why

AbstractContainerMenu.clickMenuButton(Player, int) is given the player. The doc on native_menu_button_v2 calls carried "the acting player's cursor stack", and the doc on native_give_stack says "from any server hook", so a mod reasonably expects both to work here. A button that does anything for the player who pressed it needs them: moving a stack to their inventory, checking who they are, telling them something.

Reproduction

A minimal bundle: a content block on the minecraft:barrel template, a block entity, ModContainer { slots: 9, menu: Some("minecraft:generic_9x1"), .. }, and native_screen_click setting button = Some(1). It runs the same report from three hooks, giving a minecraft:apple each time:

let acting = game.native_acting_player().map(|p| p.uuid);
let id = game.native_acting_id();
let to_id = game.native_give_stack(id, apple()).is_none();
// `known` is the UUID native_acting_player gave in native_right_click_block.
let to_known = known.map(|uuid| game.native_give_stack(uuid, apple()).is_none());

On main at f8bfa06b9, in a single player world, opening the block and pressing the button:

Hook native_acting_player native_acting_id Give to the acting id Give to the known UUID
native_right_click_block 70b53298... 70b53298... given given
native_menu_button_v2 None a01e3843... handed back handed back
native_block_entity_tick None a01e3843... handed back given

The player ended with 3 apples, as the table says.

From reading the code: lan_station_button in lan_stations.rs has the host out of self.lan and calls mod_menu_button directly, not through as_guest. So no lan_acting_* is set, and native_give_stack finds no self.lan to look the player up in. I didn't trace why the acting id's own branch refuses the stack.

Proposal

  • Run mod_menu_button inside as_guest(host, conn, ...), the way a guest's other actions run, so native_acting_player, native_acting_id and native_give_stack all answer for the player who pressed the button. carried stays as it is, read from the guest before and written back after.
  • If swapping the state in is too heavy here, give the hook the player's UUID and let native_give_stack reach the guest through host.
  • Either way, a test that presses a mod menu button and gives a stack, since the docs promise this today.

On my port

I ported the connector and the Storage Terminal of Tom's Simple Storage (tom5454, MIT) to a native mod, tested on Nightly c9d474d. The terminal's list is drawn by the mod and a click on it is a menu button, which is how taking a stack onto the cursor works, and that part is fine.

Shift-click should send the stack to the inventory of the player who clicked. In my first build it asked native_acting_player who that was, got None, and the stack was lost, which was my code not handling None. With the acting id instead, the stack came back and stayed on the cursor.

The workaround: on a shift-click, native_screen_click swallows the press and the client sends native_net_send_to_server. native_net_from_client has the player's UUID, queues the request, and native_block_entity_tick makes the transfer with native_give_stack. It works, a tick late, with a message channel where a button should have been enough.

Originally created by @JuanLuci on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6557 ## Summary Inside `native_menu_button_v2`, on the server, even in single player: - `native_acting_player()` returns `None`. - `native_acting_id()` returns a UUID that isn't the clicking player's. - `native_give_stack` hands the stack back for every UUID, the player's real one included. The same calls work from `native_right_click_block`, and `native_give_stack` with the player's real UUID works from `native_block_entity_tick`. ## Why `AbstractContainerMenu.clickMenuButton(Player, int)` is given the player. The doc on `native_menu_button_v2` calls `carried` "the acting player's cursor stack", and the doc on `native_give_stack` says "from any server hook", so a mod reasonably expects both to work here. A button that does anything for the player who pressed it needs them: moving a stack to their inventory, checking who they are, telling them something. ## Reproduction A minimal bundle: a content block on the `minecraft:barrel` template, a block entity, `ModContainer { slots: 9, menu: Some("minecraft:generic_9x1"), .. }`, and `native_screen_click` setting `button = Some(1)`. It runs the same report from three hooks, giving a `minecraft:apple` each time: ```rust let acting = game.native_acting_player().map(|p| p.uuid); let id = game.native_acting_id(); let to_id = game.native_give_stack(id, apple()).is_none(); // `known` is the UUID native_acting_player gave in native_right_click_block. let to_known = known.map(|uuid| game.native_give_stack(uuid, apple()).is_none()); ``` On main at f8bfa06b9, in a single player world, opening the block and pressing the button: | Hook | `native_acting_player` | `native_acting_id` | Give to the acting id | Give to the known UUID | |---|---|---|---|---| | `native_right_click_block` | `70b53298...` | `70b53298...` | given | given | | `native_menu_button_v2` | `None` | `a01e3843...` | handed back | handed back | | `native_block_entity_tick` | `None` | `a01e3843...` | handed back | given | The player ended with 3 apples, as the table says. From reading the code: `lan_station_button` in `lan_stations.rs` has the host out of `self.lan` and calls `mod_menu_button` directly, not through `as_guest`. So no `lan_acting_*` is set, and `native_give_stack` finds no `self.lan` to look the player up in. I didn't trace why the acting id's own branch refuses the stack. ## Proposal - Run `mod_menu_button` inside `as_guest(host, conn, ...)`, the way a guest's other actions run, so `native_acting_player`, `native_acting_id` and `native_give_stack` all answer for the player who pressed the button. `carried` stays as it is, read from the guest before and written back after. - If swapping the state in is too heavy here, give the hook the player's UUID and let `native_give_stack` reach the guest through `host`. - Either way, a test that presses a mod menu button and gives a stack, since the docs promise this today. ## On my port I ported the connector and the Storage Terminal of Tom's Simple Storage (tom5454, MIT) to a native mod, tested on Nightly c9d474d. The terminal's list is drawn by the mod and a click on it is a menu button, which is how taking a stack onto the cursor works, and that part is fine. Shift-click should send the stack to the inventory of the player who clicked. In my first build it asked `native_acting_player` who that was, got `None`, and the stack was lost, which was my code not handling `None`. With the acting id instead, the stack came back and stayed on the cursor. The workaround: on a shift-click, `native_screen_click` swallows the press and the client sends `native_net_send_to_server`. `native_net_from_client` has the player's UUID, queues the request, and `native_block_entity_tick` makes the transfer with `native_give_stack`. It works, a tick late, with a message channel where a button should have been enough.
Author
Owner

@xFedeT commented on GitHub (Nov 1, 2026):

🤖 Agent: fix opened (see the linked PR): the button now runs inside as_guest, as the issue proposed.

<!-- gh-comment-id:6565383509 --> @xFedeT commented on GitHub (Nov 1, 2026): 🤖 Agent: fix opened (see the linked PR): the button now runs inside `as_guest`, as the issue proposed.
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#2132
No description provided.