From b283f2ad314243210014263184ebf826eca53f68 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 18:45:44 +0100 Subject: [PATCH 1/2] Hurt mobs that touch a cactus or a sweet berry bush Mobs ignored both blocks. A mob inside a cactus now takes 1 damage a tick, and a mob inside a sweet berry bush is slowed (0.8, 0.75, 0.8) and, in a grown bush, takes 1 damage when it moved at least 0.003 on X or Z. Foxes and bees are left alone. --- crates/horizon-client/src/mobs.rs | 15 ++++++-- crates/horizon-client/src/mobs/ai.rs | 48 ++++++++++++++++++++++++ crates/horizon-client/src/mobs/living.rs | 9 ++++- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 00c21633e..0edcd3620 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -815,6 +815,8 @@ pub struct Mob { pub previous_swell: i32, pub ambient_timer: i32, pub fall_distance: f64, + /// `Entity.stuckSpeedMultiplier`: the next move is scaled by it. + pub stuck_multiplier: Vec3, pub persistent: bool, /// `CustomName` (plain text) and `CustomNameVisible`. pub custom_name: Option, @@ -1569,6 +1571,7 @@ impl Mob { // Mob.ambientSoundTime starts at 0. ambient_timer: 0, fall_distance: 0.0, + stuck_multiplier: Vec3::ZERO, persistent: false, random, ai: Box::default(), @@ -1640,13 +1643,17 @@ impl Mob { } } pub fn bounds(&self) -> Aabb { + self.bounds_at(self.position) + } + /// `Entity.makeBoundingBox(position)`. + pub fn bounds_at(&self, position: Vec3) -> Aabb { let w = f64::from(self.width()) / 2.0; Aabb::new( - Vec3::new(self.position.x - w, self.position.y, self.position.z - w), + Vec3::new(position.x - w, position.y, position.z - w), Vec3::new( - self.position.x + w, - self.position.y + f64::from(self.height()), - self.position.z + w, + position.x + w, + position.y + f64::from(self.height()), + position.z + w, ), ) } diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index 2676c3a37..ffc74d0b9 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -400,6 +400,7 @@ pub fn tick( if !m.no_ai { ai_step(m, w, level_random, events); } + effects_from_blocks(m, w); if m.species() == Species::Rabbit { super::rabbit::post_tick(m); } @@ -428,6 +429,53 @@ pub fn tick( } true } +/// `LivingEntity.aiStep` -> `Entity.applyEffectsFromBlocks` for the blocks +/// that hurt or hold a mob: the cactus (`CactusBlock.entityInside`, 1) and the +/// sweet berry bush (`SweetBerryBushBlock.entityInside`: stuck at 0.8, 0.75, +/// 0.8, and a grown bush pricks for 1 when the mob moved at least 0.003 on X +/// or Z this tick). The blocks are those the mob's box touches where it +/// started the tick and where it ended. +fn effects_from_blocks(m: &mut Mob, w: &MobWorld) { + let mut visited: Vec<[i32; 3]> = Vec::new(); + for at in [m.previous, m.position] { + if !m.alive() { + return; + } + let b = m.bounds_at(at).deflate(Vec3::new(1e-5, 1e-5, 1e-5)); + for x in b.min_position().x.floor() as i32..=b.max_position().x.floor() as i32 { + for y in b.min_position().y.floor() as i32..=b.max_position().y.floor() as i32 { + for z in b.min_position().z.floor() as i32..=b.max_position().z.floor() as i32 { + let p = [x, y, z]; + if visited.contains(&p) { + continue; + } + match w.block_name(x, y, z) { + "minecraft:cactus" => { + m.damage(1.0, Damage::of(DamageKind::Cactus)); + } + "minecraft:sweet_berry_bush" + if !matches!(m.species(), Species::Fox | Species::Bee) => + { + m.fall_distance = 0.0; + m.stuck_multiplier = + Vec3::new(f64::from(0.8_f32), 0.75, f64::from(0.8_f32)); + let moved = m.previous.subtract(m.position); + if w.prop(x, y, z, "age") != Some("0") + && moved.horizontal_distance_squared() > 0.0 + && (moved.x.abs() >= f64::from(0.003_f32) + || moved.z.abs() >= f64::from(0.003_f32)) + { + m.damage(1.0, Damage::of(DamageKind::Cactus)); + } + } + _ => continue, + } + visited.push(p); + } + } + } + } +} /// LivingEntity.updateSwingTime (6-tick swing duration). pub fn tick_swing(m: &mut Mob) { if m.ai.swinging { diff --git a/crates/horizon-client/src/mobs/living.rs b/crates/horizon-client/src/mobs/living.rs index 394821ace..7dfbf7017 100644 --- a/crates/horizon-client/src/mobs/living.rs +++ b/crates/horizon-client/src/mobs/living.rs @@ -370,7 +370,14 @@ impl Mob { /// Entity.move with block collisions and step-up; updates collision flags /// and fall distance (Entity.checkFallDamage). pub fn do_move(&mut self, w: &MobWorld, events: &mut Vec) { - let wanted = self.velocity; + let mut wanted = self.velocity; + // Entity.move: a block the mob is stuck in (sweet berry bush) scales + // this move once and stops it. + if self.stuck_multiplier.length_squared() > 1.0e-7 { + wanted = wanted.multiply(self.stuck_multiplier); + self.stuck_multiplier = Vec3::ZERO; + self.velocity = Vec3::ZERO; + } let step = self.kind.step_height as f32; let mut scene = SceneCollisions { world: w.world, From e9797d69d0ea0b5ee0b75c68a9b483cdbf13f364 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 21:51:25 +0100 Subject: [PATCH 2/2] Use the berry damage type for sweet berry bushes and check the whole move for contact --- .../horizon-client/src/game/commands/world_cmds.rs | 3 ++- crates/horizon-client/src/game/creatures.rs | 1 + crates/horizon-client/src/mobs.rs | 9 ++++++++- crates/horizon-client/src/mobs/ai.rs | 14 ++++++++++---- crates/horizon-client/src/mobs/sulfur_cube.rs | 1 + 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/crates/horizon-client/src/game/commands/world_cmds.rs b/crates/horizon-client/src/game/commands/world_cmds.rs index 687eb3f88..859d86397 100644 --- a/crates/horizon-client/src/game/commands/world_cmds.rs +++ b/crates/horizon-client/src/game/commands/world_cmds.rs @@ -117,7 +117,8 @@ impl Game<'_> { "drown" => DamageKind::Drown, "magic" | "indirect_magic" | "dragon_breath" => DamageKind::Magic, "sting" => DamageKind::Sting, - "cactus" | "sweet_berry_bush" => DamageKind::Cactus, + "cactus" => DamageKind::Cactus, + "sweet_berry_bush" => DamageKind::SweetBerryBush, "in_wall" => DamageKind::InWall, "thorns" => DamageKind::Thorns, _ => DamageKind::Generic, diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 2b65a3289..04228a722 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -3283,6 +3283,7 @@ pub(super) fn damage_type(kind: horizon_client::mobs::DamageKind, player: bool) K::Magic => "minecraft:magic", K::Sting => "minecraft:sting", K::Cactus => "minecraft:cactus", + K::SweetBerryBush => "minecraft:sweet_berry_bush", K::Generic => "minecraft:generic", K::InWall => "minecraft:in_wall", K::Thorns => "minecraft:thorns", diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 0edcd3620..4498e9b75 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -518,6 +518,8 @@ pub enum DamageKind { Magic, Sting, Cactus, + /// `sweet_berry_bush`. + SweetBerryBush, Generic, InWall, Thorns, @@ -573,7 +575,11 @@ impl Damage { pub fn causes_panic(&self) -> bool { !matches!( self.kind, - DamageKind::Fall | DamageKind::Drown | DamageKind::Generic | DamageKind::InWall + DamageKind::Fall + | DamageKind::Drown + | DamageKind::Generic + | DamageKind::InWall + | DamageKind::SweetBerryBush ) } /// DamageTypeTags.BYPASSES_ARMOR @@ -608,6 +614,7 @@ impl Damage { | DamageKind::Drown | DamageKind::Magic | DamageKind::Cactus + | DamageKind::SweetBerryBush | DamageKind::Generic | DamageKind::InWall | DamageKind::OutOfWorld diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index ffc74d0b9..458ccd097 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -433,14 +433,20 @@ pub fn tick( /// that hurt or hold a mob: the cactus (`CactusBlock.entityInside`, 1) and the /// sweet berry bush (`SweetBerryBushBlock.entityInside`: stuck at 0.8, 0.75, /// 0.8, and a grown bush pricks for 1 when the mob moved at least 0.003 on X -/// or Z this tick). The blocks are those the mob's box touches where it -/// started the tick and where it ended. +/// or Z this tick). The blocks are those the mob's box touches anywhere along +/// its move this tick, from where it started to where it ended. fn effects_from_blocks(m: &mut Mob, w: &MobWorld) { let mut visited: Vec<[i32; 3]> = Vec::new(); - for at in [m.previous, m.position] { + let travel = m.position.subtract(m.previous); + let longest = travel.x.abs().max(travel.y.abs()).max(travel.z.abs()); + let steps = ((longest / 0.2).ceil() as i32).clamp(1, 100); + for step in 0..=steps { if !m.alive() { return; } + let at = m + .previous + .add_vector(travel.scale(f64::from(step) / f64::from(steps))); let b = m.bounds_at(at).deflate(Vec3::new(1e-5, 1e-5, 1e-5)); for x in b.min_position().x.floor() as i32..=b.max_position().x.floor() as i32 { for y in b.min_position().y.floor() as i32..=b.max_position().y.floor() as i32 { @@ -465,7 +471,7 @@ fn effects_from_blocks(m: &mut Mob, w: &MobWorld) { && (moved.x.abs() >= f64::from(0.003_f32) || moved.z.abs() >= f64::from(0.003_f32)) { - m.damage(1.0, Damage::of(DamageKind::Cactus)); + m.damage(1.0, Damage::of(DamageKind::SweetBerryBush)); } } _ => continue, diff --git a/crates/horizon-client/src/mobs/sulfur_cube.rs b/crates/horizon-client/src/mobs/sulfur_cube.rs index 00b846b86..5a5c2f48a 100644 --- a/crates/horizon-client/src/mobs/sulfur_cube.rs +++ b/crates/horizon-client/src/mobs/sulfur_cube.rs @@ -297,6 +297,7 @@ pub fn accepts_damage(m: &mut Mob, source: &Damage, amount: f32) -> bool { | DamageKind::Fall | DamageKind::Sting | DamageKind::Cactus + | DamageKind::SweetBerryBush ); if immune { if let Some(from) = source.from {