From 0f2a497f0241248adcbe88d564004b0c9bec122f Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:09:16 +0100 Subject: [PATCH] Trapped chests give their signal, barrels show they're open TrappedChestBlock.getSignal is the chest's opener count (at most 15); TrappedChestBlockEntity.signalOpenCount updates the blocks around it and below it when the count changes. GameLevel answered 0 for every trapped chest. BarrelBlockEntity's openers set open=true for the first one and open=false when the last one leaves; nothing set it. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 7 +++ .../src/game/block_entity_anims.rs | 60 ++++++++++++++++--- .../src/game/machines/crafter.rs | 2 +- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 699468651..64f37ec31 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -548,6 +548,8 @@ struct GameLevel<'w> { /// Where the chunk tickets let blocks tick. tickets: horizon_client::ticket_levels::Levels, random_tick_sections: &'w mut horizon_client::random_tick_sections::RandomTickSections, + /// Players with each chest open (a trapped chest's signal). + lid_openers: &'w HashMap<(i32, i32, i32), i32>, } struct PlayerCollision { y: f64, @@ -683,6 +685,10 @@ impl LevelAccess for GameLevel<'_> { _state: BlockStateId, _direction: Direction, ) -> i32 { + // TrappedChestBlock.getSignal: the players with it open, at most 15. + if let Some(count) = self.lid_openers.get(&(pos.x, pos.y, pos.z)) { + return (*count).clamp(0, 15); + } jukebox::jukebox_signals(self.world, self.items, pos).map_or(0, |(signal, _)| signal) } fn biome_name(&self, pos: BlockPos) -> Option<&str> { @@ -2428,6 +2434,7 @@ impl Game<'_> { spill: &mut self.spill, tickets: self.tickets.levels(), random_tick_sections: &mut self.random_tick_sections, + lid_openers: &self.lid_openers, }; let result = f(self.res.behaviours(), &mut level, &mut self.block_ticks); self.flush_spill(); diff --git a/crates/horizon-client/src/game/block_entity_anims.rs b/crates/horizon-client/src/game/block_entity_anims.rs index 619fcd009..4fbec9c7a 100644 --- a/crates/horizon-client/src/game/block_entity_anims.rs +++ b/crates/horizon-client/src/game/block_entity_anims.rs @@ -11,7 +11,10 @@ use horizon_client::{ particles::{ParticleOptions, ParticleType}, save::number, }; -use horizon_core::geometry::{Aabb, Vec3}; +use horizon_core::{ + geometry::{Aabb, Vec3}, + position::BlockPos, +}; use horizon_world::nbt::Tag; /// The handle of the local player among a bell's gathered entities. @@ -84,6 +87,16 @@ impl Game<'_> { self.lid_openers_changed(other, open); } } + _ if self + .res + .facts() + .get(self.world.block(pos[0], pos[1], pos[2])) + .name + .as_ref() + == "minecraft:barrel" => + { + self.barrel_openers_changed(key, open); + } Some(Ticker::Shulker { .. }) => { let shulker = self.be_anims.shulkers.entry(pos).or_default(); let (count, _) = if open { @@ -102,15 +115,48 @@ impl Game<'_> { /// `ChestBlockEntity.signalOpenCount`: block event 1 with the count, here /// and for the guests. fn lid_openers_changed(&mut self, key: (i32, i32, i32), open: bool) { - let count = self.lid_openers.entry(key).or_default(); - *count = (*count + if open { 1 } else { -1 }).max(0); - let count = *count; - if count == 0 { - self.lid_openers.remove(&key); - } + let (before, count) = self.count_opener(key, open); let pos = [key.0, key.1, key.2]; self.block_entity_event(pos, 1, count); self.lan_block_event(pos, 1, count); + // TrappedChestBlockEntity.signalOpenCount: its signal is the count + // (`TrappedChestBlock.getSignal`), so the blocks around it and + // below it hear of a change. + let state = self.world.block(pos[0], pos[1], pos[2]); + if before != count && self.res.facts().get(state).name.as_ref() == "minecraft:trapped_chest" + { + let p = BlockPos::new(pos[0], pos[1], pos[2]); + self.with_level(|b, level, ticks| { + let block = b.block(state); + b.update_neighbors_at(level, ticks, p, block); + b.update_neighbors_at(level, ticks, p.offset(0, -1, 0), block); + }); + } + } + /// `BarrelBlockEntity.openersCounter`: the first opener opens the barrel + /// (`open=true`), the last one to leave closes it (`updateBlockState`). + fn barrel_openers_changed(&mut self, key: (i32, i32, i32), open: bool) { + let (before, count) = self.count_opener(key, open); + if (before == 0) != (count == 0) { + self.set_bool_prop( + key, + "open", + count > 0, + horizon_world::level::flags::UPDATE_ALL, + ); + } + } + /// One opener more (`open`) or less at `key`: the count before and after + /// (`ContainerOpenersCounter.incrementOpeners` / `decrementOpeners`). + fn count_opener(&mut self, key: (i32, i32, i32), open: bool) -> (i32, i32) { + let count = self.lid_openers.entry(key).or_default(); + let before = *count; + *count = (before + if open { 1 } else { -1 }).max(0); + let after = *count; + if after == 0 { + self.lid_openers.remove(&key); + } + (before, after) } /// `BellBlockEntity.updateEntities`: the living entities whose bounding /// box meets the bell's block box inflated by 48. diff --git a/crates/horizon-client/src/game/machines/crafter.rs b/crates/horizon-client/src/game/machines/crafter.rs index 0fe66f7c8..dd6d5cedc 100644 --- a/crates/horizon-client/src/game/machines/crafter.rs +++ b/crates/horizon-client/src/game/machines/crafter.rs @@ -33,7 +33,7 @@ fn recipe_matches(condition: &Value, id: &str) -> bool { impl Game<'_> { /// `Level.setBlock` of one boolean property of the block at `pos`. - fn set_bool_prop(&mut self, pos: Pos, key: &str, value: bool, flags: i32) { + pub(crate) fn set_bool_prop(&mut self, pos: Pos, key: &str, value: bool, flags: i32) { let registry = self.pack.assets.registry; let old = self.world.block(pos.0, pos.1, pos.2); let Some(mut state) = registry.state(old).cloned() else {