diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index 7f3565067..6c7fd1d5a 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -246,6 +246,14 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag { map.entry("sound_variant".into()) .or_insert_with(|| string("minecraft:classic")); } + "minecraft:parrot" => { + if let Some(owner) = m.extra.owner { + map.insert("Owner".into(), Tag::IntArray(owner.to_vec())); + } else { + map.remove(&"Owner".into()); + } + map.insert("Sitting".into(), Tag::Byte(i8::from(m.extra.sitting))); + } "minecraft:wolf" => { if let Some(owner) = m.extra.owner { map.insert("Owner".into(), Tag::IntArray(owner.to_vec())); @@ -773,6 +781,11 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - .unwrap_or(0) as u8; } } + if m.species() == crate::mobs::Species::Parrot { + m.extra.owner = crate::save::uuid_from_tag(tag.get("Owner")); + m.extra.tame = m.extra.owner.is_some(); + m.extra.sitting = flag(tag, "Sitting"); + } if m.species() == crate::mobs::Species::Wolf { let health = m.health; m.extra.owner = crate::save::uuid_from_tag(tag.get("Owner")); diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index d192a2b02..8eb4cc911 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -2559,6 +2559,12 @@ impl Game<'_> { .items() .get(&item) .is_some_and(|i| i.max_damage > 0); + let parrot_poisonous = self + .res + .items() + .item_tags + .get("minecraft:parrot_poisonous_food") + .is_some_and(|t| t.contains(&*item)); let m = &mut self.mobs[index]; if !m.alive() { return Ok(false); @@ -2764,6 +2770,15 @@ impl Game<'_> { m.position.z.floor() as i32 >> 4, )); } + // Parrot.mobInteract: the owner makes a tame parrot on the ground + // sit or stand (poisonous food is handled apart). + Species::Parrot if m.extra.tame && m.on_ground && !parrot_poisonous => { + m.extra.sitting = !m.extra.sitting; + self.world.modified.insert(( + m.position.x.floor() as i32 >> 4, + m.position.z.floor() as i32 >> 4, + )); + } Species::Cat if !m.extra.tame && is_food => { consume = true; m.persistent = true; diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 5292cd31b..72345970b 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -231,6 +231,13 @@ fn mob_meta( } defaults.push((18, serializer::BYTE, Value::Byte(0))); } + "minecraft:parrot" => { + // TamableAnimal.DATA_FLAGS_ID: sitting 1, tame 4. + let flags = i8::from(e.sitting) | if e.tame { 4 } else { 0 }; + if flags != 0 { + meta.push((18, serializer::BYTE, Value::Byte(flags))); + } + } "minecraft:cat" | "minecraft:wolf" => { // TamableAnimal.DATA_FLAGS_ID: sitting 1, tame 4. let flags = i8::from(e.sitting) | if e.tame { 4 } else { 0 }; diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index 2676c3a37..d30cc56ad 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -178,6 +178,7 @@ pub fn register(m: &mut Mob) { Family::Undead => undead::register(m), Family::Hostile => hostile::register(m), Family::Aquatic => aquatic::register(m), + Family::Generic if m.species() == Species::Parrot => super::tame::register_parrot(m), Family::Generic => { generic(m); if m.species() == Species::Rabbit { diff --git a/crates/horizon-client/src/mobs/tame.rs b/crates/horizon-client/src/mobs/tame.rs index 1e725df80..0043ff9ef 100644 --- a/crates/horizon-client/src/mobs/tame.rs +++ b/crates/horizon-client/src/mobs/tame.rs @@ -100,6 +100,17 @@ pub fn register(m: &mut Mob) { ), ); } +/// `Parrot.registerGoals`: a tamed parrot sits when told to and follows its +/// owner from five blocks away (the wander and the shoulder come as they are). +pub fn register_parrot(m: &mut Mob) { + let g = &mut m.ai.goals; + g.add(0, TamePanic(Panic::new(1.25))); + g.add(0, Float); + g.add(1, LookAtPlayer::new(8.0)); + g.add(2, SitWhenOrdered); + g.add(2, FollowOwner::new(1.0, 5.0, 1.0)); + g.add(2, Stroll::avoiding_water(1.0)); +} /// `Wolf.PREY_SELECTOR`: sheep, rabbits and foxes. fn wolf_prey(s: &super::Seen) -> bool { matches!(s.species, Species::Sheep | Species::Rabbit | Species::Fox)