From 07e36a90d39779a1f889fff639cfb64bdc73ec11 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:50:43 +0200 Subject: [PATCH] Add allays and keep what mobs hold Allay: given an item it keeps the player as its friend, flies to matching drops within 32 blocks, carries up to a stack and throws it to the player (or a liked note block) one item a tick within 3 blocks, pausing pickups for three seconds after each throw; it dances by a playing jukebox, duplicates when given an amethyst shard mid-dance, heals over time, cannot be hurt by its player, and hands its item back to an empty hand; animation and NBT. Mobs now save and load what they hold (equipment mainhand and offhand), and models whose root holds another part named root (allay, vex, frog, baby axolotl) no longer apply that offset twice. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/entity_nbt.rs | 86 +++++++++ crates/horizon-client/src/game.rs | 1 + crates/horizon-client/src/game/allays.rs | 200 ++++++++++++++++++++ crates/horizon-client/src/game/creatures.rs | 7 + crates/horizon-client/src/mobs.rs | 9 + crates/horizon-client/src/mobs/ai.rs | 7 + crates/horizon-client/src/mobs/allay.rs | 189 ++++++++++++++++++ crates/horizon-client/src/mobs/anim.rs | 2 + crates/horizon-client/src/mobs/species.rs | 16 ++ 9 files changed, 517 insertions(+) create mode 100644 crates/horizon-client/src/game/allays.rs create mode 100644 crates/horizon-client/src/mobs/allay.rs diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index c98de4421..00b72f0e8 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -246,6 +246,35 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag { } map.insert("equipment".into(), Tag::Compound(equipment)); } + "minecraft:allay" => { + // InventoryCarrier: the fetched stack; the liked player memory. + let mut inv = Vec::new(); + if let (Some(item), n) = (&m.extra.main_hand, m.extra.ints[1]) + && n > 0 + { + inv.push(Tag::compound([ + ("id", Tag::String(item.as_ref().into())), + ("count", Tag::Int(n)), + ])); + } + map.insert("Inventory".into(), Tag::List(inv)); + map.insert( + "DuplicationCooldown".into(), + Tag::Long(i64::from(m.extra.egg_time)), + ); + if m.extra.tame { + map.insert( + "Brain".into(), + Tag::compound([( + "memories", + Tag::compound([( + "minecraft:liked_player", + Tag::compound([("value", Tag::IntArray(vec![0, 0, 0, 1]))]), + )]), + )]), + ); + } + } "minecraft:camel" => { // LastPoseTick: negative while sitting. let sitting = crate::mobs::camel::sitting(m); @@ -306,6 +335,39 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag { } _ => {} } + // LivingEntity equipment: what the mob holds now. + if !crate::mobs::equine::is_equine(m.species()) { + let mut equipment = match map.get(&"equipment".into()) { + Some(Tag::Compound(c)) => c.clone(), + _ => horizon_world::nbt::Compound::new(), + }; + for (slot, item) in [ + ("mainhand", &m.extra.main_hand), + ("offhand", &m.extra.off_hand), + ] { + match item { + Some(id) => { + let keep = matches!( + equipment.get(&slot.into()).and_then(|e| e.get("id")), + Some(Tag::String(s)) if s.to_string_lossy() == **id + ); + if !keep { + equipment.insert( + slot.into(), + Tag::compound([ + ("id", Tag::String(id.as_ref().into())), + ("count", Tag::Int(1)), + ]), + ); + } + } + None => { + equipment.remove(&slot.into()); + } + } + } + map.insert("equipment".into(), Tag::Compound(equipment)); + } tag } /// `CustomName`: a text component saved as a string or a `{text: ..}` compound. @@ -332,6 +394,17 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - m.health = h as f32; } m.hurt_time = number(tag.get("HurtTime")).unwrap_or(0) as i32; + // What it holds (equipment.mainhand / offhand), when saved. + if let Some(eq) = tag.get("equipment") { + m.extra.main_hand = eq + .get("mainhand") + .and_then(|i| text(i.get("id"))) + .map(Into::into); + m.extra.off_hand = eq + .get("offhand") + .and_then(|i| text(i.get("id"))) + .map(Into::into); + } m.death_time = number(tag.get("DeathTime")).unwrap_or(0) as i32; m.persistent = flag(tag, "PersistenceRequired"); m.custom_name = custom_name(tag); @@ -424,6 +497,19 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - .unwrap_or(0) as u8; } } + if m.species() == crate::mobs::Species::Allay { + if let Some(Tag::List(inv)) = tag.get("Inventory") + && let Some(first) = inv.first() + { + m.extra.ints[1] = number(first.get("count")).unwrap_or(1) as i32; + } + m.extra.egg_time = number(tag.get("DuplicationCooldown")).unwrap_or(0) as i32; + m.extra.tame = tag + .get("Brain") + .and_then(|b| b.get("memories")) + .and_then(|b| b.get("minecraft:liked_player")) + .is_some(); + } if m.species() == crate::mobs::Species::Camel { let sitting = matches!(tag.get("LastPoseTick"), Some(Tag::Long(v)) if *v < 0); crate::mobs::camel::stand_up_instantly(&mut m); diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index f95c2cb8e..66925932c 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -2,6 +2,7 @@ //! block interaction, inventory and HUD. mod advancements; mod advancements_screen; +mod allays; mod armor_stands; mod beacon; mod blockctl; diff --git a/crates/horizon-client/src/game/allays.rs b/crates/horizon-client/src/game/allays.rs new file mode 100644 index 000000000..7a6d62e63 --- /dev/null +++ b/crates/horizon-client/src/game/allays.rs @@ -0,0 +1,200 @@ +//! Allays on the game side: spotting and picking up matching drops, +//! throwing their load to the player or note block, dancing to jukeboxes, +//! and the hand-over interaction (`Allay.mobInteract`). +use super::Game; +use horizon_client::{containers::BlockEntity, items::ItemStack, mobs::Species}; +use horizon_core::random::RandomSource; + +impl Game<'_> { + pub(super) fn tick_allays(&mut self) { + let griefing = self.ui.rules.bool("mob_griefing"); + let player = self.player.as_ref().map(|p| p.position); + for i in 0..self.mobs.len() { + if self.mobs[i].species() != Species::Allay || !self.mobs[i].alive() { + continue; + } + let pos = self.mobs[i].position; + // Dancing: a playing jukebox within 10 blocks. + let dancing = self.world.block_entities.iter().any(|(k, e)| { + matches!(e, BlockEntity::Jukebox(j) if j.playing) + && (f64::from(k.0) + 0.5 - pos.x).powi(2) + + (f64::from(k.1) + 0.5 - pos.y).powi(2) + + (f64::from(k.2) + 0.5 - pos.z).powi(2) + <= 100.0 + }); + self.mobs[i].extra.flag = + dancing && !horizon_client::mobs::goals::should_panic(&self.mobs[i]); + let Some(held) = self.mobs[i].extra.main_hand.clone() else { + self.mobs[i].extra.point = None; + continue; + }; + let carried = self.mobs[i].extra.ints[1]; + let max = self.res.items.get(&held).map_or(64, |i| i.max_stack as i32); + // GoToWantedItem / wantsToPickUp: the same item within 32. + let wanted = if griefing && carried < max && self.mobs[i].extra.ints[3] <= 0 { + self.dropped + .iter() + .enumerate() + .filter(|(_, e)| e.stack.item == held && e.pickup_delay == 0) + .map(|(j, e)| (j, e.position.distance_squared(pos))) + .filter(|(_, d)| *d <= 32.0 * 32.0) + .min_by(|a, b| a.1.total_cmp(&b.1)) + } else { + None + }; + let Some((j, _)) = wanted else { + self.mobs[i].extra.point = None; + self.allay_deliver(i, player); + continue; + }; + let e = &self.dropped[j]; + // getPickupReach (1, 1, 1) around the box. + let b = self.mobs[i] + .bounds() + .inflate(horizon_core::geometry::Vec3::new(1.0, 1.0, 1.0)); + if b.contains(e.position) { + let take = (max - carried).min(e.stack.count as i32); + self.mobs[i].extra.ints[1] += take; + let e = &mut self.dropped[j]; + e.stack.count -= take as u32; + if e.stack.count == 0 { + self.dropped.remove(j); + } + let at = [pos.x, pos.y, pos.z]; + let pitch = + (self.world.random.next_float() - self.world.random.next_float()) * 1.4 + 2.0; + self.audio + .play("minecraft:entity.item.pickup", Some(at), 0.2, pitch); + self.mobs[i].extra.point = None; + } else { + self.mobs[i].extra.point = Some([e.position.x, e.position.y, e.position.z]); + } + } + } + /// `GoAndGiveItemsToTarget` / `AllayAi.throwItem`: within 3 blocks of + /// the deposit, one item a tick, each restarting the three-second pause + /// before it picks anything up again. + fn allay_deliver(&mut self, i: usize, player: Option) { + let m = &self.mobs[i]; + if m.extra.ints[1] <= 0 { + return; + } + let target = match m.extra.home.filter(|_| m.extra.ints[2] > 0) { + Some(h) => horizon_core::geometry::Vec3::new( + f64::from(h[0]) + 0.5, + f64::from(h[1]) + 1.0, + f64::from(h[2]) + 0.5, + ), + None => match player.filter(|_| m.extra.tame) { + Some(p) => p, + None => return, + }, + }; + let eye = horizon_core::geometry::Vec3::new(m.position.x, m.eye_y(), m.position.z); + if target.distance_squared(eye) >= 9.0 { + return; + } + let Some(item) = m.extra.main_hand.clone() else { + return; + }; + let from = [ + m.position.x, + m.position.y + m.eye_height() - 0.3, + m.position.z, + ]; + let d = [ + target.x - from[0], + target.y + 1.0 - from[1], + target.z - from[2], + ]; + let len = (d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt().max(1e-6); + let v = [d[0] / len * 0.2, d[1] / len * 0.3, d[2] / len * 0.2]; + let m = &mut self.mobs[i]; + m.extra.ints[1] -= 1; + m.extra.ints[3] = 60; + self.spawn_item(ItemStack::new(&item, 1), from, v, 40); + if self.world.game_time % 7 == 0 && self.world.random.next_double() < 0.9 { + const PITCHES: [f32; 16] = [ + 0.5625, 0.625, 0.75, 0.9375, 1.0, 1.0, 1.125, 1.25, 1.5, 1.875, 2.0, 2.25, 2.5, + 3.0, 3.75, 4.0, + ]; + let pitch = PITCHES[self.world.random.next_int_bound(16).unwrap_or(4) as usize]; + self.audio + .play("minecraft:entity.allay.item_thrown", Some(from), 1.0, pitch); + } + } + /// `Allay.mobInteract`: duplicate when dancing with an amethyst shard, + /// take the held item, or hand back what it holds. + pub(super) fn interact_allay(&mut self, index: usize, item: &str) -> bool { + let m = &self.mobs[index]; + if m.species() != Species::Allay || !m.alive() { + return false; + } + let at = [m.position.x, m.position.y, m.position.z]; + if m.extra.flag && item == "minecraft:amethyst_shard" && m.extra.egg_time == 0 { + let pos = at; + self.mobs[index].extra.egg_time = 6000; + if let Some(id) = self.spawn_mob("minecraft:allay", pos, true) + && let Some(c) = self.mobs.iter_mut().find(|m| m.id == id) + { + c.extra.egg_time = 6000; + } + for _ in 0..3 { + let r = &mut self.world.random; + let p = [ + at[0] + r.next_double() - 0.5, + at[1] + 0.5 + r.next_double() * 0.6, + at[2] + r.next_double() - 0.5, + ]; + if let Some(ty) = horizon_client::particles::ParticleType::from_name("heart") { + self.particles.add( + &horizon_client::particles::ParticleOptions::simple(ty), + p, + [0.0; 3], + ); + } + } + self.audio + .play("minecraft:block.amethyst_block.chime", Some(at), 2.0, 1.0); + self.consume_held(); + return true; + } + let holds = m.extra.main_hand.is_some(); + if !holds && !item.is_empty() { + let m = &mut self.mobs[index]; + m.extra.main_hand = Some(item.into()); + m.extra.tame = true; + self.audio + .play("minecraft:entity.allay.item_given", Some(at), 2.0, 1.0); + self.consume_held(); + return true; + } + if holds && item.is_empty() { + let m = &mut self.mobs[index]; + let held = m + .extra + .main_hand + .take() + .unwrap_or_else(|| "minecraft:air".into()); + let carried = std::mem::take(&mut m.extra.ints[1]); + m.extra.tame = false; + self.audio + .play("minecraft:entity.allay.item_taken", Some(at), 2.0, 1.0); + if carried > 0 { + self.spawn_item( + ItemStack::new(&held, carried as u32), + at, + [0.0, 0.2, 0.0], + 40, + ); + } + if let Some(rest) = self.give(ItemStack::new(&held, 1)) + && let Some(eye) = self.eye_position() + { + self.spawn_item(rest, eye, [0.0; 3], 0); + } + return true; + } + false + } +} diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 5c72ba06a..12e63fa1f 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -243,6 +243,8 @@ impl Game<'_> { "baby": m.is_baby(), "target": m.ai.target.map(|t| format!("{t:?}")), "goals": m.ai.goals.running_names(), + "held": m.extra.main_hand.as_deref(), + "ints": m.extra.ints, "targets": m.ai.targets.running_names(), "path": m.ai.nav.path.as_ref().map(|p| p.nodes.len() - p.next.min(p.nodes.len())), "on_ground": m.on_ground, @@ -578,6 +580,7 @@ impl Game<'_> { self.handle_mob_events(events)?; self.tick_projectiles()?; self.tick_fangs(); + self.tick_allays(); self.tick_player_effects(); self.piglin_pickups(); Ok(()) @@ -1595,6 +1598,10 @@ impl Game<'_> { .unwrap_or_default(); let creative = self.creative; let selected = self.selected; + if self.interact_allay(index, &item) { + self.swing_arm(); + return Ok(true); + } // AbstractHorse.mobInteract: feed, equip or ride. if self.interact_mount(index, &item) { self.swing_arm(); diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 0e6be5a20..f7c486396 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -6,6 +6,7 @@ //! controls (`control`), `LivingEntity` physics (`living`) and per-species //! behaviour, models, animations and sounds. pub mod ai; +pub mod allay; pub mod anim; pub mod aquatic; pub mod camel; @@ -103,6 +104,14 @@ impl Part { .map(|(k, c)| Part::parse(k, c)) .collect(); children.sort_by(|a, b| a.name.cmp(&b.name)); + // A model whose root holds a part also named "root" (allay, vex, + // frog...): that inner part is what `root.getChild("root")` and the + // keyframe bones mean, so the outer one gives up the name. + let name = if name == "root" && children.iter().any(|c| c.name == "root") { + "" + } else { + name + }; Self { name: name.to_owned(), pose: p, diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index 581e568d7..532690c1f 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -85,6 +85,7 @@ pub enum Family { Vex, Ravager, Wither, + Allay, } pub fn family(s: Species) -> Family { use Species as S; @@ -118,6 +119,7 @@ pub fn family(s: Species) -> Family { S::Vex => Family::Vex, S::Ravager => Family::Ravager, S::Wither => Family::Wither, + S::Allay => Family::Allay, S::Piglin | S::PiglinBrute | S::Hoglin | S::Zoglin => Family::Piglin, S::Horse | S::Donkey | S::Mule | S::SkeletonHorse | S::ZombieHorse | S::Camel => { Family::Equine @@ -163,6 +165,7 @@ pub fn register(m: &mut Mob) { Family::Vex => super::vex::register(m), Family::Ravager => super::ravager::register(m), Family::Wither => super::wither::register(m), + Family::Allay => super::allay::register(m), } } /// Mob.tick additions that run before the entity tick (creeper fuse, puffing). @@ -384,6 +387,7 @@ fn play_ambient(m: &mut Mob, w: &MobWorld, events: &mut Vec) { Species::ElderGuardian if !m.fluids.in_water => "entity.elder_guardian.ambient_land", Species::Axolotl if !m.fluids.in_water => "entity.axolotl.idle_air", Species::Bat if m.extra.flag && m.random.next_int_bound(4).unwrap_or(1) != 0 => return, + Species::Allay if m.extra.main_hand.is_some() => "entity.allay.ambient_with_item", // Shulker.playAmbientSound: silent while closed. Species::Shulker if m.extra.counter == 0 => return, Species::ZombifiedPiglin if m.ai.target.is_some() => "entity.zombified_piglin.angry", @@ -555,6 +559,7 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec) { Species::Vex => super::vex::ai_step(m, w), Species::Ravager => super::ravager::ai_step(m, w, events), Species::Wither => super::wither::ai_step(m, w, events), + Species::Allay => super::allay::ai_step(m), Species::Shulker => { super::shulker::tick(m, w, events); super::shulker::ai_step(m, w, events); @@ -652,6 +657,8 @@ pub fn walk_target_value(m: &Mob, w: &MobWorld, p: [i32; 3]) -> f32 { /// Species damage filters (LivingEntity.hurtServer overrides). pub fn accepts_damage(m: &mut Mob, source: &Damage, _amount: f32) -> bool { match m.species() { + // Allay.hurtServer: its liked player cannot hurt it. + Species::Allay if m.extra.tame && source.attacker == Some(Who::Player) => false, Species::Wither => super::wither::accepts(m, source.kind, source.attacker, false), Species::Shulker => super::shulker::accepts(m, source), Species::Enderman => super::enderman::on_damage(m, source), diff --git a/crates/horizon-client/src/mobs/allay.rs b/crates/horizon-client/src/mobs/allay.rs new file mode 100644 index 000000000..d371c1be7 --- /dev/null +++ b/crates/horizon-client/src/mobs/allay.rs @@ -0,0 +1,189 @@ +//! Allays (`Allay`): given an item, they fetch matching drops within 32 +//! blocks and bring them to their player (or a liked note block), dance to +//! jukeboxes and duplicate when given an amethyst shard mid-dance. +use super::{ + Mob, + anim::{Poses, State}, + control::MoveKind, + goals::{Cx, Goal, LookAtPlayer, MOVE, Panic, RandomLookAround, Stroll, goal_clone}, + nav::NavKind, +}; + +// Allay state: `main_hand` the held item, `ints[1]` how many it carries, +// `tame` a liked player, `point` the wanted item (set by the game), +// `home` the liked note block with `ints[2]` its cooldown, `ints[3]` the +// pickup cooldown, `flag` dancing with `ints[4]` the dance clock, +// `egg_time` the duplication cooldown. AnimState slots: holding (0), +// spinning (1). +const HOLD: usize = 0; +const SPIN: usize = 1; + +pub fn register(m: &mut Mob) { + m.ai.mov.kind = MoveKind::Flying { + max_turn: 20.0, + hovers: true, + }; + m.ai.nav.kind = NavKind::Flying; + // FlyingPathNavigation.setRequiredPathLength(48). + m.ai.nav.required_path_length = 48.0; + m.persistent = true; + let g = &mut m.ai.goals; + g.add(0, Panic::new(2.5)); + g.add(1, Fetch); + g.add(2, Deliver); + g.add(3, StayClose); + g.add(4, Stroll::flying(1.0)); + g.add(5, LookAtPlayer::new(6.0)); + g.add(6, RandomLookAround::default()); +} +/// Where carried items go: the liked note block, else the player. +fn deposit(m: &Mob, cx: &Cx) -> Option<[f64; 3]> { + if let Some(h) = m.extra.home + && m.extra.ints[2] > 0 + { + return Some([ + f64::from(h[0]) + 0.5, + f64::from(h[1]) + 1.0, + f64::from(h[2]) + 0.5, + ]); + } + if !m.extra.tame { + return None; + } + let p = cx.w.player.as_ref().filter(|p| p.alive && !p.spectator)?; + (p.position.distance_squared(m.position) <= 64.0 * 64.0).then_some([ + p.position.x, + p.position.y, + p.position.z, + ]) +} +/// `GoToWantedItem`: fly to the wanted drop. +#[derive(Clone, Debug)] +struct Fetch; +impl Goal for Fetch { + goal_clone!(); + fn flags(&self) -> u8 { + MOVE + } + fn can_use(&mut self, m: &mut Mob, _cx: &mut Cx) -> bool { + m.extra.point.is_some() && m.extra.ints[3] <= 0 + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + if let Some(p) = m.extra.point + && (m.ai.nav.is_done() || m.age.is_multiple_of(10)) + { + m.nav_move_to(cx.w, p, 1.75); + } + } +} +/// `GoAndGiveItemsToTarget`: carry the load to the deposit and throw it. +#[derive(Clone, Debug)] +struct Deliver; +impl Goal for Deliver { + goal_clone!(); + fn flags(&self) -> u8 { + MOVE + } + fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + m.extra.ints[1] > 0 && m.extra.point.is_none() && deposit(m, cx).is_some() + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + if let Some(p) = deposit(m, cx) + && (m.ai.nav.is_done() || m.age.is_multiple_of(10)) + { + m.nav_move_to(cx.w, p, 2.25); + } + } +} +/// `StayCloseToTarget`: back within 4 blocks of the deposit. +#[derive(Clone, Debug)] +struct StayClose; +impl Goal for StayClose { + goal_clone!(); + fn flags(&self) -> u8 { + MOVE + } + fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + m.extra.point.is_none() + && deposit(m, cx).is_some_and(|p| { + let d = (p[0] - m.position.x).powi(2) + + (p[1] - m.position.y).powi(2) + + (p[2] - m.position.z).powi(2); + d > 16.0 + }) + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + if let Some(p) = deposit(m, cx) + && (m.ai.nav.is_done() || m.age.is_multiple_of(10)) + { + m.nav_move_to(cx.w, p, 2.25); + } + } +} +/// `Allay.aiStep` / `tick`: healing, cooldowns, the hold and spin clocks. +pub fn ai_step(m: &mut Mob) { + if m.alive() && m.age.is_multiple_of(10) { + m.health = (m.health + 1.0).min(m.attrs.max_health); + } + for i in [2, 3] { + if m.extra.ints[i] > 0 { + m.extra.ints[i] -= 1; + } + } + if m.extra.egg_time > 0 { + m.extra.egg_time -= 1; + } + let holding = m.extra.main_hand.is_some(); + let v = &mut m.anim.v; + v[HOLD] = (v[HOLD] + if holding { 1.0 } else { -1.0 }).clamp(0.0, 5.0); + if m.extra.flag { + m.extra.ints[4] += 1; + let spinning = (m.extra.ints[4] as f32 % 55.0) < 15.0; + v[SPIN] = (v[SPIN] + if spinning { 1.0 } else { -1.0 }).clamp(0.0, 15.0); + } else { + m.extra.ints[4] = 0; + v[SPIN] = 0.0; + m.anim.vo[SPIN] = 0.0; + } +} +/// `AllayModel.setupAnim`. +pub fn anim(m: &Mob, s: &State, p: &mut Poses) { + use std::f32::consts::PI; + let (speed, pos) = (s.speed, s.pos); + let flap_speed = (s.age * 20.0).to_radians() + pos; + let flap = flap_speed.cos() * PI * 0.15 + speed; + let idle_bob = (s.age * 9.0).to_radians(); + let flying = (speed / 0.3).min(1.0); + let idle = 1.0 - flying; + let hold = m.anim.lerp(HOLD, s.partial) / 5.0; + if m.extra.flag { + let dance = (s.age * 8.0).to_radians() + speed; + let freq = dance.cos() * 16f32.to_radians(); + let spin = m.anim.lerp(SPIN, s.partial) / 15.0; + let spinning = (m.extra.ints[4] as f32 % 55.0) < 15.0; + if spinning { + p.yrot("root", PI * 4.0 * spin); + } + p.zrot("root", freq * (1.0 - spin)); + p.yrot("head", dance.cos() * 30f32.to_radians() * (1.0 - spin)); + p.zrot("head", dance.cos() * 14f32.to_radians() * (1.0 - spin)); + } else { + p.xrot("head", s.x_rot.to_radians()); + p.yrot("head", s.y_rot.to_radians()); + } + p.xrot("right_wing", 0.436_332_32 * (1.0 - flying)); + p.yrot("right_wing", -PI / 4.0 + flap); + p.xrot("left_wing", 0.436_332_32 * (1.0 - flying)); + p.yrot("left_wing", PI / 4.0 - flap); + p.xrot("body", flying * PI / 4.0); + let arm_x = hold * (-PI / 3.0 + (-1.134_464 + PI / 3.0) * flying); + p.get("root")[1] += idle_bob.cos() * 0.25 * idle; + p.xrot("right_arm", arm_x); + p.xrot("left_arm", arm_x); + let arm_bob = idle * (1.0 - hold); + let amount = 0.436_332_32 - (idle_bob + PI * 1.5).cos() * PI * 0.075 * arm_bob; + p.zrot("left_arm", -amount); + p.zrot("right_arm", amount); + p.yrot("right_arm", 0.279_252_68 * hold); + p.yrot("left_arm", -0.279_252_68 * hold); +} diff --git a/crates/horizon-client/src/mobs/anim.rs b/crates/horizon-client/src/mobs/anim.rs index 6d635efe1..37740033f 100644 --- a/crates/horizon-client/src/mobs/anim.rs +++ b/crates/horizon-client/src/mobs/anim.rs @@ -8,6 +8,7 @@ use std::f32::consts::PI; /// The setupAnim implementation a model uses. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Anim { + Allay, Camel, Wither, Vex, @@ -344,6 +345,7 @@ pub fn setup( ) { match m.kind.anim { Anim::Camel => super::camel::anim(m, s, p, w_anims), + Anim::Allay => super::allay::anim(m, s, p), Anim::Squid | Anim::Fish | Anim::Pufferfish | Anim::Dolphin => { super::aquatic::anim(m, s, p) } diff --git a/crates/horizon-client/src/mobs/species.rs b/crates/horizon-client/src/mobs/species.rs index 04e8c9e5d..820006f32 100644 --- a/crates/horizon-client/src/mobs/species.rs +++ b/crates/horizon-client/src/mobs/species.rs @@ -82,6 +82,7 @@ pub enum Species { Ravager, Wither, Camel, + Allay, } /// Baby bounding boxes (each class's BABY_DIMENSIONS). #[derive(Clone, Copy, Debug)] @@ -899,6 +900,20 @@ pub const ALL: &[Def] = &[ None, Baby::None ), + def!( + Allay, + "allay", + "allay#main", + "entity/allay/allay", + A::Allay, + [ + "entity.allay.ambient_without_item", + "entity.allay.hurt", + "entity.allay.death" + ], + None, + Baby::None + ), def!( Camel, "camel", @@ -1246,6 +1261,7 @@ impl Def { | S::Slime | S::MagmaCube | S::Wither + | S::Allay ), flying: matches!(s, S::Ghast | S::Phantom), climber: matches!(s, S::Spider | S::CaveSpider),