Let parrots imitate nearby mobs and dance to a jukebox

Parrots only ever made their own sound. Follow Parrot.aiStep: one tick in
400 a parrot imitates a random mob within 20 blocks (half the time), and
its ambient sound is sometimes a mob's voice. A parrot within 3.46 blocks
of a playing jukebox now uses the party pose (level events 1010 and 1011).
This commit is contained in:
Kacpherek
2026-10-26 19:43:53 +01:00
parent 7f8a6680a8
commit 78a5ee0e55
6 changed files with 179 additions and 2 deletions
+6
View File
@@ -2844,6 +2844,12 @@ impl Game<'_> {
data,
} => self.sculk_charge_event(pos, data),
LevelEvent::LevelEvent { id: 3007, pos, .. } => self.shriek_event(pos),
// LevelEventHandler 1010 and 1011: the parrots nearby dance or stop.
LevelEvent::LevelEvent {
id: id @ (1010 | 1011),
pos,
..
} => self.notify_record_playing([pos.x, pos.y, pos.z], id == 1010),
LevelEvent::LevelEvent { id: 2004, pos, .. } => {
self.spawner_burst([pos.x, pos.y, pos.z])
}
+22 -1
View File
@@ -6,10 +6,15 @@ use super::Game;
use horizon_client::{
containers::{BlockEntity, Jukebox},
items::ItemStack,
mobs::Species,
particles::{ParticleOptions, ParticleType},
text::Text,
};
use horizon_core::{position::BlockPos, random::RandomSource};
use horizon_core::{
geometry::{Aabb, Vec3},
position::BlockPos,
random::RandomSource,
};
use horizon_world::level::flags as level_flags;
impl Game<'_> {
@@ -106,11 +111,27 @@ impl Game<'_> {
self.titles
.set_overlay(Text::translate("record.nowPlaying", &[description]), true);
self.update_song_volumes();
self.notify_record_playing(pos, true);
}
fn stop_song(&mut self, pos: [i32; 3]) {
if let Some(id) = self.jukebox_sounds.remove(&(pos[0], pos[1], pos[2])) {
self.audio.stop_and_release(id);
}
self.notify_record_playing(pos, false);
}
/// `LevelEventHandler.notifyNearbyEntities` (level events 1010 and 1011):
/// parrots within three blocks of the jukebox start or stop dancing.
pub(super) fn notify_record_playing(&mut self, pos: [i32; 3], playing: bool) {
let min = Vec3::new(f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2]));
let area = Aabb::new(min, min.add_vector(Vec3::new(1.0, 1.0, 1.0)))
.inflate(Vec3::new(3.0, 3.0, 3.0));
for m in self
.mobs
.iter_mut()
.filter(|m| m.species() == Species::Parrot && m.bounds().intersects(area))
{
m.extra.party_jukebox = playing.then_some(pos);
}
}
/// `popOutTheItem`: the disc above the jukebox, and the song stops.
fn eject_record(&mut self, pos: [i32; 3]) {
+6
View File
@@ -46,6 +46,7 @@ pub mod monster_brain;
pub mod nautilus;
pub mod nav;
pub mod nether;
pub mod parrot;
pub mod path;
pub mod phantom;
pub mod piglin;
@@ -667,6 +668,8 @@ pub struct Extra {
pub items: Vec<Option<crate::items::ItemStack>>,
pub tame: bool,
pub sitting: bool,
/// `Parrot.partyParrot` and `jukebox`: the playing jukebox it dances to.
pub party_jukebox: Option<[i32; 3]>,
/// The owner's UUID (tamed animals).
pub owner: Option<[i32; 4]>,
/// Slime/magma cube size (0 = not sized).
@@ -1260,6 +1263,8 @@ pub struct Seen {
pub stats: [f64; 3],
/// `Wolf.isInSittingPose`.
pub sitting: bool,
/// `Entity.isSilent`.
pub silent: bool,
/// `Entity.isVehicle` or `isPassenger`.
pub ridden: bool,
}
@@ -1335,6 +1340,7 @@ impl Mob {
m.attrs.speed,
],
sitting: m.extra.sitting,
silent: m.silent,
ridden: m.rider.is_some() || m.extra.rider.is_some() || m.extra.mount.is_some(),
}
}
+4
View File
@@ -581,6 +581,7 @@ fn play_ambient(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
"entity.wolf.pant"
}
}
Species::Parrot => super::parrot::ambient(m, w),
Species::Cat if m.extra.tame && m.extra.in_love > 0 => "entity.cat.purr",
Species::Cat if !m.extra.tame => "entity.cat.stray_ambient",
Species::PolarBear if m.is_baby() => "entity.polar_bear.ambient_baby",
@@ -632,6 +633,9 @@ fn play_ambient(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
/// LivingEntity.aiStep (and Mob/AgeableMob/Animal additions).
fn ai_step(m: &mut Mob, w: &MobWorld, level_random: &mut LegacyRandom, events: &mut Vec<MobEvent>) {
if m.species() == Species::Parrot {
super::parrot::ai_step(m, w, level_random, events);
}
// Witch.aiStep runs before super.aiStep().
if m.species() == Species::Witch {
let far = m
+3 -1
View File
@@ -980,7 +980,9 @@ pub fn anim(m: &Mob, s: &State, p: &mut Poses, a: &Animations) -> bool {
Species::Parrot => {
let flap = m.anim.flap_o + (m.anim.flap - m.anim.flap_o) * s.partial;
let speed = m.anim.flap_speed_o + (m.anim.flap_speed - m.anim.flap_speed_o) * s.partial;
let pose = if m.extra.sitting {
let pose = if m.extra.party_jukebox.is_some() {
ParrotPose::Party
} else if m.extra.sitting {
ParrotPose::Sitting
} else if !m.on_ground && !m.fluids.in_water {
ParrotPose::Flying
+138
View File
@@ -0,0 +1,138 @@
//! What `Parrot.aiStep` adds: imitating the mobs around it (`imitateNearbyMobs`,
//! the ambient sound of `getAmbient`) and dancing near a playing jukebox.
use super::{Mob, MobEvent, MobWorld, Species};
use horizon_core::{
geometry::Vec3,
random::{LegacyRandom, RandomSource},
};
/// `Parrot.MOB_SOUND_MAP` (the happy ghast's is `SoundEvents.EMPTY`: "").
const IMITATIONS: [(Species, &str); 41] = [
(Species::Blaze, "entity.parrot.imitate.blaze"),
(Species::Bogged, "entity.parrot.imitate.bogged"),
(Species::Breeze, "entity.parrot.imitate.breeze"),
(Species::CamelHusk, "entity.parrot.imitate.camel_husk"),
(Species::CaveSpider, "entity.parrot.imitate.spider"),
(Species::Creaking, "entity.parrot.imitate.creaking"),
(Species::Creeper, "entity.parrot.imitate.creeper"),
(Species::Drowned, "entity.parrot.imitate.drowned"),
(
Species::ElderGuardian,
"entity.parrot.imitate.elder_guardian",
),
(Species::Endermite, "entity.parrot.imitate.endermite"),
(Species::Evoker, "entity.parrot.imitate.evoker"),
(Species::Ghast, "entity.parrot.imitate.ghast"),
(Species::HappyGhast, ""),
(Species::Guardian, "entity.parrot.imitate.guardian"),
(Species::Hoglin, "entity.parrot.imitate.hoglin"),
(Species::Husk, "entity.parrot.imitate.husk"),
(Species::Illusioner, "entity.parrot.imitate.illusioner"),
(Species::MagmaCube, "entity.parrot.imitate.magma_cube"),
(Species::Parched, "entity.parrot.imitate.parched"),
(Species::Phantom, "entity.parrot.imitate.phantom"),
(Species::Piglin, "entity.parrot.imitate.piglin"),
(Species::PiglinBrute, "entity.parrot.imitate.piglin_brute"),
(Species::Pillager, "entity.parrot.imitate.pillager"),
(Species::Ravager, "entity.parrot.imitate.ravager"),
(Species::Shulker, "entity.parrot.imitate.shulker"),
(Species::Silverfish, "entity.parrot.imitate.silverfish"),
(Species::Skeleton, "entity.parrot.imitate.skeleton"),
(Species::Slime, "entity.parrot.imitate.slime"),
(Species::Spider, "entity.parrot.imitate.spider"),
(Species::Stray, "entity.parrot.imitate.stray"),
(Species::Vex, "entity.parrot.imitate.vex"),
(Species::Vindicator, "entity.parrot.imitate.vindicator"),
(Species::Warden, "entity.parrot.imitate.warden"),
(Species::Witch, "entity.parrot.imitate.witch"),
(Species::Wither, "entity.parrot.imitate.wither"),
(
Species::WitherSkeleton,
"entity.parrot.imitate.wither_skeleton",
),
(Species::Zoglin, "entity.parrot.imitate.zoglin"),
(Species::Zombie, "entity.parrot.imitate.zombie"),
(Species::ZombieHorse, "entity.parrot.imitate.zombie_horse"),
(
Species::ZombieNautilus,
"entity.parrot.imitate.zombie_nautilus",
),
(
Species::ZombieVillager,
"entity.parrot.imitate.zombie_villager",
),
];
fn imitation(species: Species) -> Option<&'static str> {
IMITATIONS.iter().find(|i| i.0 == species).map(|i| i.1)
}
/// `Parrot.getPitch`.
fn pitch(random: &mut LegacyRandom) -> f32 {
(random.next_float() - random.next_float()) * 0.2 + 1.0
}
/// The start of `Parrot.aiStep`: a jukebox that is gone or farther than
/// 3.46 blocks stops the dance, and one tick in 400 the parrot imitates a
/// mob nearby.
pub fn ai_step(
m: &mut Mob,
w: &MobWorld,
level_random: &mut LegacyRandom,
events: &mut Vec<MobEvent>,
) {
if let Some(at) = m.extra.party_jukebox {
let d = |i: usize, v: f64| f64::from(at[i]) + 0.5 - v;
let (x, y, z) = (d(0, m.position.x), d(1, m.position.y), d(2, m.position.z));
let jukebox = &*w.facts.get(w.world.block(at[0], at[1], at[2])).name == "minecraft:jukebox";
if x * x + y * y + z * z >= 3.46 * 3.46 || !jukebox {
m.extra.party_jukebox = None;
}
}
if level_random.next_int_bound(400).unwrap_or(1) == 0 {
imitate_nearby_mobs(m, w, level_random, events);
}
}
/// `Parrot.imitateNearbyMobs`: half the time, a random imitable mob within 20
/// blocks is heard through the parrot's own mouth.
fn imitate_nearby_mobs(
m: &Mob,
w: &MobWorld,
random: &mut LegacyRandom,
events: &mut Vec<MobEvent>,
) {
if !m.alive() || m.silent || random.next_int_bound(2).unwrap_or(1) != 0 {
return;
}
let area = m.bounds().inflate(Vec3::new(20.0, 20.0, 20.0));
let mobs: Vec<_> = w
.others
.iter()
.filter(|s| s.alive && imitation(s.species).is_some() && s.bounds.intersects(area))
.collect();
if mobs.is_empty() {
return;
}
let mob = mobs[random.next_int_bound(mobs.len() as i32).unwrap_or(0) as usize];
if mob.silent {
return;
}
if let Some(sound) = imitation(mob.species).filter(|s| !s.is_empty()) {
let at = [m.position.x, m.position.y, m.position.z];
events.push(MobEvent::Sound(sound, at, 0.7, pitch(random)));
}
}
/// `Parrot.getAmbient`: now and then (outside peaceful) the voice of a random
/// imitable mob instead of the parrot's own.
pub fn ambient(m: &mut Mob, w: &MobWorld) -> &'static str {
if w.difficulty.effective > 0.0 && m.random.next_int_bound(1000).unwrap_or(1) == 0 {
let i = m
.random
.next_int_bound(IMITATIONS.len() as i32)
.unwrap_or(0);
return IMITATIONS[i as usize].1;
}
"entity.parrot.ambient"
}