Make a tame parrot answer only to its owner
This commit is contained in:
@@ -2565,6 +2565,7 @@ impl Game<'_> {
|
||||
.item_tags
|
||||
.get("minecraft:parrot_poisonous_food")
|
||||
.is_some_and(|t| t.contains(&*item));
|
||||
let acting = self.acting_uuid();
|
||||
let m = &mut self.mobs[index];
|
||||
if !m.alive() {
|
||||
return Ok(false);
|
||||
@@ -2772,7 +2773,12 @@ impl Game<'_> {
|
||||
}
|
||||
// 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 => {
|
||||
Species::Parrot
|
||||
if m.extra.tame
|
||||
&& m.extra.owner == Some(acting)
|
||||
&& m.on_ground
|
||||
&& !parrot_poisonous =>
|
||||
{
|
||||
m.extra.sitting = !m.extra.sitting;
|
||||
self.world.modified.insert((
|
||||
m.position.x.floor() as i32 >> 4,
|
||||
@@ -2841,7 +2847,7 @@ impl Game<'_> {
|
||||
let tamed = m.random.next_int_bound(10).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);
|
||||
}
|
||||
let kind = if tamed { "heart" } else { "smoke" };
|
||||
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
|
||||
|
||||
@@ -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<u32>,
|
||||
) -> Option<u32> {
|
||||
// A tame parrot sees its owner (`TamableAnimal.getOwner`), while they
|
||||
// are in play, whoever is nearer.
|
||||
if m.species() == Species::Parrot
|
||||
&& 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)
|
||||
|
||||
@@ -135,12 +135,16 @@ pub fn set_tame(m: &mut Mob, tame: bool) {
|
||||
m.attrs.max_health = 8.0;
|
||||
}
|
||||
}
|
||||
/// The owner (the local player) when tame.
|
||||
/// The owner (the local player) when tame. A parrot's owner is the player
|
||||
/// its saved UUID names (`TamableAnimal.getOwner`), not whoever is nearest.
|
||||
fn owner(m: &Mob, w: &MobWorld) -> Option<(Vec3, f64, bool)> {
|
||||
if !m.extra.tame {
|
||||
return None;
|
||||
}
|
||||
let p = w.player.as_ref()?;
|
||||
if m.species() == Species::Parrot && m.extra.owner != Some(p.uuid) {
|
||||
return None;
|
||||
}
|
||||
Some((p.position, p.eye[1], p.spectator))
|
||||
}
|
||||
/// `TamableAnimal.unableToMoveToOwner`.
|
||||
|
||||
Reference in New Issue
Block a user