[GH-ISSUE #6188] Native mods: a player opening and closing a menu, PlayerContainerEvent #2005

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

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

Originally assigned to: @levzzz5154 on GitHub.

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

Part of #4953 ("Player opens and closes a container (PlayerContainerEvent.Open / Close), for blocks that change while someone has them open").

Problem

native_mod_container_viewers (#6049) tells a mod how many players have one of its containers open. It cannot say which player, cannot see vanilla menus (a chest, a furnace, a crafting table, a trade) and cannot see a menu that is not a block's. A mod that logs who looked into a chest, locks a machine to its first user, or starts a process when a player opens a menu needs a per-player, per-menu event.

Vanilla and NeoForge

  • Vanilla: ServerPlayer.openMenu sets the new containerMenu (after initMenu); openHorseInventory and openNautilusInventory do the same; doCloseContainer runs containerMenu.removed(player), then goes back to the inventory menu. closeContainer, a death, a disconnect, stillValid failing and a new openMenu all end in doCloseContainer.
  • NeoForge: PlayerContainerEvent.Open(player, menu) is posted right after containerMenu is set in those three methods; PlayerContainerEvent.Close(player, menu) is posted in doCloseContainer after removed. Neither can be cancelled.

Proposal

Two server hook points, API from a fragment (tools/native-hook-fragments/player_container_events.json):

  • native_player_container_open(player, name, dimension, menu, pos)
  • native_player_container_close(player, name, dimension, menu, pos)

menu is the menu type's name, pos the block for a block's menu. The player's state is swapped in, so the helpers reach them. Horizon keeps a guest's open menu in several places (the hub's container, trade, crafting table, workstation, lectern, mount), so the game compares what each player has open with what the mods last heard once a tick, and also tells the close at once when a menu is closed for a new one or for a leaving player.

Not in this step: the player's own inventory menu (vanilla posts Close for it too, when the client sends a close with window 0, but it has no Open), and cancelling.

Originally created by @levzzz5154 on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6188 Originally assigned to: @levzzz5154 on GitHub. > 🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. Part of #4953 ("Player opens and closes a container (`PlayerContainerEvent.Open` / `Close`), for blocks that change while someone has them open"). ## Problem `native_mod_container_viewers` (#6049) tells a mod how many players have one of its containers open. It cannot say which player, cannot see vanilla menus (a chest, a furnace, a crafting table, a trade) and cannot see a menu that is not a block's. A mod that logs who looked into a chest, locks a machine to its first user, or starts a process when a player opens a menu needs a per-player, per-menu event. ## Vanilla and NeoForge - Vanilla: `ServerPlayer.openMenu` sets the new `containerMenu` (after `initMenu`); `openHorseInventory` and `openNautilusInventory` do the same; `doCloseContainer` runs `containerMenu.removed(player)`, then goes back to the inventory menu. `closeContainer`, a death, a disconnect, `stillValid` failing and a new `openMenu` all end in `doCloseContainer`. - NeoForge: `PlayerContainerEvent.Open(player, menu)` is posted right after `containerMenu` is set in those three methods; `PlayerContainerEvent.Close(player, menu)` is posted in `doCloseContainer` after `removed`. Neither can be cancelled. ## Proposal Two server hook points, API from a fragment (`tools/native-hook-fragments/player_container_events.json`): - `native_player_container_open(player, name, dimension, menu, pos)` - `native_player_container_close(player, name, dimension, menu, pos)` `menu` is the menu type's name, `pos` the block for a block's menu. The player's state is swapped in, so the helpers reach them. Horizon keeps a guest's open menu in several places (the hub's container, trade, crafting table, workstation, lectern, mount), so the game compares what each player has open with what the mods last heard once a tick, and also tells the close at once when a menu is closed for a new one or for a leaving player. Not in this step: the player's own inventory menu (vanilla posts `Close` for it too, when the client sends a close with window 0, but it has no `Open`), and cancelling.
Author
Owner

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

/claim

<!-- gh-comment-id:6561731754 --> @levzzz5154 commented on GitHub (Nov 1, 2026): /claim
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#2005
No description provided.