diff --git a/crates/horizon-client/src/game/commands/world_cmds.rs b/crates/horizon-client/src/game/commands/world_cmds.rs index 39587fa00..9cd376194 100644 --- a/crates/horizon-client/src/game/commands/world_cmds.rs +++ b/crates/horizon-client/src/game/commands/world_cmds.rs @@ -118,7 +118,8 @@ impl Game<'_> { "dry_out" => DamageKind::DryOut, "magic" | "indirect_magic" | "dragon_breath" => DamageKind::Magic, "sting" => DamageKind::Sting, - "cactus" | "sweet_berry_bush" => DamageKind::Cactus, + "cactus" => DamageKind::Cactus, + "sweet_berry_bush" => DamageKind::SweetBerryBush, "freeze" => DamageKind::Freeze, "in_wall" => DamageKind::InWall, "thorns" => DamageKind::Thorns, diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 6384a3051..7a0a0ea07 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -4229,6 +4229,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 cd8962754..045e7327e 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -530,6 +530,8 @@ pub enum DamageKind { Magic, Sting, Cactus, + /// `sweet_berry_bush`. + SweetBerryBush, Generic, InWall, Thorns, @@ -592,6 +594,7 @@ impl Damage { | DamageKind::DryOut | DamageKind::Generic | DamageKind::InWall + | DamageKind::SweetBerryBush ) } /// DamageTypeTags.BYPASSES_ARMOR @@ -628,6 +631,7 @@ impl Damage { | DamageKind::DryOut | DamageKind::Magic | DamageKind::Cactus + | DamageKind::SweetBerryBush | DamageKind::Generic | DamageKind::InWall | DamageKind::Freeze @@ -862,6 +866,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, /// `Entity.pistonDeltas` and `pistonDeltasGameTime`: how far a moving /// block has pushed this mob this tick (0.51 at most on any axis). pub piston: horizon_world::piston_movement::PistonMovement, @@ -1794,6 +1800,7 @@ impl Mob { // Mob.ambientSoundTime starts at 0. ambient_timer: 0, fall_distance: 0.0, + stuck_multiplier: Vec3::ZERO, piston: Default::default(), persistent: false, random, @@ -1866,13 +1873,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 e1627e29f..1dbf4d03d 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -445,6 +445,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); } @@ -480,6 +481,59 @@ 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 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(); + 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 { + 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::SweetBerryBush)); + } + } + _ => 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 612ab0dbb..4c5866857 100644 --- a/crates/horizon-client/src/mobs/living.rs +++ b/crates/horizon-client/src/mobs/living.rs @@ -505,7 +505,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, diff --git a/crates/horizon-client/src/mobs/sulfur_cube.rs b/crates/horizon-client/src/mobs/sulfur_cube.rs index 9a71e9682..901d04bf7 100644 --- a/crates/horizon-client/src/mobs/sulfur_cube.rs +++ b/crates/horizon-client/src/mobs/sulfur_cube.rs @@ -378,6 +378,7 @@ pub fn accepts_damage(m: &mut Mob, source: &Damage, amount: f32) -> bool { | DamageKind::Sting | DamageKind::Cactus | DamageKind::Freeze + | DamageKind::SweetBerryBush ); if immune { if let Some(from) = source.from {