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.
This commit is contained in:
@@ -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<String>,
|
||||
@@ -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,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<MobEvent>) {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user