[GH-ISSUE #6047] Native mods: hear a mod container's viewers change (ContainerOpenersCounter) #1947

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

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

Originally assigned to: @Xmilon on GitHub.

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

A native mod's block with a container (a mod menu type, open_mod_menu) cannot show itself open the way a vanilla barrel does: the OPEN blockstate is set while any player has it open and cleared when the last one leaves. A mod gets no event when a player opens or closes its container, and a player can leave without closing (disconnect, death, moving out of reach, a dimension change, the block breaking).

Vanilla: BarrelBlockEntity holds a ContainerOpenersCounter; incrementOpeners / decrementOpeners run when a player's ChestMenu opens and closes, onOpen / onClose fire when the count goes from 0 to more than 0 and back, openerCountChanged on every change, and recheckOpeners finds the players who left without closing.

Proposal: one server-side hook, native_mod_container_viewers(dimension, pos, viewers, previous), heard once each time the number of players with the container at pos open changes (0 to 1 opens it, back to 0 closes it, as onOpen/onClose; any change is openerCountChanged). The count is recounted every server tick from the players' open menus, so every way of leaving is covered the way recheckOpeners does it, and a level keeps ticking until its last change was heard. A no-op without a mod; an API fragment, no catalog edits. NeoForge has no event for it (it is the block entity's own counter), so it keeps a Horizon name.

Test: the real counting and dispatch with a fake mod, covering open, a second viewer, both closing, and a viewer that vanishes without closing.

🤖 Generated with Claude Code

Originally created by @Xmilon on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6047 Originally assigned to: @Xmilon on GitHub. > 🤖 Filed by Xmilon's AI agent (Claude Code, Sonnet 5.5), not by Xmilon personally. A native mod's block with a container (a mod menu type, `open_mod_menu`) cannot show itself open the way a vanilla barrel does: the `OPEN` blockstate is set while any player has it open and cleared when the last one leaves. A mod gets no event when a player opens or closes its container, and a player can leave without closing (disconnect, death, moving out of reach, a dimension change, the block breaking). Vanilla: `BarrelBlockEntity` holds a `ContainerOpenersCounter`; `incrementOpeners` / `decrementOpeners` run when a player's `ChestMenu` opens and closes, `onOpen` / `onClose` fire when the count goes from 0 to more than 0 and back, `openerCountChanged` on every change, and `recheckOpeners` finds the players who left without closing. Proposal: one server-side hook, `native_mod_container_viewers(dimension, pos, viewers, previous)`, heard once each time the number of players with the container at `pos` open changes (0 to 1 opens it, back to 0 closes it, as `onOpen`/`onClose`; any change is `openerCountChanged`). The count is recounted every server tick from the players' open menus, so every way of leaving is covered the way `recheckOpeners` does it, and a level keeps ticking until its last change was heard. A no-op without a mod; an API fragment, no catalog edits. NeoForge has no event for it (it is the block entity's own counter), so it keeps a Horizon name. Test: the real counting and dispatch with a fake mod, covering open, a second viewer, both closing, and a viewer that vanishes without closing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

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

🤖 Agent: /claim

<!-- gh-comment-id:6559861731 --> @Xmilon commented on GitHub (Nov 1, 2026): 🤖 Agent: /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#1947
No description provided.