[PR #7578] world/client: the level recounts a container's openers so a stale count closes the lid #7688

Open
opened 2026-11-03 07:22:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7578
Author: @MSedgeMC
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/chest-openers-recheck


📝 Commits (3)

  • 696d83a fix: the level recounts a container's openers, and the first opener schedules it
  • 120c53b test: a stale opener count is recounted away
  • 12c0aea port_map: the openers counter says who schedules and who recounts

📊 Changes

3 files changed (+141 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+48 -3)
📝 crates/horizon-client/src/game/block_entity_anims.rs (+91 -0)
📝 tools/port_map/game2-017.tsv (+2 -0)

📄 Description

Vanilla

A container with an openers counter rechecks who still has it open, on its own scheduled tick, every five
ticks while anyone does.

ContainerOpenersCounter.incrementOpeners schedules that recheck the moment the count leaves zero:

  13: iload 7        // the new openCount
  15: ifne 42        // only when it became non-zero
  18-23: onOpen(level, pos, state)
  26-32: level.gameEvent(entity, CONTAINER_OPEN, pos)
  35-39: scheduleRecheck(level, pos, state)

scheduleRecheck is Level.scheduleTick(pos, state.getBlock(), 5) (CHECK_TICK_DELAY = 5) and
ContainerOpenersCounter.recheckOpeners recounts:

   0-6: getEntitiesWithContainerOpen(level, pos)     // who still has it open
  65-84: count = list.size(); if (openCount == count) skip
  87-137: count > 0 and openCount == 0 -> onOpen + level.gameEvent(null, CONTAINER_OPEN, pos)
 140-158: count == 0 and openCount != 0 -> onClose + level.gameEvent(null, CONTAINER_CLOSE, pos)
 161-164: openCount = count
 167-175: openerCountChanged(level, pos, state, old, count)     // always
 178-186: count > 0 -> scheduleRecheck                          // repeat

ChestBlock.tick, EnderChestBlock.tick and BarrelBlock.tick are the callers: each fetches its block
entity and calls recheckOpen. A chest's openerCountChanged is signalOpenCount, which sends block event
1 with the count (the lid), and a trapped chest's getSignal is that count.

Horizon

horizon-world already dispatched the recheck — Sim::tick_block's Class::Chest | Class::EnderChest arm
calls LevelAccess::recheck_container_openers and, on Some((previous, count)), queues block event 1 and
updates a trapped chest's neighbours — but the trait method was left to the game and GameLevel never
implemented it, so the default None was answered. Nothing ever rechecked, and nothing even scheduled the
recheck in the first place (incrementOpeners' scheduleRecheck had no port).

The player-visible effect of that stale count: a chest or barrel whose menu closed without the close path (a
death, a teleport, a dropped connection, a guest leaving mid-click) keeps openCount above zero, so its lid
stays open, its close sound never plays, and a trapped chest's comparator signal stays high.

GameLevel::recheck_container_openers now answers from the two facts that know who has what open — the local
player's container and each guest's menu.pos — counting both halves of a double chest
(ChestBlockEntity$1.isOwnContainer takes a CompoundContainer) and never a spectator; it returns None
for any block that keeps no openers counter. Game::count_opener schedules the five-tick recheck when the
first opener arrives, as incrementOpeners does.

Proven:

cargo test -p horizon-client --lib block_entity_anims::tests — 3 passed:

  • a_stale_opener_count_is_recounted_away: a chest opened ((0, 1), the count stored as 1) and then closed
    without the close path is recounted to (1, 0) and its entry is removed, so the next opener counts from
    zero again. Before the fix the recheck was never asked at all, and had it been, the answer was None, so
    the count stayed 1 and the lid stayed open.
  • a_recount_that_agrees_leaves_the_count_alone: (1, 1) with the stored count untouched.
  • both_halves_of_a_double_chest_count: both halves of a double chest count for a player, two players on one
    half give (0, 2), and another container's position is ignored (openers_at 1 there, 0 elsewhere).

cargo clippy -q -p horizon-client --lib is silent and rustfmt --edition 2024 --check is clean.

The world's side of the chain is already covered by PR #7562's
a_barrel_recounts_its_openers_on_its_scheduled_tick, which needs a level; with this hook answering, its
(1, 0) answer closes the barrel and plays block.barrel.close.

Not proven:

  • No client-level test drives a chest through open → stale → tick → lid closed: a Game harness needs the
    prepared client resources (block-behaviours.json, the item and block tables), which this machine does
    not have, and the level tests skip without them.
  • The recount sees the containers lid_openers counts — this process's local player and its LAN guests. A
    player whose menu is held elsewhere is not visible to it, so the count stays as tracked for them.

🔄 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/7578 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/chest-openers-recheck` --- ### 📝 Commits (3) - [`696d83a`](https://github.com/horizon-rust/horizon/commit/696d83a3322b50f50478c09d3b7086434c85a435) fix: the level recounts a container's openers, and the first opener schedules it - [`120c53b`](https://github.com/horizon-rust/horizon/commit/120c53b535240c247d94c787ce76c7a768962ca0) test: a stale opener count is recounted away - [`12c0aea`](https://github.com/horizon-rust/horizon/commit/12c0aea68705486f52f6d7bc97f4981cd0c4837c) port_map: the openers counter says who schedules and who recounts ### 📊 Changes **3 files changed** (+141 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+48 -3) 📝 `crates/horizon-client/src/game/block_entity_anims.rs` (+91 -0) 📝 `tools/port_map/game2-017.tsv` (+2 -0) </details> ### 📄 Description ## Vanilla A container with an openers counter rechecks who still has it open, on its own scheduled tick, every five ticks while anyone does. `ContainerOpenersCounter.incrementOpeners` schedules that recheck the moment the count leaves zero: ``` 13: iload 7 // the new openCount 15: ifne 42 // only when it became non-zero 18-23: onOpen(level, pos, state) 26-32: level.gameEvent(entity, CONTAINER_OPEN, pos) 35-39: scheduleRecheck(level, pos, state) ``` `scheduleRecheck` is `Level.scheduleTick(pos, state.getBlock(), 5)` (`CHECK_TICK_DELAY = 5`) and `ContainerOpenersCounter.recheckOpeners` recounts: ``` 0-6: getEntitiesWithContainerOpen(level, pos) // who still has it open 65-84: count = list.size(); if (openCount == count) skip 87-137: count > 0 and openCount == 0 -> onOpen + level.gameEvent(null, CONTAINER_OPEN, pos) 140-158: count == 0 and openCount != 0 -> onClose + level.gameEvent(null, CONTAINER_CLOSE, pos) 161-164: openCount = count 167-175: openerCountChanged(level, pos, state, old, count) // always 178-186: count > 0 -> scheduleRecheck // repeat ``` `ChestBlock.tick`, `EnderChestBlock.tick` and `BarrelBlock.tick` are the callers: each fetches its block entity and calls `recheckOpen`. A chest's `openerCountChanged` is `signalOpenCount`, which sends block event 1 with the count (the lid), and a trapped chest's `getSignal` is that count. ## Horizon `horizon-world` already dispatched the recheck — `Sim::tick_block`'s `Class::Chest | Class::EnderChest` arm calls `LevelAccess::recheck_container_openers` and, on `Some((previous, count))`, queues block event 1 and updates a trapped chest's neighbours — but the trait method was left to the game and `GameLevel` never implemented it, so the default `None` was answered. Nothing ever rechecked, and nothing even scheduled the recheck in the first place (`incrementOpeners`' `scheduleRecheck` had no port). The player-visible effect of that stale count: a chest or barrel whose menu closed without the close path (a death, a teleport, a dropped connection, a guest leaving mid-click) keeps `openCount` above zero, so its lid stays open, its close sound never plays, and a trapped chest's comparator signal stays high. `GameLevel::recheck_container_openers` now answers from the two facts that know who has what open — the local player's `container` and each guest's `menu.pos` — counting both halves of a double chest (`ChestBlockEntity$1.isOwnContainer` takes a `CompoundContainer`) and never a spectator; it returns `None` for any block that keeps no openers counter. `Game::count_opener` schedules the five-tick recheck when the first opener arrives, as `incrementOpeners` does. ## **Proven:** `cargo test -p horizon-client --lib block_entity_anims::tests` — 3 passed: - `a_stale_opener_count_is_recounted_away`: a chest opened (`(0, 1)`, the count stored as 1) and then closed without the close path is recounted to `(1, 0)` and its entry is removed, so the next opener counts from zero again. Before the fix the recheck was never asked at all, and had it been, the answer was `None`, so the count stayed 1 and the lid stayed open. - `a_recount_that_agrees_leaves_the_count_alone`: `(1, 1)` with the stored count untouched. - `both_halves_of_a_double_chest_count`: both halves of a double chest count for a player, two players on one half give `(0, 2)`, and another container's position is ignored (`openers_at` 1 there, 0 elsewhere). `cargo clippy -q -p horizon-client --lib` is silent and `rustfmt --edition 2024 --check` is clean. The world's side of the chain is already covered by PR #7562's `a_barrel_recounts_its_openers_on_its_scheduled_tick`, which needs a level; with this hook answering, its `(1, 0)` answer closes the barrel and plays `block.barrel.close`. ## **Not proven:** - No client-level test drives a chest through open → stale → tick → lid closed: a `Game` harness needs the prepared client resources (`block-behaviours.json`, the item and block tables), which this machine does not have, and the level tests skip without them. - The recount sees the containers `lid_openers` counts — this process's local player and its LAN guests. A player whose menu is held elsewhere is not visible to it, so the count stays as tracked for them. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7688
No description provided.