From 608a6d9bee44680bb640777663d2c3258e5590b4 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 15:50:47 +0100 Subject: [PATCH] Turtles: a fixed home from spawn or load, one breeding orb Turtle.finalizeSpawn sets homePos to where it spawns, and loading falls back to the block it stands on; the home no longer moves with a turtle that had none, which let it lay eggs anywhere. TurtleBreedGoal.breed adds one ExperienceOrb of 1 to 7 drawn from the mother's random. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/entity_nbt.rs | 12 ++++++++---- crates/horizon-client/src/game/creatures.rs | 10 +++++++--- crates/horizon-client/src/mobs/spawning.rs | 8 ++++++++ crates/horizon-client/src/mobs/turtle.rs | 4 ++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index f7c843264..73bc580bc 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -856,10 +856,14 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - if m.species() == crate::mobs::Species::Turtle { // Turtle.readAdditionalSaveData: `home_pos` (else where it stands) and `has_egg`. m.extra.flag = flag(tag, "has_egg"); - m.extra.home = match tag.get("home_pos") { - Some(Tag::IntArray(home)) if home.len() == 3 => Some([home[0], home[1], home[2]]), - _ => None, - }; + m.extra.home = Some(match tag.get("home_pos") { + Some(Tag::IntArray(home)) if home.len() == 3 => [home[0], home[1], home[2]], + _ => [ + m.position.x.floor() as i32, + m.position.y.floor() as i32, + m.position.z.floor() as i32, + ], + }); } if m.species() == crate::mobs::Species::Wither { m.extra.counter = number(tag.get("Invul")).unwrap_or(0) as i32; diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 03911ffda..d9764288b 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -1360,9 +1360,13 @@ impl Game<'_> { // TurtleBreedGoal.breed: the goal gave the mother her egg; only the // experience is left, and only with mob loot on. if p.species() == Species::Turtle { - if self.ui.rules.bool("mob_drops") { - let xp = 1 + self.world.random.next_int_bound(7).unwrap_or(0) as u32; - self.spawn_orbs([p.position.x, p.position.y, p.position.z], xp); + // One `new ExperienceOrb` of 1 to 7 from the mother's random (not + // split up as `ExperienceOrb.award` does). + if self.ui.rules.bool("mob_drops") + && let Some(m) = self.mobs.iter_mut().find(|m| m.id == parent) + { + let xp = 1 + m.random.next_int_bound(7).unwrap_or(0) as u32; + self.add_orb([p.position.x, p.position.y, p.position.z], xp); } return; } diff --git a/crates/horizon-client/src/mobs/spawning.rs b/crates/horizon-client/src/mobs/spawning.rs index 93e3fe119..d58fa35c3 100644 --- a/crates/horizon-client/src/mobs/spawning.rs +++ b/crates/horizon-client/src/mobs/spawning.rs @@ -148,6 +148,14 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts, difficulty: &LocalDifficulty) { S::Pig | S::Cow | S::Chicken => m.extra.variant = climate_index, S::Sheep => m.extra.color = super::farm::sheep_color(biome.climate, &mut m.random), S::Mooshroom => m.extra.variant = 0, + // Turtle.finalizeSpawn: home is where it spawned. + S::Turtle => { + m.extra.home = Some([ + m.position.x.floor() as i32, + m.position.y.floor() as i32, + m.position.z.floor() as i32, + ]) + } S::Frog => m.extra.variant = biome.frog, S::Wolf => m.extra.variant = biome.wolf, S::Cat => m.extra.variant = super::tame::cat_variant(m, biome.full_moon), diff --git a/crates/horizon-client/src/mobs/turtle.rs b/crates/horizon-client/src/mobs/turtle.rs index 0596adfdf..98dd5b558 100644 --- a/crates/horizon-client/src/mobs/turtle.rs +++ b/crates/horizon-client/src/mobs/turtle.rs @@ -23,8 +23,8 @@ fn set_laying_egg(m: &mut Mob, on: bool) { m.extra.counter = i32::from(on); m.extra.flag2 = on; } -/// `homePos.closerToCenterThan(position, distance)`; a turtle that never -/// had a home is at home where it stands. +/// `homePos.closerToCenterThan(position, distance)`. Spawning, hatching and +/// loading all set a home; one made any other way is at home where it stands. fn close_to_home(m: &Mob, distance: f64) -> bool { let home = m.extra.home.unwrap_or([ m.position.x.floor() as i32,