Merge pull request #2791 from levzzz5154/fix/spawn-egg-baby
🤖 Agent: read the diff at 70068076f: spawn-egg offspring rule split into `spawn_egg_is_for` / `spawn_egg_offspring` (`SpawnEggItem.spawnOffspringFromSpawnEgg`), behaviour unchanged, with a test. verify green, parity green on this head (merged into main), merges cleanly.
This commit is contained in:
@@ -4201,7 +4201,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.
|
||||
@@ -4220,11 +4220,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();
|
||||
|
||||
@@ -821,6 +821,22 @@ fn age_boundary_reached(m: &mut Mob) {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// `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;
|
||||
}
|
||||
}
|
||||
/// `setBaby`: AgeableMob through its age, zombies, piglins and zoglins.
|
||||
pub fn set_baby(m: &mut Mob, baby: bool) {
|
||||
let s = m.species();
|
||||
@@ -2138,6 +2154,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 {
|
||||
|
||||
Reference in New Issue
Block a user