From b5a735c8d176f0ea15535c450bf4d548c1d69ffe Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:33:51 +0100 Subject: [PATCH 1/3] Let tame parrots follow their owner and sit when told to A tamed parrot ignored its owner: it never followed, and right-clicking it did nothing. Give the parrot the goals of Parrot.registerGoals (SitWhenOrderedToGoal, FollowOwnerGoal 1.0, 5.0, 1.0), let the owner toggle sitting with a click while it stands on the ground, and keep the owner and sitting state in the save file and in the data a guest gets. --- crates/horizon-client/src/entity_nbt.rs | 13 +++++++++++++ crates/horizon-client/src/game/creatures.rs | 15 +++++++++++++++ crates/horizon-client/src/game/lan.rs | 7 +++++++ crates/horizon-client/src/mobs/ai.rs | 1 + crates/horizon-client/src/mobs/tame.rs | 11 +++++++++++ 5 files changed, 47 insertions(+) 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) From 9ca7162169b8db523223534eaa4874ea937e1be8 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:39:14 +0100 Subject: [PATCH 2/3] Let a tame parrot sit on its owner's shoulder A tame parrot never landed on its owner. Add LandOnOwnersShoulderGoal: when the parrot touches its owner, it is stored in the player's ShoulderEntityLeft or ShoulderEntityRight and removed from the world. It comes back, still tame, when the player falls, swims, flies, sleeps, is hurt, dies, turns spectator or spins with a riptide. The shoulder data is the player's own save data, so it also works for players on the integrated server and for LAN guests. --- crates/horizon-client/src/game.rs | 2 + crates/horizon-client/src/game/creatures.rs | 3 + crates/horizon-client/src/game/lan_actions.rs | 4 + crates/horizon-client/src/game/lan_mobs.rs | 1 + crates/horizon-client/src/game/shoulders.rs | 120 ++++++++++++++++++ crates/horizon-client/src/mobs.rs | 5 + crates/horizon-client/src/mobs/tame.rs | 29 +++++ 7 files changed, 164 insertions(+) create mode 100644 crates/horizon-client/src/game/shoulders.rs diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 58b89a140..2acbfb4f9 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -156,6 +156,7 @@ mod server_packs; mod server_travel; mod shader_packs; mod shield; +mod shoulders; mod sign_edit; mod sniffers; mod spawner; @@ -4574,6 +4575,7 @@ impl Game<'_> { } self.powder_snow_fire()?; self.tick_totem(); + self.handle_shoulder_entities(); let Some(player) = self.player.as_mut() else { return Ok(()); }; diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 8eb4cc911..1a04ef0eb 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -49,6 +49,8 @@ pub(super) struct Creatures { pub elder_apparition: i32, /// The wandering trader spawner's clock. pub trader: super::wandering_trader::Spawner, + /// When each player last put a parrot on a shoulder (`timeEntitySatOnShoulder`). + pub shoulder_time: std::collections::HashMap<[i32; 4], i64>, } pub(super) struct ProjWorld<'a, 'w> { pub w: &'a MobWorld<'w>, @@ -992,6 +994,7 @@ impl Game<'_> { } MobEvent::BecomeStatue { mob } => self.golem_become_statue(mob), MobEvent::EnterHive { mob, hive } => self.bee_enter_hive(mob, hive), + MobEvent::ParrotToShoulder { mob } => self.parrot_to_shoulder(mob), MobEvent::Gift { target, item } => { if let Some(m) = self.mobs.iter_mut().find(|m| m.id == target) && m.saddle_item().is_none() diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 43bb573dc..6e7f63f9c 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -378,6 +378,7 @@ impl Game<'_> { std::mem::swap(&mut self.adv.changed, &mut g.advancements_changed); std::mem::swap(&mut self.adv.unlocked, &mut g.recipes_unlocked); std::mem::swap(&mut self.level.recipe_book, &mut g.recipe_book); + std::mem::swap(&mut self.level.player_extra, &mut g.saved); std::mem::swap(&mut self.stats, &mut play.stats); std::mem::swap(&mut self.hook, &mut play.hook); let adv_loaded = std::mem::replace(&mut self.adv.loaded, true); @@ -610,6 +611,7 @@ impl Game<'_> { std::mem::swap(&mut self.adv.changed, &mut g.advancements_changed); std::mem::swap(&mut self.adv.unlocked, &mut g.recipes_unlocked); std::mem::swap(&mut self.level.recipe_book, &mut g.recipe_book); + std::mem::swap(&mut self.level.player_extra, &mut g.saved); std::mem::swap(&mut self.stats, &mut play.stats); std::mem::swap(&mut self.hook, &mut play.hook); self.adv.loaded = adv_loaded; @@ -2178,6 +2180,7 @@ impl Game<'_> { if !g.effects.list.is_empty() { self.as_guest(host, conn, |game| game.tick_mob_effects()); } + self.as_guest(host, conn, |game| game.handle_shoulder_entities()); return; } let in_wall = !g.sleeping && self.in_wall(g.position, g.eye_height()); @@ -2279,6 +2282,7 @@ impl Game<'_> { // LivingEntity.baseTick: outside the world border, then tickEffects. game.border_damage(); game.tick_mob_effects(); + game.handle_shoulder_entities(); let Some(player) = game.player.as_mut() else { return (Vec::new(), None); }; diff --git a/crates/horizon-client/src/game/lan_mobs.rs b/crates/horizon-client/src/game/lan_mobs.rs index 4f53cec60..4555474a5 100644 --- a/crates/horizon-client/src/game/lan_mobs.rs +++ b/crates/horizon-client/src/game/lan_mobs.rs @@ -80,6 +80,7 @@ pub(super) fn acts_on_player(e: &MobEvent) -> bool { } | MobEvent::EffectPlayer { .. } | MobEvent::AxolotlSupportPlayer + | MobEvent::ParrotToShoulder { .. } ) } diff --git a/crates/horizon-client/src/game/shoulders.rs b/crates/horizon-client/src/game/shoulders.rs new file mode 100644 index 000000000..602c5a5af --- /dev/null +++ b/crates/horizon-client/src/game/shoulders.rs @@ -0,0 +1,120 @@ +//! Parrots on a player's shoulder: a tame parrot lands on its owner +//! (`LandOnOwnersShoulderGoal`), is kept as the player's `ShoulderEntityLeft` +//! or `ShoulderEntityRight`, and flies off again when the player is hurt, +//! falls, swims, flies or sleeps (`ServerPlayer.handleShoulderEntities`). +use super::Game; +use horizon_client::mobs::Species; +use horizon_world::nbt::Tag; + +const KEYS: [&str; 2] = ["ShoulderEntityLeft", "ShoulderEntityRight"]; + +/// A shoulder slot holds a parrot when its compound is not empty. +fn occupied(extra: &Tag, key: &str) -> bool { + matches!(extra.get(key), Some(Tag::Compound(c)) if !c.is_empty()) +} + +impl Game<'_> { + /// `ServerPlayer.setEntityOnShoulder` for a parrot that touched its + /// owner: stored in the first free slot, the parrot gone from the world. + pub(super) fn parrot_to_shoulder(&mut self, mob: u32) { + let Some(i) = self + .mobs + .iter() + .position(|m| m.id == mob && m.alive() && !m.removed && m.species() == Species::Parrot) + else { + return; + }; + let Some(p) = self.player.as_ref() else { + return; + }; + if self.riding.is_some() + || !p.ground.on_ground + || p.fluids.was_touching_water + || p.in_powder_snow + || p.flying + { + return; + } + let extra = self + .level + .player_extra + .get_or_insert_with(|| Tag::Compound(Default::default())); + let Some(key) = KEYS.into_iter().find(|k| !occupied(extra, k)) else { + return; + }; + let tag = self.mob_tree_nbt(i); + if let Some(Tag::Compound(map)) = self.level.player_extra.as_mut() { + map.insert(key.into(), tag); + } + let (uuid, now) = (self.acting_uuid(), self.world.game_time); + self.creatures.shoulder_time.insert(uuid, now); + self.mobs[i].removed = true; + } + + /// `ServerPlayer.handleShoulderEntities`: the parrots leave the shoulder + /// of a player who falls, swims, flies, sleeps, is hurt, dying, a + /// spectator or spinning with a riptide. + pub(super) fn handle_shoulder_entities(&mut self) { + let Some(p) = self.player.as_ref() else { + return; + }; + let any = self + .level + .player_extra + .as_ref() + .is_some_and(|e| KEYS.iter().any(|k| occupied(e, k))); + if any + && (p.fall_distance > 0.5 + || p.fluids.was_touching_water + || p.flying + || p.spectator + || p.in_powder_snow + || p.auto_spin_attack_ticks > 0 + || p.health.hurt.hurt_time > 0 + || p.health.dead_or_dying() + || self.sleeping.is_some()) + { + self.remove_entities_on_shoulder(); + } + } + + /// `ServerPlayer.removeEntitiesOnShoulder` (not within a second of the + /// landing) and `respawnEntityOnShoulder`: the parrots come back at the + /// player, still owned by them. + fn remove_entities_on_shoulder(&mut self) { + let (uuid, now) = (self.acting_uuid(), self.world.game_time); + if self + .creatures + .shoulder_time + .get(&uuid) + .is_some_and(|t| t + 20 >= now) + { + return; + } + let Some(p) = self.player.as_ref().map(|p| p.position) else { + return; + }; + let Some(Tag::Compound(map)) = self.level.player_extra.as_mut() else { + return; + }; + let tags: Vec = KEYS + .iter() + .filter_map(|k| map.remove(&(*k).into())) + .collect(); + let pos = [p.x, p.y + f64::from(0.7_f32), p.z]; + for mut tag in tags { + let Tag::Compound(c) = &mut tag else { + continue; + }; + if c.is_empty() { + continue; + } + c.insert( + "Pos".into(), + Tag::List(pos.iter().map(|v| Tag::Double(v.to_bits())).collect()), + ); + c.insert("Owner".into(), Tag::IntArray(uuid.to_vec())); + self.load_mob(tag, None); + } + } +} diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 4b67f738f..b7e38bb01 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -894,6 +894,11 @@ pub enum MobEvent { mob: u32, hive: [i32; 3], }, + /// `LandOnOwnersShoulderGoal`: a tame parrot touched its owner and sits + /// on their shoulder (the host stores its tag and discards it). + ParrotToShoulder { + mob: u32, + }, /// `CopperGolem.turnToStatue`. BecomeStatue { mob: u32, diff --git a/crates/horizon-client/src/mobs/tame.rs b/crates/horizon-client/src/mobs/tame.rs index 0043ff9ef..82d808b7f 100644 --- a/crates/horizon-client/src/mobs/tame.rs +++ b/crates/horizon-client/src/mobs/tame.rs @@ -110,6 +110,35 @@ pub fn register_parrot(m: &mut Mob) { g.add(2, SitWhenOrdered); g.add(2, FollowOwner::new(1.0, 5.0, 1.0)); g.add(2, Stroll::avoiding_water(1.0)); + g.add(3, LandOnOwnersShoulder); +} +/// `LandOnOwnersShoulderGoal`: a standing parrot, 100 ticks old, lands on +/// the shoulder of the owner it touches; the host does the landing. +#[derive(Clone, Debug)] +struct LandOnOwnersShoulder; +impl Goal for LandOnOwnersShoulder { + goal_clone!(); + fn flags(&self) -> u8 { + 0 + } + fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + // ShoulderRidingEntity.canSitOnShoulder: rideCooldownCounter > 100. + owner(m, cx.w).is_some_and(|(_, _, spectator)| !spectator) + && !m.extra.sitting + && m.age > 100 + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + if !m.extra.sitting + && m.extra.leash.is_none() + && cx + .w + .player + .as_ref() + .is_some_and(|p| m.bounds().intersects(p.bounds)) + { + cx.events.push(MobEvent::ParrotToShoulder { mob: m.id }); + } + } } /// `Wolf.PREY_SELECTOR`: sheep, rabbits and foxes. fn wolf_prey(s: &super::Seen) -> bool { From be714b38bbc3e27aa2d5aa1b3f0244b490c7d16b Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 21:38:16 +0100 Subject: [PATCH 3/3] Only let a tame parrot land on its saved owner --- crates/horizon-client/src/game/shoulders.rs | 4 ++++ crates/horizon-client/src/mobs/tame.rs | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/game/shoulders.rs b/crates/horizon-client/src/game/shoulders.rs index 602c5a5af..7dfc2f355 100644 --- a/crates/horizon-client/src/game/shoulders.rs +++ b/crates/horizon-client/src/game/shoulders.rs @@ -27,6 +27,10 @@ impl Game<'_> { let Some(p) = self.player.as_ref() else { return; }; + // The acting player must be the saved owner (`getOwner`). + if !horizon_client::mobs::tame::owned_by(self.mobs[i].extra.owner, self.acting_uuid()) { + return; + } if self.riding.is_some() || !p.ground.on_ground || p.fluids.was_touching_water diff --git a/crates/horizon-client/src/mobs/tame.rs b/crates/horizon-client/src/mobs/tame.rs index 82d808b7f..3002ce1f7 100644 --- a/crates/horizon-client/src/mobs/tame.rs +++ b/crates/horizon-client/src/mobs/tame.rs @@ -123,13 +123,15 @@ impl Goal for LandOnOwnersShoulder { } fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { // ShoulderRidingEntity.canSitOnShoulder: rideCooldownCounter > 100. - owner(m, cx.w).is_some_and(|(_, _, spectator)| !spectator) + is_owner(m, cx.w) + && owner(m, cx.w).is_some_and(|(_, _, spectator)| !spectator) && !m.extra.sitting && m.age > 100 } fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { if !m.extra.sitting && m.extra.leash.is_none() + && is_owner(m, cx.w) && cx .w .player @@ -172,6 +174,18 @@ fn owner(m: &Mob, w: &MobWorld) -> Option<(Vec3, f64, bool)> { let p = w.player.as_ref()?; Some((p.position, p.eye[1], p.spectator)) } +/// Whether the player the mob sees is the one saved as its owner (with +/// guests on, that player is whoever stands nearest). +fn is_owner(m: &Mob, w: &MobWorld) -> bool { + w.player + .as_ref() + .is_some_and(|p| owned_by(m.extra.owner, p.uuid)) +} +/// Whether `uuid` is the saved owner. A host with no UUID yet owns what it +/// tamed under the placeholder `[0, 0, 0, 1]`. +pub fn owned_by(owner: Option<[i32; 4]>, uuid: [i32; 4]) -> bool { + owner.is_some_and(|o| o == uuid || (o == [0, 0, 0, 1] && uuid == [0; 4])) +} /// `TamableAnimal.unableToMoveToOwner`. fn unable_to_move_to_owner(m: &Mob, w: &MobWorld) -> bool { m.extra.sitting || w.player.as_ref().is_some_and(|p| p.spectator)