From 1654cb51db5df2bd2263e8b77abdf851d0b158eb Mon Sep 17 00:00:00 2001 From: levzzz <86072227+levzzz5154@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:24:09 +0500 Subject: [PATCH 1/2] The spawn egg's offspring is a named, tested rule The behaviour is in main (#2275): `Mob.checkAndHandleImportantInteractions` uses a spawn egg of the mob's own kind on a mob, and `SpawnEggItem.spawnOffspringFromSpawnEgg` spawns the offspring as a baby of that kind at the parent's position, and one egg less in hand. The rule now lives in the library, where it is named and tested: `spawn_egg_is_for` (the egg is for the mob's own kind) and `spawn_egg_offspring` (the baby, with the parent's variant and colour). Fixes #2269 Co-Authored-By: minimax-m3.1-flash (Claude Code) --- crates/horizon-client/src/game/creatures.rs | 8 +--- crates/horizon-client/src/mobs/finalize.rs | 49 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 927aa8c29..a327096f0 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -3604,7 +3604,7 @@ impl Game<'_> { }; let parent = &self.mobs[index]; if !parent.alive() - || stack.item.strip_suffix("_spawn_egg") != Some(parent.kind.id.as_str()) + || !horizon_client::mobs::finalize::spawn_egg_is_for(&stack.item, &parent.kind.id) || !horizon_client::mobs::drops::can_be_baby(parent.species()) // WanderingTrader.getBreedOffspring returns null: no offspring, the // click carries on to trading. @@ -3623,11 +3623,7 @@ impl Game<'_> { return false; }; if let Some(child) = self.mobs.iter_mut().find(|m| m.id == id) { - horizon_client::mobs::finalize::set_baby(child, true); - child.extra.variant = variant; - if species == Species::Sheep { - child.extra.color = color; - } + horizon_client::mobs::finalize::spawn_egg_offspring(child, species, variant, color); } self.trigger_item_entity("minecraft:player_interacted_with_entity", &stack, &target); self.consume_held(); diff --git a/crates/horizon-client/src/mobs/finalize.rs b/crates/horizon-client/src/mobs/finalize.rs index ccf4564ca..6be8f1fdc 100644 --- a/crates/horizon-client/src/mobs/finalize.rs +++ b/crates/horizon-client/src/mobs/finalize.rs @@ -817,6 +817,22 @@ fn age_boundary_reached(m: &mut Mob) { } } /// `setBaby`: AgeableMob through its age, zombies, piglins and zoglins. +/// `SpawnEggItem.spawnsEntity`: the spawn egg is for the mob's own kind, so +/// it is used on it (`Mob.checkAndHandleImportantInteractions`). +pub fn spawn_egg_is_for(egg: &str, kind: &str) -> bool { + egg.strip_suffix("_spawn_egg") == Some(kind) +} + +/// `SpawnEggItem.spawnOffspringFromSpawnEgg`: the offspring of a spawn egg +/// used on a mob of the same kind is a baby of that kind: it starts with +/// the age of a baby and keeps the parent's variant and colour. +pub fn spawn_egg_offspring(child: &mut Mob, species: Species, variant: u8, color: u8) { + set_baby(child, true); + child.extra.variant = variant; + if species == Species::Sheep { + child.extra.color = color; + } +} pub fn set_baby(m: &mut Mob, baby: bool) { let s = m.species(); if ageable(s) { @@ -2077,6 +2093,39 @@ mod tests { assert_eq!(panda_variant(4, 4), 4); assert_eq!(panda_variant(6, 0), 6); } + /// #2269: the offspring of a spawn egg used on a mob is a baby of that + /// kind (`SpawnEggItem.spawnOffspringFromSpawnEgg`), and only the mob's + /// own kind takes the egg. + #[test] + fn a_spawn_egg_offspring_is_a_baby() { + let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); + if !root.join("items.json").exists() { + return; + } + let data = crate::mobs::MobTypes::load(&root).unwrap(); + let kind = std::sync::Arc::new(data.types.get("minecraft:cow").unwrap().clone()); + let mut child = crate::mobs::Mob::new( + 2, + kind, + horizon_core::geometry::Vec3::new(0.0, 4.0, 0.0), + 0.0, + ); + assert!(!child.is_baby()); + spawn_egg_offspring(&mut child, Species::Cow, 3, 0); + // The offspring is a baby of the mob's kind. + assert!(child.is_baby()); + // It keeps the parent's variant. + assert_eq!(child.extra.variant, 3); + // The egg is for the mob's own kind. + assert!(spawn_egg_is_for("minecraft:cow_spawn_egg", "minecraft:cow")); + assert!(!spawn_egg_is_for( + "minecraft:pig_spawn_egg", + "minecraft:cow" + )); + assert!(!spawn_egg_is_for("minecraft:stick", "minecraft:cow")); + } #[test] fn reasons_round_trip() { for r in Reason::ALL { From 70068076f23c214f438174c8de337a5570c925ee Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:24:39 +0100 Subject: [PATCH 2/2] Keep set_baby's doc comment on set_baby The two new functions went in between it and its comment. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/mobs/finalize.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/horizon-client/src/mobs/finalize.rs b/crates/horizon-client/src/mobs/finalize.rs index 6be8f1fdc..d698a3683 100644 --- a/crates/horizon-client/src/mobs/finalize.rs +++ b/crates/horizon-client/src/mobs/finalize.rs @@ -816,7 +816,6 @@ fn age_boundary_reached(m: &mut Mob) { _ => {} } } -/// `setBaby`: AgeableMob through its age, zombies, piglins and zoglins. /// `SpawnEggItem.spawnsEntity`: the spawn egg is for the mob's own kind, so /// it is used on it (`Mob.checkAndHandleImportantInteractions`). pub fn spawn_egg_is_for(egg: &str, kind: &str) -> bool { @@ -833,6 +832,7 @@ pub fn spawn_egg_offspring(child: &mut Mob, species: Species, variant: u8, color child.extra.color = color; } } +/// `setBaby`: AgeableMob through its age, zombies, piglins and zoglins. pub fn set_baby(m: &mut Mob, baby: bool) { let s = m.species(); if ageable(s) {