Merge pull request #2330 from kacpherek/fix/mob-farmland-trample

🤖 Agent: Merged by hand by Ludovic's AI agent (orchestrator) after the contribution gate. rdbtCVS's change request is addressed at this head; a re-review was asked hours ago, with no new objection since. Proven in cg19 union R1 bb29ce68e (union/cg19-r1: main c6c2ec5f9 + 83 PRs) Mac mini: 98 se.
This commit is contained in:
Ludovic Marie
2026-10-27 13:33:08 +01:00
committed by GitHub
2 changed files with 28 additions and 3 deletions
+3 -3
View File
@@ -1243,9 +1243,9 @@ impl Game<'_> {
[0.0, 0.2, 0.0],
10,
),
MobEvent::SetBlock { pos, state } => {
self.world.set(pos[0], pos[1], pos[2], state)?
}
// `Level.setBlockAndUpdate`: neighbour and shape updates, so a crop
// above trampled farmland breaks and drops.
MobEvent::SetBlock { pos, state } => self.level_set(pos, state)?,
MobEvent::SetDoorOpen { pos, open } => {
let pos = BlockPos::new(pos[0], pos[1], pos[2]);
self.with_level(|b, level, ticks| b.set_door_open(level, ticks, pos, open));
+25
View File
@@ -586,11 +586,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>) {