From b0527b4818290a3fb20c02b943bc86d37317fd1b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:32:58 +0200 Subject: [PATCH] Check a shulker box's lid room before opening and tick animations only while the world runs ShulkerBoxBlock.canOpen: a closed box opens only when the half-open lid box is free of collisions. Bells gather and test entities by their real bounding boxes and liveness. Client block-entity tickers run with ClientLevel.tickBlockEntities, which Minecraft.tick skips while paused. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 7 +- .../src/game/block_entity_anims.rs | 72 ++++++++++++------- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index f482568e6..c805d8cc7 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1610,6 +1610,8 @@ impl Game<'_> { self.world.block_entities.entry(key).or_insert_with(|| { BlockEntity::for_block(&name).unwrap_or(BlockEntity::Chest(Vec::new())) }); + } else if storage::is_shulker_box(&name) && !self.shulker_can_open(pos) { + // ShulkerBoxBlock.canOpen: the lid has no room; nothing opens. } else if let Some(entity) = BlockEntity::for_block(&name) { self.world.block_entities.entry(key).or_insert(entity); self.container = Some(key); @@ -2745,9 +2747,10 @@ impl Game<'_> { self.tick_sculk()?; self.tick_brewing_stands()?; } - // ClientLevel.tickBlockEntities: chest lids, books, shulker boxes, bells... - self.tick_block_entity_anims(); if running { + // ClientLevel.tickBlockEntities (not while paused or frozen): + // chest lids, books, shulker boxes, bells, conduits, heads. + self.tick_block_entity_anims(); self.tick_particles(); } if self.right && self.use_delay == 0 && self.screen == Screen::Playing { diff --git a/crates/horizon-client/src/game/block_entity_anims.rs b/crates/horizon-client/src/game/block_entity_anims.rs index 349e4724d..d1597a7a3 100644 --- a/crates/horizon-client/src/game/block_entity_anims.rs +++ b/crates/horizon-client/src/game/block_entity_anims.rs @@ -5,10 +5,12 @@ //! [`Game::block_anim`] and [`Game::chest_lid`]. use super::Game; use horizon_client::{ - block_entity_anim::{BellEntity, Ticker}, + block_entity_anim::{BellEntity, Shulker, ShulkerStatus, Ticker}, block_entity_render::BlockAnim, + collisions::{SceneCollisions, no_collision_empty}, particles::{ParticleOptions, ParticleType}, }; +use horizon_core::geometry::{Aabb, Vec3}; use std::collections::HashMap; /// The handle of the local player among a bell's gathered entities. @@ -86,37 +88,57 @@ impl Game<'_> { /// `BellBlockEntity.updateEntities`: the living entities whose bounding /// box meets the bell's block box inflated by 48. fn bell_gather(&self, pos: [i32; 3]) -> Vec { - let lo = [ - f64::from(pos[0]) - 48.0, - f64::from(pos[1]) - 48.0, - f64::from(pos[2]) - 48.0, - ]; - let hi = [ - lo[0] + 49.0 + 48.0, - lo[1] + 49.0 + 48.0, - lo[2] + 49.0 + 48.0, - ]; - let meets = |p: [f64; 3], width: f64, height: f64| { - let (bl, bh) = ( - [p[0] - width / 2.0, p[1], p[2] - width / 2.0], - [p[0] + width / 2.0, p[1] + height, p[2] + width / 2.0], - ); - (0..3).all(|a| bl[a] < hi[a] && bh[a] > lo[a]) - }; + let area = Aabb::new( + Vec3::new( + f64::from(pos[0]) - 48.0, + f64::from(pos[1]) - 48.0, + f64::from(pos[2]) - 48.0, + ), + Vec3::new( + f64::from(pos[0]) + 49.0, + f64::from(pos[1]) + 49.0, + f64::from(pos[2]) + 49.0, + ), + ); let mut out = Vec::new(); - if let Some(p) = &self.player - && meets([p.position.x, p.position.y, p.position.z], 0.6, 1.8) + if self + .player_view() + .is_some_and(|p| p.bounds.intersects(area)) { out.push(PLAYER); } for m in &self.mobs { - let p = [m.position.x, m.position.y, m.position.z]; - if meets(p, m.kind.width, m.kind.height) { + if !m.removed && m.bounds().intersects(area) { out.push(u64::from(m.id)); } } out } + /// `ShulkerBoxBlock.canOpen`: a closed box opens only when its lid has + /// room to rise (`level.noCollision` of the half-open lid box). + pub(super) fn shulker_can_open(&self, pos: [i32; 3]) -> bool { + let state = self.world.block(pos[0], pos[1], pos[2]).0; + let Some(Ticker::Shulker { facing }) = self.be_anims.ticker(state) else { + return true; + }; + let closed = self + .be_anims + .shulkers + .get(&pos) + .is_none_or(|s| s.status == ShulkerStatus::Closed); + if !closed { + return true; + } + let b = Shulker::lid_box(pos, facing); + let mut scene = SceneCollisions { + world: &self.world, + binding: self.collision, + }; + no_collision_empty( + &mut scene, + Aabb::new(Vec3::new(b[0], b[1], b[2]), Vec3::new(b[3], b[4], b[5])), + ) + } /// The client tickers of the loaded animated block entities, once per /// client tick (`ClientLevel.tickBlockEntities`). pub(super) fn tick_block_entity_anims(&mut self) { @@ -173,9 +195,9 @@ impl Game<'_> { self.be_anims.skulls.entry(pos).or_default().tick(powered); } Ticker::Bell => { - let player = self.player.as_ref().map(|p| BellEntity { + let player = self.player_view().map(|p| BellEntity { position: [p.position.x, p.position.y, p.position.z], - alive: true, + alive: p.alive, raider: false, }); let mobs = &self.mobs; @@ -186,7 +208,7 @@ impl Game<'_> { let m = mobs.iter().find(|m| u64::from(m.id) == h)?; Some(BellEntity { position: [m.position.x, m.position.y, m.position.z], - alive: m.health > 0.0, + alive: m.alive() && !m.removed, raider: raiders.contains(&m.kind.id), }) };