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.
This commit is contained in:
@@ -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<String, Arc<MobType>>, 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"));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user