From de0f76476f1ee603c7d86d167b669d9680acfdb7 Mon Sep 17 00:00:00 2001 From: vlesmentie <129341611+vlesmentie@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:10:26 -0300 Subject: [PATCH] Big dripleaves tilt under a player standing on them The leaf's tilt ticks, its reset and its redstone reset were already in horizon-world (big_dripleaf_tick, big_dripleaf_reset_tilt), but nothing started them: BigDripleafBlock.entityInside was missing. An entity on the ground whose feet are above the leaf's y + 0.6875 (canEntityTilt) tilts a flat, unpowered leaf UNSTABLE and schedules its tick in 10. The block tick's inside scan now also passes the host's and the LAN guests' feet and on-ground flag to Behaviours::entity_on_big_dripleaf. Fixes #1683. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 31 ++++++++++++++++ crates/horizon-client/src/game/lan_mobs.rs | 13 +++++++ crates/horizon-world/src/level/hooks.rs | 23 ++++++++++++ crates/horizon-world/src/level/mod.rs | 13 +++++++ crates/horizon-world/src/level/tests.rs | 41 ++++++++++++++++++++++ 5 files changed, 121 insertions(+) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index f05ee41e4..9edb3c17d 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -2575,10 +2575,41 @@ impl Game<'_> { } } } + // BigDripleafBlock.entityInside also asks whether the player stands on + // the ground and how high its feet are: the leaves its box's feet + // layer is inside (the host and the LAN guests). + let mut standing = Vec::new(); + let feet = self + .player + .iter() + .filter(|_| !self.spectator()) + .map(|p| { + ( + [p.position.x, p.position.y, p.position.z], + p.ground.on_ground, + f64::from(p.dimensions.width) / 2.0, + ) + }) + .chain( + self.lan_guest_feet() + .into_iter() + .map(|(at, on_ground)| (at, on_ground, 0.3)), + ); + for (at, on_ground, w) in feet { + let y = (at[1] + 1e-7).floor() as i32; + for x in (at[0] - w + 1e-7).floor() as i32..=(at[0] + w - 1e-7).floor() as i32 { + for z in (at[2] - w + 1e-7).floor() as i32..=(at[2] + w - 1e-7).floor() as i32 { + standing.push((BlockPos::new(x, y, z), on_ground, at[1])); + } + } + } self.with_level(|b, level, ticks| { for pos in inside { b.entity_inside(level, ticks, pos); } + for (pos, on_ground, feet_y) in standing { + b.entity_on_big_dripleaf(level, ticks, pos, on_ground, feet_y); + } }); self.process_level_events()?; self.tick_scheduled()?; diff --git a/crates/horizon-client/src/game/lan_mobs.rs b/crates/horizon-client/src/game/lan_mobs.rs index be277b6e0..dc4d1eb42 100644 --- a/crates/horizon-client/src/game/lan_mobs.rs +++ b/crates/horizon-client/src/game/lan_mobs.rs @@ -171,6 +171,19 @@ impl Game<'_> { }) .collect() } + /// The same guests' feet and whether they stand on the ground, for the + /// blocks that also ask that (`BigDripleafBlock.canEntityTilt`). + pub(super) fn lan_guest_feet(&self) -> Vec<([f64; 3], bool)> { + let Some(host) = self.lan.as_ref() else { + return Vec::new(); + }; + host.hub + .guests + .iter() + .filter(|g| host.hub.here(g) && g.loaded && !g.dead && !g.spectator()) + .map(|g| (g.position, g.on_ground)) + .collect() + } /// The guests a projectile can hit, under their entity ids. pub(super) fn lan_projectile_targets(&self) -> Vec<(Who, Aabb)> { diff --git a/crates/horizon-world/src/level/hooks.rs b/crates/horizon-world/src/level/hooks.rs index 0695a92b3..7f9e8d19a 100644 --- a/crates/horizon-world/src/level/hooks.rs +++ b/crates/horizon-world/src/level/hooks.rs @@ -573,6 +573,29 @@ impl Sim<'_, L> { self.game_event_state(pos, "minecraft:block_destroy", state); } } + /// `BigDripleafBlock.entityInside` on a server level: an entity standing on + /// a flat leaf (`canEntityTilt`: on the ground, its feet above the leaf's + /// lowest top, 11/16, less 4/16: 0.6875) tilts it UNSTABLE unless the leaf + /// is powered; `setTiltAndScheduleTick` with no sound (UNSTABLE causes no + /// vibration) and the next state in 10 ticks. + pub(crate) fn big_dripleaf_entity_inside( + &mut self, + pos: BlockPos, + on_ground: bool, + feet_y: f64, + ) { + let b = self.b; + let state = self.state(pos); + if !b.data(state).is(Class::BigDripleaf) + || b.table.text(state, b.props.tilt) != "none" + || !(on_ground && feet_y > f64::from(pos.y) + f64::from(0.6875_f32)) + || self.has_neighbor_signal(pos) + { + return; + } + self.set_block(pos, b.table.set_text(state, b.props.tilt, "unstable"), 2); + self.schedule_tick(pos, b.block(state), 10); + } /// `BigDripleafBlock.resetTilt`. pub(crate) fn big_dripleaf_reset_tilt(&mut self, pos: BlockPos, state: BlockStateId) { let b = self.b; diff --git a/crates/horizon-world/src/level/mod.rs b/crates/horizon-world/src/level/mod.rs index 696777386..3831efbd6 100644 --- a/crates/horizon-world/src/level/mod.rs +++ b/crates/horizon-world/src/level/mod.rs @@ -749,6 +749,19 @@ impl Behaviours { ) { self.sim(level, ticks).entity_inside(pos); } + /// `BigDripleafBlock.entityInside` for an entity whose box is inside + /// `pos`: whether it is on the ground and its feet's y (`canEntityTilt`). + pub fn entity_on_big_dripleaf( + &self, + level: &mut L, + ticks: &mut Ticks, + pos: BlockPos, + on_ground: bool, + feet_y: f64, + ) { + self.sim(level, ticks) + .big_dripleaf_entity_inside(pos, on_ground, feet_y); + } /// Redstone signal queries (`SignalGetter`). pub fn has_neighbor_signal( &self, diff --git a/crates/horizon-world/src/level/tests.rs b/crates/horizon-world/src/level/tests.rs index 1a1b9ebae..8a4b6c34f 100644 --- a/crates/horizon-world/src/level/tests.rs +++ b/crates/horizon-world/src/level/tests.rs @@ -1283,3 +1283,44 @@ fn player_breaks_fire_with_extinguish_not_generic_break_event() { assert_eq!(w.get(pos), w.b().air()); } } + +#[test] +fn big_dripleaf_tilts_under_an_entity_standing_on_it() { + let mut w = world!(); + w.floor(0, 2, "clay"); + let pos = BlockPos::new(0, 1, 0); + let leaf = w.id("big_dripleaf", &[("facing", "north")]); + w.put(pos, leaf); + let stand = |w: &mut World, on_ground: bool, feet: f64| { + w.f.behaviours + .entity_on_big_dripleaf(&mut w.level, &mut w.ticks, pos, on_ground, feet); + }; + // canEntityTilt: in the air, or with its feet at or under 0.6875, nothing. + stand(&mut w, false, 1.9375); + stand(&mut w, true, 1.6875); + assert_eq!(w.prop(pos, "tilt"), "none"); + // Standing on the leaf's top (15/16): UNSTABLE, then PARTIAL and FULL + // 10 ticks apart, and back to NONE 100 ticks later. + stand(&mut w, true, 1.9375); + assert_eq!(w.prop(pos, "tilt"), "unstable"); + for _ in 0..10 { + w.tick(); + } + assert_eq!(w.prop(pos, "tilt"), "partial"); + for _ in 0..10 { + w.tick(); + } + assert_eq!(w.prop(pos, "tilt"), "full"); + // A tilted leaf doesn't restart under the entity. + stand(&mut w, true, 1.9375); + assert_eq!(w.prop(pos, "tilt"), "full"); + for _ in 0..100 { + w.tick(); + } + assert_eq!(w.prop(pos, "tilt"), "none"); + // A powered leaf doesn't tilt. + let power = w.id("redstone_block", &[]); + w.put(BlockPos::new(1, 1, 0), power); + stand(&mut w, true, 1.9375); + assert_eq!(w.prop(pos, "tilt"), "none"); +}