Server-thread clients animate warden, sniffer, breeze, camel and shulker

A client of a server (single player's window included) never got the
animation state these mobs compute on the server: no pose, no sniffer
state, no shulker peek or wall face, no camel sit or dash, no warden
tendril, attack or sonic boom events.

Send Entity.DATA_POSE and the species' synched data from mob_meta,
broadcast the warden's entity events 4, 61 and 62, read both in the
remote mob code, and run the client animation steps in
mobs::sync::client_tick.
This commit is contained in:
Kacpherek
2026-10-26 22:48:27 +01:00
parent 0c7f6b7f0b
commit a45d0de43e
12 changed files with 354 additions and 34 deletions
@@ -897,6 +897,9 @@ impl Game<'_> {
match e {
MobEvent::SquidCycle { mob, at } => self.lan_entity_event(mob as i32, 19, at),
MobEvent::RabbitHop { mob, at } => self.lan_entity_event(mob as i32, 1, at),
MobEvent::EntityEvent { mob, event, at } => {
self.lan_entity_event(mob as i32, event, at)
}
MobEvent::Sound(name, at, volume, pitch)
| MobEvent::LocalSound(name, at, volume, pitch) => {
self.audio
+62 -1
View File
@@ -161,6 +161,7 @@ fn mob_meta(
m: &Mob,
hub: &Hub,
player_entity: Option<i32>,
game_time: i64,
meta: &mut Vec<(u8, i32, Value)>,
defaults: &mut Vec<(u8, i32, Value)>,
) {
@@ -168,6 +169,12 @@ fn mob_meta(
if m.fire_ticks > 0 {
meta.push((0, serializer::BYTE, Value::Byte(1)));
}
// Entity.DATA_POSE: the pose the species keeps in its own fields (a
// pose back at standing goes out by the entity's own default).
let pose = horizon_client::mobs::sync::pose_id(m);
if pose != 0 {
meta.push((6, serializer::POSE, Value::Id(i32::from(pose))));
}
if let Some(name) = &m.custom_name {
meta.push((
2,
@@ -357,6 +364,41 @@ fn mob_meta(
}
defaults.push((17, serializer::BYTE, Value::Byte(0)));
}
// Warden.CLIENT_ANGER_LEVEL: the heartbeat's pace.
"minecraft:warden" => {
let anger = e.warden.as_ref().map_or(0, |w| w.client_anger);
if anger != 0 {
meta.push((16, serializer::INT, Value::Int(anger)));
}
defaults.push((16, serializer::INT, Value::Int(0)));
}
// Sniffer.DATA_STATE (after AgeableMob's two).
"minecraft:sniffer" => {
if e.variant != 0 {
meta.push((
18,
serializer::SNIFFER_STATE,
Value::Id(i32::from(e.variant)),
));
}
defaults.push((18, serializer::SNIFFER_STATE, Value::Id(0)));
}
// Shulker.DATA_ATTACH_FACE_ID, DATA_PEEK_ID and DATA_COLOR_ID (16
// for none).
"minecraft:shulker" => {
if e.variant3 != 0 {
meta.push((16, serializer::DIRECTION, Value::Id(i32::from(e.variant3))));
}
defaults.push((16, serializer::DIRECTION, Value::Id(0)));
if e.counter != 0 {
meta.push((17, serializer::BYTE, Value::Byte(e.counter as i8)));
}
defaults.push((17, serializer::BYTE, Value::Byte(0)));
if e.color != 16 {
meta.push((18, serializer::BYTE, Value::Byte(e.color as i8)));
}
defaults.push((18, serializer::BYTE, Value::Byte(16)));
}
// Enderman.DATA_CARRY_STATE.
"minecraft:enderman" => {
if let Some(state) = e.carried {
@@ -369,6 +411,18 @@ fn mob_meta(
}
_ => {}
}
// Camel.DASH and LAST_POSE_CHANGE_TICK (after AbstractHorse's flags).
if horizon_client::mobs::camel::is_camel(m.species()) {
if e.flag2 {
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
}
defaults.push((19, serializer::BOOLEAN, Value::Bool(false)));
let tick = horizon_client::mobs::camel::synced_pose_tick(m, game_time);
if tick != 0 {
meta.push((20, serializer::LONG, Value::Long(tick)));
}
defaults.push((20, serializer::LONG, Value::Long(0)));
}
}
/// The equipment a mob shows (ClientboundSetEquipmentPacket slots: main hand,
@@ -877,7 +931,14 @@ impl Game<'_> {
e.on_ground = m.on_ground;
e.velocity = [m.velocity.x, m.velocity.y, m.velocity.z];
e.needs_sync = m.needs_sync;
mob_meta(m, hub, player_entity, &mut e.meta, &mut e.defaults);
mob_meta(
m,
hub,
player_entity,
self.world.game_time,
&mut e.meta,
&mut e.defaults,
);
mob_equipment(m, hub, &mut e.equipment);
self.mob_attributes(m, &mut e.attributes);
e.leash = leash;
+7
View File
@@ -2135,6 +2135,10 @@ impl Game<'_> {
{
m.health = 0.0;
}
// The events that start a mob's animation (the warden's).
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
horizon_client::mobs::sync::entity_event(m, p.event as u8);
}
if p.event == super::totem::TOTEM_EVENT {
self.remote_totem(p.id);
}
@@ -3484,6 +3488,7 @@ impl Game<'_> {
m.fluids = fluids;
}
}
let game_time = self.world.game_time;
let Some(r) = self.remote.as_mut() else {
return;
};
@@ -3589,6 +3594,8 @@ impl Game<'_> {
if m.species() == horizon_client::mobs::Species::Bat {
horizon_client::mobs::bat::setup_animation_states(m);
}
// The animation states a server computes in its own `ai_step`.
horizon_client::mobs::sync::client_tick(m, game_time);
}
for o in self.orbs.iter_mut().filter(|_| running) {
o.previous = o.position;
@@ -4,7 +4,7 @@
//! own simulation, which a client of a server doesn't run.
use super::Game;
use horizon_client::mobs::render::{PROFESSIONS, VILLAGER_TYPES};
use horizon_client::mobs::{Mob, Species, Who, bat, tame};
use horizon_client::mobs::{Mob, Species, Who, bat, camel, sniffer, sync, tame};
use horizon_protocol::entity_data::Value;
use horizon_protocol::registry::Builtin;
@@ -20,6 +20,8 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_enti
// client, which draws the flames. A client doesn't count the
// fire down: the flag goes off when the server's fire is out.
(0, Value::Byte(flags)) => m.fire_ticks = i32::from(flags & 1),
// Entity.DATA_POSE: the pose the species animates by.
(6, Value::Id(pose)) => sync::set_pose(m, (*pose).clamp(0, 17) as u8),
// LivingEntity.DATA_LIVING_ENTITY_FLAGS: using an item 1, in the
// off hand 2. The flag starts and stops the use; the client ticks
// the count itself (a bow's pull follows it).
@@ -79,6 +81,29 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_enti
(Species::Slime | Species::MagmaCube, 18, Value::Int(size)) => {
m.extra.size = (*size).clamp(1, 127);
}
// Warden.CLIENT_ANGER_LEVEL: the heartbeat's pace.
(Species::Warden, 16, Value::Int(anger)) => {
if let Some(st) = m.extra.warden.as_mut() {
st.client_anger = *anger;
}
}
// Sniffer.DATA_STATE (after AgeableMob's two): the animation
// follows it in `sync::client_tick`.
(Species::Sniffer, 18, Value::Id(state)) => {
sniffer::set_state(m, (*state).clamp(0, 6) as u8);
}
// Shulker.DATA_ATTACH_FACE_ID, DATA_PEEK_ID and DATA_COLOR_ID.
(Species::Shulker, 16, Value::Id(face)) => m.extra.variant3 = (*face).clamp(0, 5) as u8,
(Species::Shulker, 17, Value::Byte(peek)) => m.extra.counter = i32::from(*peek),
(Species::Shulker, 18, Value::Byte(color)) => m.extra.color = *color as u8,
// Camel.DASH and LAST_POSE_CHANGE_TICK (after AbstractHorse's
// flags).
(Species::Camel | Species::CamelHusk, 19, Value::Bool(dashing)) => {
camel::set_dashing(m, *dashing);
}
(Species::Camel | Species::CamelHusk, 20, Value::Long(tick)) => {
camel::set_synced_pose_tick(m, *tick);
}
// Pillager.IS_CHARGING_CROSSBOW: the charge pose (Raider's
// IS_CELEBRATING takes 16).
(Species::Pillager, 17, Value::Bool(charging)) => m.extra.flag = *charging,
+9
View File
@@ -65,6 +65,7 @@ pub mod spawning;
pub mod species;
pub mod strider;
pub mod sulfur_cube;
pub mod sync;
pub mod tame;
pub mod trader;
pub mod transport_items;
@@ -776,6 +777,8 @@ pub struct Extra {
pub memories: Vec<(&'static str, i64, i64)>,
/// A camel's `LAST_POSE_CHANGE_TICK`.
pub pose_change_tick: i64,
/// `Entity.DATA_POSE` as a mob of a server has it (`sync::pose_id`).
pub pose: u8,
/// The school leader a fish follows, and a tropical fish that swims alone.
pub leader: Option<u32>,
pub lone: bool,
@@ -885,6 +888,12 @@ pub enum MobEvent {
mob: u32,
at: [f64; 3],
},
/// `Level.broadcastEntityEvent` for a mob: guests run `sync::entity_event`.
EntityEvent {
mob: u32,
event: i8,
at: [f64; 3],
},
Sound(&'static str, [f64; 3], f32, f32),
/// `ChestBlockEntity.startOpen` / `stopOpen` by a copper golem: the
/// chest's opener count goes up or down (interaction range 3).
+22
View File
@@ -31,6 +31,28 @@ pub fn pose(m: &Mob) -> u8 {
pub(super) fn set_pose(m: &mut Mob, pose: u8) {
m.extra.variant3 = pose;
}
/// `Pose.id` of the pose (`sync::pose_id`), and its inverse.
pub fn pose_id(m: &Mob) -> u8 {
match pose(m) {
SHOOTING => 16,
INHALING => 17,
LONG_JUMPING => 6,
SLIDING => 15,
_ => 0,
}
}
pub(super) fn set_pose_id(m: &mut Mob, id: u8) {
set_pose(
m,
match id {
16 => SHOOTING,
17 => INHALING,
6 => LONG_JUMPING,
15 => SLIDING,
_ => STANDING,
},
);
}
/// `Breeze.getFiringYPosition`.
pub fn firing_y(m: &Mob) -> f64 {
m.position.y + f64::from(m.height()) / 2.0 + f64::from(0.3_f32)
+45 -4
View File
@@ -45,6 +45,25 @@ pub fn sitting(m: &Mob) -> bool {
fn in_transition(m: &Mob) -> bool {
pose_time(m) < if sitting(m) { SIT_DOWN } else { STAND_UP }
}
/// `Camel.getPoseTime` of a client mob from the `LAST_POSE_CHANGE_TICK` it
/// was sent and the client's game time, and whether that value says it sits.
fn client_pose(m: &Mob, game_time: i64) -> (i64, bool) {
let tick = m.extra.pose_change_tick;
(game_time - tick.abs(), tick < 0)
}
/// The camel's `LAST_POSE_CHANGE_TICK` as the server sends it: in game time
/// (a mob counts its own age), negative while sitting.
pub fn synced_pose_tick(m: &Mob, game_time: i64) -> i64 {
let tick = (game_time - pose_time(m)).max(0);
if sitting(m) { -tick.max(1) } else { tick }
}
/// `Entity.onSyncedDataUpdated` for the pose tick of a client mob: its sign
/// is whether it sits. `client_tick` keeps `egg_time` (in the mob's age, for
/// `sitting` and `refuse_to_move`) with it.
pub fn set_synced_pose_tick(m: &mut Mob, tick: i64) {
m.extra.pose_change_tick = tick;
m.extra.egg_time = if tick < 0 { -1 } else { 0 };
}
/// `Camel.refuseToMove`: sitting or getting up or down.
pub fn refuse_to_move(m: &Mob) -> bool {
sitting(m) || in_transition(m)
@@ -166,7 +185,29 @@ pub fn ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
m.ai.zza = 0.0;
m.ai.nav.stop();
}
// setupAnimationStates.
animation_states(m, pose_time(m), sitting(m));
}
/// `Camel.tick` on a client that is not the server: the dash cooldown, which
/// the dash flag starts, and the keyframe states from the synced pose tick.
pub fn client_tick(m: &mut Mob, game_time: i64) {
if m.extra.anim_ticks > 0 {
m.extra.anim_ticks -= 1;
}
let (pose_time, sitting) = client_pose(m, game_time);
let since = (i64::from(m.age) - pose_time).max(0) as i32;
m.extra.egg_time = if sitting { -since.max(1) } else { since };
animation_states(m, pose_time, sitting);
}
/// `Camel.onSyncedDataUpdated(DASH)`: a dash starts the cooldown unless it
/// runs. Not on the first tick.
pub fn set_dashing(m: &mut Mob, dashing: bool) {
if m.age > 0 && m.extra.anim_ticks == 0 {
m.extra.anim_ticks = DASH_COOLDOWN;
}
m.extra.flag2 = dashing;
}
/// `Camel.setupAnimationStates` for a pose time and whether it sits.
fn animation_states(m: &mut Mob, pose_time: i64, sitting: bool) {
let age = m.age as f32;
if m.extra.ints[0] <= 0 {
m.extra.ints[0] = m.random.next_int_bound(40).unwrap_or(0) + 80;
@@ -175,9 +216,9 @@ pub fn ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
m.extra.ints[0] -= 1;
}
// isCamelVisuallySitting: (poseTime < 0) != sitting.
let visually_sitting = (pose_time(m) < 0) != sitting(m);
let sitting_down = sitting(m) && pose_time(m) < SIT_DOWN && pose_time(m) >= 0;
let transition = in_transition(m) && pose_time(m) >= 0;
let visually_sitting = (pose_time < 0) != sitting;
let sitting_down = sitting && (0..SIT_DOWN).contains(&pose_time);
let transition = (0..if sitting { SIT_DOWN } else { STAND_UP }).contains(&pose_time);
let dashing = m.extra.flag2;
let st = &mut m.anim.states;
if visually_sitting {
+11
View File
@@ -143,6 +143,10 @@ pub fn tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
}
}
peek_step(m);
}
/// `Shulker.updatePeekAmount`: the lid eases to the raw peek.
fn peek_step(m: &mut Mob) {
let a = &mut m.anim;
let target = m.extra.counter as f32 * 0.01;
let cur = a.v[PEEK];
@@ -152,6 +156,13 @@ pub fn tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
a.v[PEEK] = (cur + 0.05).clamp(0.0, target);
}
}
/// `Shulker.tick` on a client that is not the server: the lid eases to the
/// peek it was sent, and its body stays square (`ShulkerBodyRotationControl`).
pub fn client_tick(m: &mut Mob) {
m.anim.vo = m.anim.v;
peek_step(m);
m.body_yaw = 0.0;
}
/// `Shulker.hurtServer` before the damage: arrows bounce off a closed shell.
pub fn accepts(m: &Mob, source: &Damage) -> bool {
!(m.extra.counter == 0 && source.kind == DamageKind::Arrow)
+22 -16
View File
@@ -74,23 +74,8 @@ pub fn head_block(m: &Mob) -> [i32; 3] {
/// the dropped seed and the water malus.
pub fn ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
use super::path::PathType;
let age = m.age as f32;
let current = state(m);
if current != m.extra.scratch[0] as u8 {
// resetAnimations, then the state's own.
for s in &mut m.anim.states[..5] {
s.stop();
}
match current {
FEELING_HAPPY => m.anim.states[0].start_if_stopped(age),
SCENTING => m.anim.states[1].start_if_stopped(age),
SNIFFING => m.anim.states[2].start_if_stopped(age),
DIGGING => m.anim.states[3].start_if_stopped(age),
RISING => m.anim.states[4].start_if_stopped(age),
_ => {}
}
m.extra.scratch[0] = i32::from(current);
}
animate(m);
if current == DIGGING && now(m) == m.extra.ints[3] {
let h = head_block(m);
events.push(MobEvent::GiftLoot {
@@ -110,6 +95,27 @@ pub fn ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
let wet = m.fluids.in_water || m.fire_ticks > 0;
m.set_malus(PathType::Water, if wet { 0.0 } else { -1.0 });
}
/// `Sniffer.onSyncedDataUpdated(DATA_STATE)`: the animation states of the
/// state it changed to (on a client, each tick for the state it has).
pub fn animate(m: &mut Mob) {
let age = m.age as f32;
let current = state(m);
if current != m.extra.scratch[0] as u8 {
// resetAnimations, then the state's own.
for s in &mut m.anim.states[..5] {
s.stop();
}
match current {
FEELING_HAPPY => m.anim.states[0].start_if_stopped(age),
SCENTING => m.anim.states[1].start_if_stopped(age),
SNIFFING => m.anim.states[2].start_if_stopped(age),
DIGGING => m.anim.states[3].start_if_stopped(age),
RISING => m.anim.states[4].start_if_stopped(age),
_ => {}
}
m.extra.scratch[0] = i32::from(current);
}
}
/// The brain memory holding the explored positions
/// (`SNIFFER_EXPLORED_POSITIONS`).
pub fn to_nbt(m: &Mob, map: &mut horizon_world::nbt::Compound) {
+85
View File
@@ -0,0 +1,85 @@
//! A server's mobs as a client animates them. The server thread, a LAN host
//! and a dedicated server run each mob's animation state (`ai::tick`); a
//! client of a server only gets synched data and entity events, and runs the
//! animation steps vanilla runs on the client (`Entity.onSyncedDataUpdated`,
//! `handleEntityEvent` and the per tick animation states). The server's half
//! is `game/lan.rs` (`mob_meta`, with `pose_id` here for index 6) and
//! `MobEvent::EntityEvent`; the client's half is `game/remote_mob_data.rs`,
//! `game/remote.rs` (`C::EntityEvent`) and `client_tick` here.
//!
//! To animate another species for a client:
//! - send its synched data in `mob_meta` and read it in
//! `remote_mob_data::apply`;
//! - send its poses in `pose_id` and read them in `set_pose`;
//! - broadcast its entity events with `MobEvent::EntityEvent` and handle
//! them in `entity_event`;
//! - run its client side animation in `client_tick`, sharing the function
//! with the server's `ai_step` where the server computes the same.
use super::{Mob, Species, breeze, camel, shulker, sniffer, warden};
// `Pose.id` of the poses mobs take.
pub const STANDING: u8 = 0;
pub const LONG_JUMPING: u8 = 6;
pub const SITTING: u8 = 10;
pub const ROARING: u8 = 11;
pub const SNIFFING: u8 = 12;
pub const EMERGING: u8 = 13;
pub const DIGGING: u8 = 14;
pub const SLIDING: u8 = 15;
pub const SHOOTING: u8 = 16;
pub const INHALING: u8 = 17;
/// `Entity.DATA_POSE` (index 6) of a mob of a server: the pose its species
/// keeps in its own fields.
pub fn pose_id(m: &Mob) -> u8 {
match m.species() {
Species::Warden => warden::pose_id(m),
Species::Breeze => breeze::pose_id(m),
Species::Camel | Species::CamelHusk if camel::sitting(m) => SITTING,
_ => STANDING,
}
}
/// `Entity.onSyncedDataUpdated(DATA_POSE)` on a client.
pub fn set_pose(m: &mut Mob, id: u8) {
m.extra.pose = id;
match m.species() {
Species::Warden => warden::set_pose_id(m, id),
Species::Breeze => breeze::set_pose_id(m, id),
_ => {}
}
}
/// The per tick animation steps of a client's mobs (after `m.age` moved on),
/// for the species whose server runs them in `ai_step`. `game_time` is the
/// client level's.
pub fn client_tick(m: &mut Mob, game_time: i64) {
match m.species() {
Species::Warden => warden::client_tick(m),
Species::Sniffer => sniffer::animate(m),
Species::Breeze => breeze::ai_step(m),
Species::Camel | Species::CamelHusk => camel::client_tick(m, game_time),
Species::Shulker => shulker::client_tick(m),
_ => {}
}
}
/// `handleEntityEvent` of the mob types that start animations by an event
/// (`ClientboundEntityEventPacket` for a mob of a client).
pub fn entity_event(m: &mut Mob, event: u8) {
let age = m.age as f32;
if m.species() == Species::Warden {
match event {
// Attack: the roar ends, the swing starts.
4 => {
m.anim.states[warden::ROAR].stop();
m.anim.states[warden::ATTACK].start(age);
}
// The tendrils twitch.
61 => m.anim.v[warden::TENDRIL] = 10.0,
// The sonic boom.
62 => m.anim.states[warden::SONIC_BOOM].start(age),
_ => {}
}
}
}
+57 -12
View File
@@ -67,6 +67,29 @@ impl Pose {
}
}
}
/// `Pose.id` of the poses a warden takes (`sync::pose_id`).
pub fn pose_id(m: &Mob) -> u8 {
match pose(m) {
Pose::Standing => 0,
Pose::Roaring => 11,
Pose::Sniffing => 12,
Pose::Emerging => 13,
Pose::Digging => 14,
}
}
/// `Entity.onSyncedDataUpdated(DATA_POSE)` on a client.
pub(super) fn set_pose_id(m: &mut Mob, id: u8) {
set_pose(
m,
match id {
11 => Pose::Roaring,
12 => Pose::Sniffing,
13 => Pose::Emerging,
14 => Pose::Digging,
_ => Pose::Standing,
},
);
}
/// The warden's pose (kept in `Extra.counter` so it can be read while the
/// brain is being ticked).
pub fn pose(m: &Mob) -> Pose {
@@ -434,6 +457,11 @@ pub fn do_push(m: &mut Mob, w: &MobWorld, who: Who, events: &mut Vec<MobEvent>)
pub(super) fn do_hurt_target(m: &mut Mob, target: Who, w: &MobWorld, events: &mut Vec<MobEvent>) {
m.anim.states[ROAR].stop();
m.anim.states[ATTACK].start(m.age as f32);
events.push(MobEvent::EntityEvent {
mob: m.id,
event: 4,
at: at(m),
});
let pitch = voice_pitch(m);
sound(m, "entity.warden.attack_impact", 10.0, pitch, events);
warden_brain::mem(m).sonic_boom_cooldown.set_ttl((), 40);
@@ -546,6 +574,11 @@ fn receive_vibration(m: &mut Mob, w: &MobWorld, info: Info, events: &mut Vec<Mob
warden_brain::mem(m).vibration_cooldown.set_ttl((), 40);
// Entity event 61: the tendrils twitch.
m.anim.v[TENDRIL] = 10.0;
events.push(MobEvent::EntityEvent {
mob: m.id,
event: 61,
at: at(m),
});
let pitch = voice_pitch(m);
sound(m, "entity.warden.tendril_clicks", 5.0, pitch, events);
let origin = [
@@ -731,13 +764,7 @@ pub(super) fn tick_sonic_boom(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEve
/// of the warden: a level event sound here), the tendril and heart
/// animations, digging crumbs, and keyframes that ended.
pub fn ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
let Some(st) = m.extra.warden.as_ref() else {
return;
};
let client_anger = st.client_anger;
let delay = heart_beat_delay(client_anger);
if i64::from(m.age) % i64::from(delay) == 0 {
m.anim.v[HEART] = 10.0;
if heartbeat(m) {
events.push(MobEvent::LevelEventSound {
sound: "entity.warden.heartbeat",
at: at(m),
@@ -745,12 +772,30 @@ pub fn ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
spread: 0.2,
});
}
// The animation values count down after the sync of the last tick.
for slot in [TENDRIL, HEART] {
if m.anim.v[slot] > 0.0 {
m.anim.v[slot] -= 1.0;
}
animate(m, events);
}
/// The heart's beat on its clock, from the client's anger level: whether
/// this tick has one (its sound is the caller's).
fn heartbeat(m: &mut Mob) -> bool {
let Some(st) = m.extra.warden.as_ref() else {
return false;
};
let delay = heart_beat_delay(st.client_anger);
let beat = i64::from(m.age) % i64::from(delay) == 0;
if beat {
m.anim.v[HEART] = 10.0;
}
beat
}
/// `Warden.tick` on a client that is not the server: the heart and tendril
/// animations and the keyframes that ended. Its sounds and particles come
/// from the server.
pub fn client_tick(m: &mut Mob) {
m.anim.vo = m.anim.v;
heartbeat(m);
animate(m, &mut Vec::new());
}
fn animate(m: &mut Mob, events: &mut Vec<MobEvent>) {
let digging_clock = |m: &Mob, slot: usize| {
m.anim.states[slot]
.millis(m.age as f32)
@@ -937,6 +937,11 @@ impl B {
mm.sonic_boom_sound_delay.set_ttl((), SONIC_SOUND_DELAY);
// Entity event 62: the sonic boom keyframes start.
m.anim.states[warden::SONIC_BOOM].start(m.age as f32);
cx.events.push(MobEvent::EntityEvent {
mob: m.id,
event: 62,
at: [m.position.x, m.position.y, m.position.z],
});
sound(m, "entity.warden.sonic_charge", 3.0, 1.0, cx.events);
true
}