[PR #7562] world: a barrel recounts its openers on its scheduled tick (BarrelBlock.tick) #7674

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

📋 Pull Request Information

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

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


📝 Commits (3)

  • 6e17bc6 fix: a barrel recounts its openers on its scheduled tick
  • 66b5fba test: a barrel's scheduled tick recounts its openers
  • aca46f0 port_map: recheckOpen says what rechecks a barrel

📊 Changes

4 files changed (+142 additions, -2 deletions)

View changed files

📝 crates/horizon-world/src/level/tests.rs (+102 -0)
📝 crates/horizon-world/src/level/tick.rs (+38 -0)
📝 tools/port_map/classes-03.tsv (+1 -1)
📝 tools/port_map/classes-04.tsv (+1 -1)

📄 Description

Vanilla

BarrelBlock.tick recounts the barrel's openers on the barrel's own scheduled tick:

protected void tick(BlockState, ServerLevel, BlockPos, RandomSource);
   0: aload_2  1: aload_3  2: invokevirtual ServerLevel.getBlockEntity
   9: instanceof BarrelBlockEntity ... 24: invokevirtual BarrelBlockEntity.recheckOpen()V

BarrelBlockEntity.recheckOpen forwards to ContainerOpenersCounter.recheckOpeners(level, pos, state)
(getfield openersCounter, invokevirtual recheckOpeners), which counts the entities that still have the
container open and, when the count differs from openCount, calls onOpen/onClose and then
level.gameEvent(null, CONTAINER_OPEN or CONTAINER_CLOSE, pos) (bytecode 31-164); it always calls
openerCountChanged(level, pos, state, old, count) (167-175) and, while the count is above zero,
scheduleRecheck (178-186). A barrel's openerCountChanged is an empty return
(BarrelBlockEntity$1), so it broadcasts no block event — unlike a chest's signalOpenCount, which does.
Its onOpen/onClose play BARREL_OPEN/BARREL_CLOSE through BarrelBlockEntity.playSound
(SoundSource.BLOCKS, volume 0.5f, pitch 0.9f + level.getRandom().nextFloat() * 0.1f) and call
updateBlockState, i.e. Level.setBlockAndUpdate(pos, state.setValue(OPEN, open)).

Horizon

Sim::tick_block dispatched the container recheck for Class::Chest | Class::EnderChest only, so a
barrel's scheduled tick fell through to the catch-all arm and its block entity was never asked to recount
anything: a barrel whose viewers all left stayed open=true, played no close sound and sent no
container_close game event.

The new arm asks the level for the recount, applies updateBlockState, plays the barrel's sound and sends
the container game event when the count crosses zero, and keeps the recheck repeating every five ticks
while someone still has it open. It deliberately queues no block event, as vanilla's empty
openerCountChanged does.

tools/port_map/classes-04.tsv had BarrelBlockEntity.recheckOpen as missing; it now points at the port.

Proven:

The new test a_barrel_recounts_its_openers_on_its_scheduled_tick (crates/horizon-world/src/level/tests.rs)
drives one scheduled tick of a barrel whose opener recount answers (1, 0) and asserts: the hook was called
for the barrel ([pos]), the state is now open=false, minecraft:block.barrel.close was played once at
volume 0.5 with a pitch in 0.9..1.0, minecraft:container_close was sent once, and ticks.block_events
is empty. A (0, 1) recount then reopens it with block.barrel.open and container_open; the recheck
repeats five ticks later while the count stays above zero; and once the recount answers zero again the chain
stops.

Without the arm the first assertion fails with opener_rechecks == [] (the hook is never called) and the
barrel stays open=true.

Not proven:

  • The level tests need the prepared client resources (block-behaviours.json and the registry) and this
    machine has none, so cargo test -p horizon-world --lib barrel here skips the body; CI runs it.
  • Until the level answers the recheck this arm changes nothing: GameLevel did not implement
    LevelAccess::recheck_container_openers, so the game answered None for a barrel — exactly as it did for
    the pre-existing chest arm. PR #7578 implements that hook (the player's container plus each guest's
    menu.pos) and the five-tick schedule that starts it, so with that PR this arm closes a barrel whose
    viewers left; this PR alone still needs it.

