Let mobs trample farmland when they land on it

A cow dropped onto farmland left it untouched. A landing mob now turns
farmland to dirt with chance fall distance - 0.5, when mob griefing is on and
the mob is big enough, and is lifted onto the dirt.
This commit is contained in:
Kacpherek
2026-10-26 18:46:37 +01:00
parent 2ca383f36d
commit c1844dfe57
+25
View File
@@ -440,11 +440,36 @@ impl Mob {
}
if self.on_ground {
if self.fall_distance > 0.0 {
self.trample_farmland(w, events);
self.cause_fall_damage(events);
}
self.fall_distance = 0.0;
}
}
/// `FarmlandBlock.fallOn`: a landing on farmland turns it to dirt with
/// chance `fallDistance - 0.5`, if mobs may grief and the mob's
/// `width * width * height` is over 0.512. `Block.pushEntitiesUp` lifts
/// the mob onto the dirt, which is a full block.
fn trample_farmland(&mut self, w: &MobWorld, events: &mut Vec<MobEvent>) {
let p = self.block_on_legacy(w);
if w.block_name(p[0], p[1], p[2]) != "minecraft:farmland" {
return;
}
let roll = f64::from(self.random.next_float());
let Some(dirt) = w.registry.default_state("minecraft:dirt") else {
return;
};
if roll < self.fall_distance - 0.5
&& w.mob_griefing
&& self.width() * self.width() * self.height() > 0.512
{
events.push(MobEvent::SetBlock {
pos: p,
state: dirt,
});
self.position.y = self.position.y.max(f64::from(p[1]) + 1.0);
}
}
/// Entity.updateFluidInteraction: the fluid state, then touching water
/// resets the fall and entering it (after the first tick) splashes.
pub(super) fn update_fluids(&mut self, w: &MobWorld, events: &mut Vec<MobEvent>) {