Break turtle eggs by stepping on them

TurtleEggBlock.stepOn calls destroyEgg(100) for any step that is not careful; only the fall path (1 in 3) existed.
This commit is contained in:
Kacpherek
2026-10-27 22:33:01 +01:00
parent 1ab273641e
commit 0d3ca74bd0
2 changed files with 75 additions and 35 deletions
+13
View File
@@ -1257,6 +1257,19 @@ impl MotionWorld<'_, '_, '_> {
if magma && !self.player.shift_key_down {
self.environment_hurt("minecraft:hot_floor", 1.0)?;
}
// TurtleEggBlock.stepOn: a step that is not careful may break an egg.
if !self.player.shift_key_down {
let state = self.block(on);
self.resources
.landing
.step_on(
self,
state,
on,
horizon_world::block_landing::LandingEntityKind::Player,
)
.map_err(|e| e.to_string())?;
}
// SlimeBlock.stepOn: a slow walk on slime drags the horizontal
// speed (the client moves its own player, so not the server's copy).
if slime && !damage_only && !self.player.shift_key_down {
+62 -35
View File
@@ -266,6 +266,66 @@ impl BlockLandingRegistry {
}
Ok(())
}
/// `TurtleEggBlock.stepOn`: a step that is not careful breaks an egg one
/// time in 100.
pub fn step_on<W: BlockLandingWorld>(
&self,
world: &mut W,
state: BlockStateId,
position: BlockPos,
entity: LandingEntityKind,
) -> Result<(), LandingError<W::Error>> {
if let Rule::TurtleEgg { remaining } = self.state(state)?.rule {
self.destroy_egg(world, remaining, state, position, entity, 100)?;
}
Ok(())
}
/// `TurtleEggBlock.destroyEgg`: one egg breaks with chance 1 in `randomness`.
fn destroy_egg<W: BlockLandingWorld>(
&self,
world: &mut W,
remaining: Option<BlockStateId>,
state: BlockStateId,
position: BlockPos,
entity: LandingEntityKind,
randomness: i32,
) -> Result<(), LandingError<W::Error>> {
if !world.is_server_level()
|| matches!(entity, LandingEntityKind::Turtle | LandingEntityKind::Bat)
{
return Ok(());
}
let allowed = if entity == LandingEntityKind::Player {
!world
.under_spawn_protection(position)
.map_err(LandingError::World)?
} else {
entity.living() && world.mob_griefing().map_err(LandingError::World)?
};
if allowed && world.random_int(randomness).map_err(LandingError::World)? == 0 {
let sound = world.known_sound(LandingSound::TurtleEggBreak);
let pitch = 0.9f32 + world.random_float().map_err(LandingError::World)? * 0.2f32;
world
.block_sound(position, sound, 0.7, pitch)
.map_err(LandingError::World)?;
if let Some(next) = remaining {
world
.set_block(position, next, 2)
.map_err(LandingError::World)?;
world
.block_event(LandingEvent::BlockDestroy, position, state, false)
.map_err(LandingError::World)?;
world
.level_event(2001, position, state.0 as i32)
.map_err(LandingError::World)?;
} else {
world
.destroy_block(position, false)
.map_err(LandingError::World)?;
}
}
Ok(())
}
pub fn fall_on<W: BlockLandingWorld>(
&self,
world: &mut W,
@@ -373,41 +433,8 @@ impl BlockLandingRegistry {
}
}
Rule::TurtleEgg { remaining } => {
if !matches!(
entity,
LandingEntityKind::Zombie | LandingEntityKind::Turtle | LandingEntityKind::Bat
) && world.is_server_level()
{
let allowed = if entity == LandingEntityKind::Player {
!world
.under_spawn_protection(position)
.map_err(LandingError::World)?
} else {
entity.living() && world.mob_griefing().map_err(LandingError::World)?
};
if allowed && world.random_int(3).map_err(LandingError::World)? == 0 {
let sound = world.known_sound(LandingSound::TurtleEggBreak);
let pitch =
0.9f32 + world.random_float().map_err(LandingError::World)? * 0.2f32;
world
.block_sound(position, sound, 0.7, pitch)
.map_err(LandingError::World)?;
if let Some(next) = remaining {
world
.set_block(position, next, 2)
.map_err(LandingError::World)?;
world
.block_event(LandingEvent::BlockDestroy, position, state, false)
.map_err(LandingError::World)?;
world
.level_event(2001, position, state.0 as i32)
.map_err(LandingError::World)?;
} else {
world
.destroy_block(position, false)
.map_err(LandingError::World)?;
}
}
if entity != LandingEntityKind::Zombie {
self.destroy_egg(world, remaining, state, position, entity, 3)?;
}
}
}