From 77fe538e09b0b8677634083d6fdca88d9f543b45 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 21:48:05 +0100 Subject: [PATCH] Let only the owner command a tame wolf or cat, and make pets follow their owner Sitting, standing, dyeing and healing a cat or wolf now check the saved owner. The follow, teleport and owner-hurt goals use the owner, not the nearest player, and a new tame wolf or cat is owned by whoever tamed it. --- crates/horizon-client/src/game/creatures.rs | 22 ++++++++++++++----- crates/horizon-client/src/game/lan_mobs.rs | 15 ++++++++++++- crates/horizon-client/src/mobs/tame.rs | 24 +++++++++++++-------- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index f6961ab13..68964a3fd 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -2739,6 +2739,7 @@ impl Game<'_> { .items() .get(&item) .is_some_and(|i| i.max_damage > 0); + let acting = self.acting_uuid(); let m = &mut self.mobs[index]; if !m.alive() { return Ok(false); @@ -2833,6 +2834,7 @@ impl Game<'_> { } Species::Wolf if m.extra.tame + && m.extra.owner == Some(acting) && item.ends_with("_dye") && horizon_client::mobs::render::DYE_NAMES .iter() @@ -2855,7 +2857,9 @@ impl Game<'_> { consume = true; } Species::Wolf - if m.extra.tame && !(is_food && m.extra.age == 0 && m.extra.in_love <= 0) => + if m.extra.tame + && m.extra.owner == Some(acting) + && !(is_food && m.extra.age == 0 && m.extra.in_love <= 0) => { m.extra.sitting = !m.extra.sitting; m.ai.jumping = false; @@ -2875,7 +2879,7 @@ impl Game<'_> { let tamed = m.random.next_int_bound(3).unwrap_or(1) == 0; if tamed { horizon_client::mobs::tame::set_tame(m, true); - m.extra.owner = self.level.player_uuid.or(Some([0, 0, 0, 1])); + m.extra.owner = Some(acting); m.persistent = true; m.nav_stop(); m.ai.target = None; @@ -2902,6 +2906,7 @@ impl Game<'_> { // Cat.mobInteract: dye, heal or sit when tame; fish may tame a wild one. Species::Cat if m.extra.tame + && m.extra.owner == Some(acting) && item.ends_with("_dye") && horizon_client::mobs::render::DYE_NAMES .iter() @@ -2924,7 +2929,12 @@ impl Game<'_> { m.persistent = true; consume = true; } - Species::Cat if m.extra.tame && is_food && m.health < m.attrs.max_health => { + Species::Cat + if m.extra.tame + && m.extra.owner == Some(acting) + && is_food + && m.health < m.attrs.max_health => + { let heal = self .res .items() @@ -2937,7 +2947,9 @@ impl Game<'_> { eat = eating_sound(m, &mut self.world.random); } Species::Cat - if m.extra.tame && !(is_food && m.extra.age == 0 && m.extra.in_love <= 0) => + if m.extra.tame + && m.extra.owner == Some(acting) + && !(is_food && m.extra.age == 0 && m.extra.in_love <= 0) => { m.extra.sitting = !m.extra.sitting; self.world.modified.insert(( @@ -2951,7 +2963,7 @@ impl Game<'_> { let tamed = m.random.next_int_bound(3).unwrap_or(1) == 0; if tamed { m.extra.tame = true; - m.extra.owner = self.level.player_uuid.or(Some([0, 0, 0, 1])); + m.extra.owner = Some(acting); m.extra.sitting = true; } eat = eating_sound(m, &mut self.world.random); diff --git a/crates/horizon-client/src/game/lan_mobs.rs b/crates/horizon-client/src/game/lan_mobs.rs index 6527f1015..f0e7cb4f9 100644 --- a/crates/horizon-client/src/game/lan_mobs.rs +++ b/crates/horizon-client/src/game/lan_mobs.rs @@ -5,7 +5,7 @@ //! (hits, pushes, fire, its projectiles) runs with that guest swapped in. use super::{Game, lan::LanHost}; use horizon_client::{ - mobs::{Mob, MobEvent, PlayerView, Who}, + mobs::{Mob, MobEvent, PlayerView, Species, Who}, projectiles::{Hit, Projectile}, }; use horizon_core::geometry::{Aabb, Vec3}; @@ -26,6 +26,19 @@ pub(super) fn player_for( guests: &GuestViews, bound: Option, ) -> Option { + // A tame wolf or cat sees its owner (`TamableAnimal.getOwner`), while they + // are in play, whoever is nearer. + if matches!(m.species(), Species::Wolf | Species::Cat) + && m.extra.tame + && let Some(owner) = m.extra.owner + { + if host.is_some_and(|v| v.alive && v.uuid == owner) { + return None; + } + if let Some((conn, _)) = guests.iter().find(|(_, v)| v.alive && v.uuid == owner) { + return Some(*conn); + } + } let targeting = m.ai.target == Some(Who::Player) || m.ai.last_hurt_by == Some(Who::Player) && m.age as i32 - m.ai.last_hurt_by_time <= 100; choose(m.position, targeting, host, guests, bound) diff --git a/crates/horizon-client/src/mobs/tame.rs b/crates/horizon-client/src/mobs/tame.rs index 1e725df80..85d8a3cd0 100644 --- a/crates/horizon-client/src/mobs/tame.rs +++ b/crates/horizon-client/src/mobs/tame.rs @@ -2,7 +2,7 @@ //! sitting, following and defending the owner, begging, anger and shaking //! off water (`Wolf`, `WolfModel`). use super::{ - Damage, Mob, MobEvent, MobWorld, Species, Who, + Damage, Mob, MobEvent, MobWorld, PlayerView, Species, Who, anim::{Poses, State}, goals::{ Breed, Cx, Float, Goal, HurtByTarget, JUMP, LOOK, LeapAtTarget, LookAtPlayer, MOVE, @@ -124,17 +124,23 @@ pub fn set_tame(m: &mut Mob, tame: bool) { m.attrs.max_health = 8.0; } } -/// The owner (the local player) when tame. -fn owner(m: &Mob, w: &MobWorld) -> Option<(Vec3, f64, bool)> { +/// `TamableAnimal.getOwner`: the player the saved owner UUID names, when it +/// is the one this mob sees; anyone else nearby is not its owner. +fn owner_view<'a>(m: &Mob, w: &'a MobWorld) -> Option<&'a PlayerView> { if !m.extra.tame { return None; } let p = w.player.as_ref()?; + (m.extra.owner == Some(p.uuid)).then_some(p) +} +/// The owner's position, eye height and spectator flag when tame. +fn owner(m: &Mob, w: &MobWorld) -> Option<(Vec3, f64, bool)> { + let p = owner_view(m, w)?; Some((p.position, p.eye[1], p.spectator)) } /// `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) + m.extra.sitting || owner_view(m, w).is_some_and(|p| p.spectator) } /// `TamableAnimal.tryToTeleportToOwner`: ten tries around the owner. fn teleport_to_owner(m: &mut Mob, w: &MobWorld) { @@ -240,7 +246,7 @@ impl Goal for SitWhenOrdered { match owner_distance_sqr(m, cx.w) { None => true, Some(d) => { - let attacked = cx.w.player.as_ref().is_some_and(|p| p.hurt_by.is_some()); + let attacked = owner_view(m, cx.w).is_some_and(|p| p.hurt_by.is_some()); !(d < 144.0 && attacked) && m.extra.sitting } } @@ -388,7 +394,7 @@ impl Goal for OwnerHurtBy { if !m.extra.tame || m.extra.sitting { return false; } - let Some((who, at)) = cx.w.player.as_ref().and_then(|p| p.hurt_by) else { + let Some((who, at)) = owner_view(m, cx.w).and_then(|p| p.hurt_by) else { return false; }; at != self.timestamp && wants_to_attack(m, cx.w, who) @@ -399,7 +405,7 @@ impl Goal for OwnerHurtBy { .is_some_and(|t| t.alive) } fn start(&mut self, m: &mut Mob, cx: &mut Cx) { - if let Some((who, at)) = cx.w.player.as_ref().and_then(|p| p.hurt_by) { + if let Some((who, at)) = owner_view(m, cx.w).and_then(|p| p.hurt_by) { m.ai.target = Some(who); self.timestamp = at; } @@ -422,7 +428,7 @@ impl Goal for OwnerHurt { if !m.extra.tame || m.extra.sitting { return false; } - let Some((who, at)) = cx.w.player.as_ref().and_then(|p| p.last_hurt) else { + let Some((who, at)) = owner_view(m, cx.w).and_then(|p| p.last_hurt) else { return false; }; at != self.timestamp && wants_to_attack(m, cx.w, who) @@ -433,7 +439,7 @@ impl Goal for OwnerHurt { .is_some_and(|t| t.alive) } fn start(&mut self, m: &mut Mob, cx: &mut Cx) { - if let Some((who, at)) = cx.w.player.as_ref().and_then(|p| p.last_hurt) { + if let Some((who, at)) = owner_view(m, cx.w).and_then(|p| p.last_hurt) { m.ai.target = Some(who); self.timestamp = at; }