🔄 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/7562 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/barrel-openers-recheck` --- ### 📝 Commits (3) - [`6e17bc6`](https://github.com/horizon-rust/horizon/commit/6e17bc643eb0ef292a6e54b7a8228c6d3e497b7b) fix: a barrel recounts its openers on its scheduled tick - [`66b5fba`](https://github.com/horizon-rust/horizon/commit/66b5fba32bad74db197043f4bd18026aa4dc850b) test: a barrel's scheduled tick recounts its openers - [`aca46f0`](https://github.com/horizon-rust/horizon/commit/aca46f07210adc467879a068bac70b685c1f3032) port_map: recheckOpen says what rechecks a barrel ### 📊 Changes **4 files changed** (+142 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/level/tests.rs` (+102 -0) 📝 `crates/horizon-world/src/level/tick.rs` (+38 -0) 📝 `tools/port_map/classes-03.tsv` (+1 -1) 📝 `tools/port_map/classes-04.tsv` (+1 -1) </details> ### 📄 Description ## Vanilla `BarrelBlock.tick` recounts the barrel's openers on the barrel's own scheduled tick: ``` protected void tick(BlockState, ServerLevel, BlockPos, RandomSource); 0: aload_2 1: aload_3 2: invokevirtual ServerLevel.getBlockEntity 9: instanceof BarrelBlockEntity ... 24: invokevirtual BarrelBlockEntity.recheckOpen()V ``` `BarrelBlockEntity.recheckOpen` forwards to `ContainerOpenersCounter.recheckOpeners(level, pos, state)` (`getfield openersCounter`, `invokevirtual recheckOpeners`), which counts the entities that still have the container open and, when the count differs from `openCount`, calls `onOpen`/`onClose` and then `level.gameEvent(null, CONTAINER_OPEN or CONTAINER_CLOSE, pos)` (bytecode `31`-`164`); it always calls `openerCountChanged(level, pos, state, old, count)` (`167`-`175`) and, while the count is above zero, `scheduleRecheck` (`178`-`186`). A barrel's `openerCountChanged` is an empty `return` (`BarrelBlockEntity$1`), so it broadcasts no block event — unlike a chest's `signalOpenCount`, which does. Its `onOpen`/`onClose` play `BARREL_OPEN`/`BARREL_CLOSE` through `BarrelBlockEntity.playSound` (`SoundSource.BLOCKS`, volume `0.5f`, pitch `0.9f + level.getRandom().nextFloat() * 0.1f`) and call `updateBlockState`, i.e. `Level.setBlockAndUpdate(pos, state.setValue(OPEN, open))`. ## Horizon `Sim::tick_block` dispatched the container recheck for `Class::Chest | Class::EnderChest` only, so a barrel's scheduled tick fell through to the catch-all arm and its block entity was never asked to recount anything: a barrel whose viewers all left stayed `open=true`, played no close sound and sent no `container_close` game event. The new arm asks the level for the recount, applies `updateBlockState`, plays the barrel's sound and sends the container game event when the count crosses zero, and keeps the recheck repeating every five ticks while someone still has it open. It deliberately queues no block event, as vanilla's empty `openerCountChanged` does. `tools/port_map/classes-04.tsv` had `BarrelBlockEntity.recheckOpen` as `missing`; it now points at the port. ## **Proven:** The new test `a_barrel_recounts_its_openers_on_its_scheduled_tick` (crates/horizon-world/src/level/tests.rs) drives one scheduled tick of a barrel whose opener recount answers `(1, 0)` and asserts: the hook was called for the barrel (`[pos]`), the state is now `open=false`, `minecraft:block.barrel.close` was played once at volume `0.5` with a pitch in `0.9..1.0`, `minecraft:container_close` was sent once, and `ticks.block_events` is empty. A `(0, 1)` recount then reopens it with `block.barrel.open` and `container_open`; the recheck repeats five ticks later while the count stays above zero; and once the recount answers zero again the chain stops. Without the arm the first assertion fails with `opener_rechecks == []` (the hook is never called) and the barrel stays `open=true`. ## **Not proven:** - The level tests need the prepared client resources (`block-behaviours.json` and the registry) and this machine has none, so `cargo test -p horizon-world --lib barrel` here skips the body; CI runs it. - Until the level answers the recheck this arm changes nothing: `GameLevel` did not implement `LevelAccess::recheck_container_openers`, so the game answered `None` for a barrel — exactly as it did for the pre-existing chest arm. PR #7578 implements that hook (the player's `container` plus each guest's `menu.pos`) and the five-tick schedule that starts it, so with that PR this arm closes a barrel whose viewers left; this PR alone still needs it. --- <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#7674
No description provided.