Merge #2533 into fix/armadillo-roll
Both change the same lines; this head carries #2533's, so it merges after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4705,25 +4705,12 @@ impl Game<'_> {
|
||||
.play("minecraft:entity.player.swim", Some(feet), volume, pitch);
|
||||
}
|
||||
MotionEvent::Drown => {
|
||||
// LivingEntity.makeDrownParticles: eight bubbles moving
|
||||
// with the player.
|
||||
use horizon_client::particles::{ParticleOptions, ParticleType};
|
||||
for _ in 0..8 {
|
||||
let mut triangle = || {
|
||||
let r = self.particles.random();
|
||||
r.next_double() - r.next_double()
|
||||
};
|
||||
let p = [
|
||||
feet[0] + triangle(),
|
||||
feet[1] + triangle(),
|
||||
feet[2] + triangle(),
|
||||
];
|
||||
self.particles.add(
|
||||
&ParticleOptions::simple(ParticleType::Bubble),
|
||||
p,
|
||||
player_velocity,
|
||||
);
|
||||
// The guests see the entity event 67 too.
|
||||
if let Some(host) = &self.lan {
|
||||
host.hub
|
||||
.entity_event(host.host_entity, combat::DROWN_EVENT, feet);
|
||||
}
|
||||
self.drown_particles(feet, player_velocity);
|
||||
}
|
||||
MotionEvent::BubbleColumnParticle { bubble, position } => {
|
||||
// ServerLevel.sendParticles: SPLASH (speed 1) or BUBBLE
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
//! The player's `CombatTracker`: the damage taken lately, who dealt it and
|
||||
//! where the player fell from, turned into the vanilla death message.
|
||||
use super::{Game, chat::PLAYER_NAME};
|
||||
use horizon_client::{health::HealthEvent, motion::MotionEvent, text::Text};
|
||||
use horizon_client::{
|
||||
health::HealthEvent,
|
||||
motion::MotionEvent,
|
||||
particles::{ParticleOptions, ParticleType},
|
||||
text::Text,
|
||||
};
|
||||
use horizon_core::random::RandomSource;
|
||||
|
||||
/// `EntityEvent.DROWN_PARTICLES`: broadcast with the drowning damage.
|
||||
pub(super) const DROWN_EVENT: i8 = 67;
|
||||
|
||||
struct Entry {
|
||||
damage_type: String,
|
||||
@@ -45,6 +54,38 @@ pub(super) struct CombatTracker {
|
||||
fall_before: f64,
|
||||
}
|
||||
impl Game<'_> {
|
||||
/// `LivingEntity.makeDrownParticles`: eight bubbles around the entity,
|
||||
/// moving with it.
|
||||
pub(super) fn drown_particles(&mut self, at: [f64; 3], velocity: [f64; 3]) {
|
||||
let bubble = ParticleOptions::simple(ParticleType::Bubble);
|
||||
for _ in 0..8 {
|
||||
let mut triangle = || {
|
||||
let r = self.particles.random();
|
||||
r.next_double() - r.next_double()
|
||||
};
|
||||
let p = [at[0] + triangle(), at[1] + triangle(), at[2] + triangle()];
|
||||
self.particles.add(&bubble, p, velocity);
|
||||
}
|
||||
}
|
||||
/// Entity event 67 from a server, for this client's own player or an
|
||||
/// entity it draws.
|
||||
pub(super) fn remote_drown(&mut self, id: i32) {
|
||||
let own = self.remote.as_ref().is_some_and(|r| r.entity_id == id);
|
||||
let body = if own {
|
||||
self.player.as_ref().map(|p| {
|
||||
let (at, v) = (p.position, p.velocity);
|
||||
([at.x, at.y, at.z], [v.x, v.y, v.z])
|
||||
})
|
||||
} else {
|
||||
self.mobs.iter().find(|m| m.id == id as u32).map(|m| {
|
||||
let (at, v) = (m.position, m.velocity);
|
||||
([at.x, at.y, at.z], [v.x, v.y, v.z])
|
||||
})
|
||||
};
|
||||
if let Some((at, v)) = body {
|
||||
self.drown_particles(at, v);
|
||||
}
|
||||
}
|
||||
/// The display name of a mob: its custom name or its type's name.
|
||||
pub(super) fn mob_display_name(&self, id: u32) -> Option<Text> {
|
||||
let m = self.mobs.iter().find(|m| m.id == id)?;
|
||||
|
||||
@@ -119,6 +119,7 @@ impl Game<'_> {
|
||||
"magic" | "indirect_magic" | "dragon_breath" => DamageKind::Magic,
|
||||
"sting" => DamageKind::Sting,
|
||||
"cactus" | "sweet_berry_bush" => DamageKind::Cactus,
|
||||
"freeze" => DamageKind::Freeze,
|
||||
"in_wall" => DamageKind::InWall,
|
||||
"thorns" => DamageKind::Thorns,
|
||||
_ => DamageKind::Generic,
|
||||
|
||||
@@ -935,6 +935,15 @@ 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::Drown { mob, at } => {
|
||||
self.lan_entity_event(mob as i32, super::combat::DROWN_EVENT, at);
|
||||
let v = self
|
||||
.mobs
|
||||
.iter()
|
||||
.find(|m| m.id == mob)
|
||||
.map_or([0.0; 3], |m| [m.velocity.x, m.velocity.y, m.velocity.z]);
|
||||
self.drown_particles(at, v);
|
||||
}
|
||||
MobEvent::EntityEvent { mob, event, at } => {
|
||||
self.lan_entity_event(mob as i32, event, at)
|
||||
}
|
||||
@@ -3708,6 +3717,7 @@ pub(super) fn damage_type(kind: horizon_client::mobs::DamageKind, player: bool)
|
||||
K::InWall => "minecraft:in_wall",
|
||||
K::Thorns => "minecraft:thorns",
|
||||
K::SonicBoom => "minecraft:sonic_boom",
|
||||
K::Freeze => "minecraft:freeze",
|
||||
K::OutOfWorld => "minecraft:out_of_world",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,6 +439,59 @@ fn mob_meta(
|
||||
}
|
||||
defaults.push((18, serializer::BYTE, Value::Byte(16)));
|
||||
}
|
||||
// Vex.DATA_FLAGS_ID: charging in bit 0 (the arms and the glowing
|
||||
// texture).
|
||||
"minecraft:vex" => {
|
||||
if e.flag {
|
||||
meta.push((16, serializer::BYTE, Value::Byte(1)));
|
||||
}
|
||||
defaults.push((16, serializer::BYTE, Value::Byte(0)));
|
||||
}
|
||||
// Creaking.CAN_MOVE, IS_ACTIVE and IS_TEARING_DOWN.
|
||||
"minecraft:creaking" => {
|
||||
if e.flag2 {
|
||||
meta.push((16, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
defaults.push((16, serializer::BOOLEAN, Value::Bool(true)));
|
||||
if e.flag {
|
||||
meta.push((17, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
defaults.push((17, serializer::BOOLEAN, Value::Bool(false)));
|
||||
if horizon_client::mobs::creaking::tearing_down(m) {
|
||||
meta.push((18, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
defaults.push((18, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
// Allay.DATA_DANCING and DATA_CAN_DUPLICATE (the held item is its
|
||||
// main hand equipment).
|
||||
"minecraft:allay" => {
|
||||
if e.flag {
|
||||
meta.push((16, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
defaults.push((16, serializer::BOOLEAN, Value::Bool(false)));
|
||||
if e.egg_time > 0 {
|
||||
meta.push((17, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
defaults.push((17, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
// Axolotl.DATA_PLAYING_DEAD (after DATA_VARIANT).
|
||||
"minecraft:axolotl" => {
|
||||
if horizon_client::mobs::axolotl::is_playing_dead(m) {
|
||||
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
defaults.push((19, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
// CopperGolem.COPPER_GOLEM_STATE (after DATA_WEATHER_STATE).
|
||||
"minecraft:copper_golem" => {
|
||||
if e.variant3 != 0 {
|
||||
meta.push((
|
||||
17,
|
||||
serializer::COPPER_GOLEM_STATE,
|
||||
Value::Id(i32::from(e.variant3)),
|
||||
));
|
||||
}
|
||||
defaults.push((17, serializer::COPPER_GOLEM_STATE, Value::Id(0)));
|
||||
}
|
||||
// Armadillo.ARMADILLO_STATE (after AgeableMob's two).
|
||||
"minecraft:armadillo" => {
|
||||
let state = horizon_client::mobs::armadillo::state(m);
|
||||
@@ -473,6 +526,26 @@ fn mob_meta(
|
||||
}
|
||||
}
|
||||
|
||||
/// What a client shakes a mob by: Entity.DATA_TICKS_FROZEN (7), whose full
|
||||
/// count is `isFullyFrozen`, and Strider.DATA_SUFFOCATING (19, after
|
||||
/// AgeableMob's two and DATA_BOOST_TIME).
|
||||
fn mob_freeze_meta(
|
||||
m: &Mob,
|
||||
meta: &mut Vec<(u8, i32, Value)>,
|
||||
defaults: &mut Vec<(u8, i32, Value)>,
|
||||
) {
|
||||
if m.ticks_frozen > 0 {
|
||||
meta.push((7, serializer::INT, Value::Int(m.ticks_frozen)));
|
||||
}
|
||||
defaults.push((7, serializer::INT, Value::Int(0)));
|
||||
if m.kind.id == "minecraft:strider" {
|
||||
if m.extra.flag {
|
||||
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
|
||||
}
|
||||
defaults.push((19, serializer::BOOLEAN, Value::Bool(false)));
|
||||
}
|
||||
}
|
||||
|
||||
/// The equipment a mob shows (ClientboundSetEquipmentPacket slots: main hand,
|
||||
/// off hand, feet, legs, chest, head, body, saddle).
|
||||
fn mob_equipment(
|
||||
@@ -997,6 +1070,7 @@ impl Game<'_> {
|
||||
&mut e.meta,
|
||||
&mut e.defaults,
|
||||
);
|
||||
mob_freeze_meta(m, &mut e.meta, &mut e.defaults);
|
||||
mob_equipment(m, hub, &mut e.equipment);
|
||||
self.mob_attributes(m, &mut e.attributes);
|
||||
e.leash = leash;
|
||||
|
||||
@@ -2333,6 +2333,15 @@ impl Game<'_> {
|
||||
speed,
|
||||
}) => self.landing_dust(Some(host), state, position, count, speed),
|
||||
MotionEvent::Fall(event) => self.landing_block_updates(&event),
|
||||
// LivingEntity.baseTick's entity event 67, to every client
|
||||
// around, the guest's own included; this window draws it too.
|
||||
MotionEvent::Drown => {
|
||||
if let Some(g) = host.hub.guest(conn) {
|
||||
host.hub
|
||||
.entity_event(g.entity_id, super::combat::DROWN_EVENT, at);
|
||||
}
|
||||
self.drown_particles(at, [0.0; 3]);
|
||||
}
|
||||
// HoneyBlock.maybeDoSlideEffects: the sound reaches the
|
||||
// others (Player.playSound excludes the player, whose client
|
||||
// plays it), the entity event 53 everyone around.
|
||||
|
||||
@@ -1926,6 +1926,22 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
|
||||
for (index, _, value) in &p.values {
|
||||
match (index, value) {
|
||||
// Entity.DATA_TICKS_FROZEN: isFullyFrozen shakes it.
|
||||
(7, Value::Int(ticks)) => m.ticks_frozen = *ticks,
|
||||
// Strider.DATA_SUFFOCATING (after AgeableMob's two
|
||||
// and DATA_BOOST_TIME): a cold strider shakes.
|
||||
(19, Value::Bool(cold))
|
||||
if m.species() == horizon_client::mobs::Species::Strider =>
|
||||
{
|
||||
m.extra.flag = *cold;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// LivingEntity.DATA_LIVING_ENTITY_FLAGS: for another player
|
||||
// too, remote_mob_data's apply reads index 8 above.
|
||||
let mannequin = self
|
||||
@@ -2161,6 +2177,9 @@ impl Game<'_> {
|
||||
if p.event == super::totem::TOTEM_EVENT {
|
||||
self.remote_totem(p.id);
|
||||
}
|
||||
if p.event == super::combat::DROWN_EVENT {
|
||||
self.remote_drown(p.id);
|
||||
}
|
||||
// Entity event 53: the honey slide particles of a player
|
||||
// sliding down a honey block (HoneyBlock.showSlideParticles).
|
||||
if p.event == 53 {
|
||||
@@ -3220,6 +3239,7 @@ impl Game<'_> {
|
||||
self.border.tick();
|
||||
self.player_border();
|
||||
self.tick_remote_entities(running);
|
||||
self.tick_remote_guardian_eyes(running);
|
||||
// ClientLevel.tickBlockEntities: chest lids, shulker boxes, bells,
|
||||
// and the moving pistons a block event's client-side moveBlocks made
|
||||
// (their progress advances between the server's block updates).
|
||||
@@ -3509,6 +3529,43 @@ impl Game<'_> {
|
||||
}
|
||||
/// ClientLevel.tickEntities; a frozen level only ticks the players
|
||||
/// (`TickRateManager.isEntityFrozen`).
|
||||
/// `GuardianRenderer.getEntityToLookAt`: a guardian's eye follows its
|
||||
/// synched attack target, else the camera.
|
||||
fn tick_remote_guardian_eyes(&mut self, running: bool) {
|
||||
use horizon_client::mobs::{Species, Who, guardian};
|
||||
if !running {
|
||||
return;
|
||||
}
|
||||
let camera = self.player.as_ref().map(|p| {
|
||||
[
|
||||
p.position.x,
|
||||
p.position.y + f64::from(p.dimensions.eye_height),
|
||||
p.position.z,
|
||||
]
|
||||
});
|
||||
let looks: Vec<_> = self
|
||||
.mobs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, m)| {
|
||||
matches!(m.species(), Species::Guardian | Species::ElderGuardian) && m.alive()
|
||||
})
|
||||
.filter_map(|(i, m)| {
|
||||
let look = match m.ai.target.filter(|_| m.extra.flag) {
|
||||
Some(Who::Mob(id)) => self
|
||||
.mobs
|
||||
.iter()
|
||||
.find(|t| t.id == id)
|
||||
.map(|t| [t.position.x, t.eye_y(), t.position.z]),
|
||||
_ => camera,
|
||||
};
|
||||
look.map(|look| (i, look))
|
||||
})
|
||||
.collect();
|
||||
for (i, look) in looks {
|
||||
guardian::look_at(&mut self.mobs[i], look);
|
||||
}
|
||||
}
|
||||
fn tick_remote_entities(&mut self, running: bool) {
|
||||
if running {
|
||||
self.tick_text_displays();
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
//! 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, armadillo, bat, camel, sniffer, sync, tame};
|
||||
use horizon_client::mobs::{
|
||||
Mob, Species, Who, armadillo, bat, camel, creaking, sniffer, sync, tame,
|
||||
};
|
||||
use horizon_client::particles::{ParticleOptions, ParticleType};
|
||||
use horizon_protocol::entity_data::{Particle, ParticleData, Value};
|
||||
use horizon_protocol::registry::Builtin;
|
||||
@@ -124,6 +126,23 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_enti
|
||||
(Species::Camel | Species::CamelHusk, 20, Value::Long(tick)) => {
|
||||
camel::set_synced_pose_tick(m, *tick);
|
||||
}
|
||||
// Vex.DATA_FLAGS_ID: charging in bit 0.
|
||||
(Species::Vex, 16, Value::Byte(flags)) => m.extra.flag = flags & 1 != 0,
|
||||
// Creaking.CAN_MOVE, IS_ACTIVE and IS_TEARING_DOWN.
|
||||
(Species::Creaking, 16, Value::Bool(can_move)) => m.extra.flag2 = !*can_move,
|
||||
(Species::Creaking, 17, Value::Bool(active)) => m.extra.flag = *active,
|
||||
(Species::Creaking, 18, Value::Bool(true)) => creaking::set_tearing_down(m),
|
||||
// Allay.DATA_DANCING and DATA_CAN_DUPLICATE (a cooldown running
|
||||
// is any non-zero `egg_time`).
|
||||
(Species::Allay, 16, Value::Bool(dancing)) => m.extra.flag = *dancing,
|
||||
(Species::Allay, 17, Value::Bool(can)) => m.extra.egg_time = i32::from(!*can),
|
||||
// Axolotl.DATA_PLAYING_DEAD (after DATA_VARIANT): the factors
|
||||
// ease in `sync::client_tick`.
|
||||
(Species::Axolotl, 19, Value::Bool(dead)) => m.extra.axolotl.playing_dead = *dead,
|
||||
// CopperGolem.COPPER_GOLEM_STATE (after DATA_WEATHER_STATE).
|
||||
(Species::CopperGolem, 17, Value::Id(state)) => {
|
||||
m.extra.variant3 = (*state).clamp(0, 4) as u8;
|
||||
}
|
||||
// Pillager.IS_CHARGING_CROSSBOW: the charge pose (Raider's
|
||||
// IS_CELEBRATING takes 16).
|
||||
(Species::Pillager, 17, Value::Bool(charging)) => m.extra.flag = *charging,
|
||||
|
||||
@@ -529,6 +529,8 @@ pub enum DamageKind {
|
||||
InWall,
|
||||
Thorns,
|
||||
SonicBoom,
|
||||
/// `freeze`: a fully frozen mob in powder snow.
|
||||
Freeze,
|
||||
/// `fell_out_of_world`: below the world's floor.
|
||||
OutOfWorld,
|
||||
}
|
||||
@@ -598,6 +600,7 @@ impl Damage {
|
||||
| DamageKind::InWall
|
||||
| DamageKind::Generic
|
||||
| DamageKind::SonicBoom
|
||||
| DamageKind::Freeze
|
||||
| DamageKind::OutOfWorld
|
||||
)
|
||||
}
|
||||
@@ -622,6 +625,7 @@ impl Damage {
|
||||
| DamageKind::Cactus
|
||||
| DamageKind::Generic
|
||||
| DamageKind::InWall
|
||||
| DamageKind::Freeze
|
||||
| DamageKind::OutOfWorld
|
||||
)
|
||||
}
|
||||
@@ -909,6 +913,12 @@ pub enum MobEvent {
|
||||
mob: u32,
|
||||
at: [f64; 3],
|
||||
},
|
||||
/// `LivingEntity.baseTick`'s drowning damage: entity event 67, the
|
||||
/// clients' `makeDrownParticles`.
|
||||
Drown {
|
||||
mob: u32,
|
||||
at: [f64; 3],
|
||||
},
|
||||
/// `Level.broadcastEntityEvent` for a mob: guests run `sync::entity_event`.
|
||||
EntityEvent {
|
||||
mob: u32,
|
||||
@@ -1360,6 +1370,10 @@ impl Mob {
|
||||
.max((f64::from(ticks) * self.burning_time()).ceil() as i32);
|
||||
self.ticks_frozen = 0;
|
||||
}
|
||||
/// `Entity.isFullyFrozen`.
|
||||
pub fn is_fully_frozen(&self) -> bool {
|
||||
self.ticks_frozen >= crate::motion::PlayerMotion::TICKS_REQUIRED_TO_FREEZE
|
||||
}
|
||||
|
||||
/// What other mobs see of this one this tick (`player`: the player's
|
||||
/// UUID, which villagers' reputation is keyed by).
|
||||
@@ -1844,6 +1858,15 @@ impl Mob {
|
||||
{
|
||||
amount *= 0.75;
|
||||
}
|
||||
// LivingEntity.hurtServer: `#freeze_hurts_extra_types` take five times.
|
||||
if source.kind == DamageKind::Freeze
|
||||
&& matches!(
|
||||
self.species(),
|
||||
Species::Strider | Species::Blaze | Species::MagmaCube
|
||||
)
|
||||
{
|
||||
amount *= 5.0;
|
||||
}
|
||||
let (worn, worn_toughness) = self.worn_armor();
|
||||
if !source.bypasses_armor() && self.kind.armor + worn > 0.0 {
|
||||
// CombatRules.getDamageAfterAbsorb
|
||||
|
||||
@@ -555,6 +555,10 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
m.air -= 1;
|
||||
if m.air == -20 {
|
||||
m.air = 0;
|
||||
events.push(MobEvent::Drown {
|
||||
mob: m.id,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
});
|
||||
m.damage(2.0, Damage::of(DamageKind::Drown));
|
||||
}
|
||||
} else if m.air < 300 {
|
||||
@@ -566,6 +570,7 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
{
|
||||
m.damage(1.0, Damage::of(DamageKind::Drown));
|
||||
}
|
||||
freeze_tick(m, w);
|
||||
}
|
||||
tick_effects(m);
|
||||
if m.species() == Species::Illusioner {
|
||||
@@ -595,6 +600,57 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
// Entity.baseTick ends with Leashable.tickLeash.
|
||||
super::leash::tick(m, w, events);
|
||||
}
|
||||
/// `LivingEntity.aiStep`'s "freezing" with `InsideBlockEffectType.FREEZE`:
|
||||
/// powder snow builds `ticks_frozen` up, anywhere else it melts twice as
|
||||
/// fast, and a fully frozen mob takes one freeze damage every 40 ticks.
|
||||
fn freeze_tick(m: &mut Mob, w: &MobWorld) {
|
||||
let in_snow = in_powder_snow(m, w);
|
||||
if !in_snow && m.ticks_frozen == 0 {
|
||||
return;
|
||||
}
|
||||
let can_freeze = can_freeze(m, w);
|
||||
if in_snow && can_freeze {
|
||||
m.ticks_frozen =
|
||||
(m.ticks_frozen + 1).min(crate::motion::PlayerMotion::TICKS_REQUIRED_TO_FREEZE);
|
||||
} else {
|
||||
m.ticks_frozen = (m.ticks_frozen - 2).max(0);
|
||||
}
|
||||
if m.age.is_multiple_of(40) && m.is_fully_frozen() && can_freeze {
|
||||
m.damage(1.0, Damage::of(DamageKind::Freeze));
|
||||
}
|
||||
}
|
||||
/// Whether the mob's box (shrunk by `1.0E-5`, as in `Entity.checkInsideBlocks`)
|
||||
/// touches powder snow.
|
||||
fn in_powder_snow(m: &Mob, w: &MobWorld) -> bool {
|
||||
let b = m.bounds().deflate(Vec3::new(1e-5, 1e-5, 1e-5));
|
||||
let (min, max) = (b.min_position(), b.max_position());
|
||||
for x in min.x.floor() as i32..=max.x.floor() as i32 {
|
||||
for y in min.y.floor() as i32..=max.y.floor() as i32 {
|
||||
for z in min.z.floor() as i32..=max.z.floor() as i32 {
|
||||
if &*w.facts.get(w.world.block(x, y, z)).name == "minecraft:powder_snow" {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
/// `LivingEntity.canFreeze`: not a `#freeze_immune_entity_types` mob and no
|
||||
/// worn piece in `#freeze_immune_wearables`.
|
||||
fn can_freeze(m: &Mob, w: &MobWorld) -> bool {
|
||||
if w.data
|
||||
.entity_has("minecraft:freeze_immune_entity_types", &m.kind.id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let immune = w
|
||||
.items
|
||||
.and_then(|i| i.item_tags.get("minecraft:freeze_immune_wearables"));
|
||||
![&m.extra.head, &m.extra.chest, &m.extra.legs, &m.extra.feet]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.any(|item| immune.is_some_and(|t| t.contains(&**item)))
|
||||
}
|
||||
/// `Mob.playAmbientSound` on demand: a spawn egg or a mob bucket just placed `m`.
|
||||
pub fn ambient_sound(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
play_ambient(m, w, events);
|
||||
|
||||
@@ -133,6 +133,11 @@ pub fn ai_step(m: &mut Mob) {
|
||||
if m.extra.egg_time > 0 {
|
||||
m.extra.egg_time -= 1;
|
||||
}
|
||||
animate(m);
|
||||
}
|
||||
/// `Allay.tick`'s client half: the hold and spin clocks (the server's and a
|
||||
/// client's).
|
||||
pub fn animate(m: &mut Mob) {
|
||||
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);
|
||||
|
||||
@@ -70,6 +70,16 @@ pub fn sound(m: &Mob, what: &str) -> &'static str {
|
||||
}
|
||||
/// `CopperGolem.setupAnimationStates` (client) and the sound of the head spin.
|
||||
pub fn ai_step(m: &mut Mob, _w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if animate(m) {
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
events.push(MobEvent::LocalSound(sound(m, "spin"), at, 1.0, 1.0));
|
||||
}
|
||||
}
|
||||
/// `CopperGolem.setupAnimationStates`, for the server and a client alike;
|
||||
/// returns whether the head spin sound plays now (a client's sound is the
|
||||
/// server's `LocalSound`).
|
||||
pub fn animate(m: &mut Mob) -> bool {
|
||||
let mut spin = false;
|
||||
let age = m.age as f32;
|
||||
let state = m.extra.variant3;
|
||||
let st = &mut m.anim.states;
|
||||
@@ -93,8 +103,7 @@ pub fn ai_step(m: &mut Mob, _w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
m.extra.ints[0] = tick + 200 + r.next_int_bound(40).unwrap_or(0);
|
||||
}
|
||||
if tick == m.extra.ints[0] + 10 {
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
events.push(MobEvent::LocalSound(sound(m, "spin"), at, 1.0, 1.0));
|
||||
spin = true;
|
||||
m.extra.ints[0] = 0;
|
||||
}
|
||||
}
|
||||
@@ -106,6 +115,7 @@ pub fn ai_step(m: &mut Mob, _w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
spin
|
||||
}
|
||||
/// `CopperGolem.updateWeathering` on the level random: the first tick sets
|
||||
/// the next weathering tick, which advances the weather state; once
|
||||
|
||||
@@ -152,8 +152,26 @@ pub fn sway(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
}
|
||||
/// `Creaking.doHurtTarget`: the attack animation (the sound is the
|
||||
/// `playAttackSound` that ends `Mob.doHurtTarget`).
|
||||
pub fn on_attack(m: &mut Mob, _events: &mut Vec<MobEvent>) {
|
||||
pub fn on_attack(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
m.extra.ints[ATTACKING] = ATTACK_TICKS;
|
||||
broadcast(m, 4, events);
|
||||
}
|
||||
/// `Level.broadcastEntityEvent` for a creaking (guests run `entity_event`).
|
||||
fn broadcast(m: &Mob, event: i8, events: &mut Vec<MobEvent>) {
|
||||
events.push(MobEvent::EntityEvent {
|
||||
mob: m.id,
|
||||
event,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
});
|
||||
}
|
||||
/// `Creaking.handleEntityEvent` on a client: 66 the invulnerability flash,
|
||||
/// 4 the attack swing (the sounds are the server's).
|
||||
pub fn entity_event(m: &mut Mob, event: u8) {
|
||||
match event {
|
||||
66 => m.extra.ints[INVULNERABLE] = INVULNERABILITY_TICKS,
|
||||
4 => m.extra.ints[ATTACKING] = ATTACK_TICKS,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// The heart this creaking is bound to protects it (`isProtector`); a link
|
||||
/// read from a save is trusted until the heart resolves it.
|
||||
@@ -176,15 +194,12 @@ pub fn update(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if heart_bound(m) && m.alive() && !protected(m, w) {
|
||||
m.health = 0.0;
|
||||
}
|
||||
for slot in [INVULNERABLE, ATTACKING] {
|
||||
if m.extra.ints[slot] > 0 {
|
||||
m.extra.ints[slot] -= 1;
|
||||
}
|
||||
// hurtServer set the invulnerability clock since the last tick: entity
|
||||
// event 66.
|
||||
if m.extra.ints[INVULNERABLE] == INVULNERABILITY_TICKS {
|
||||
broadcast(m, 66, events);
|
||||
}
|
||||
let age = m.age as f32;
|
||||
m.anim.states[0].animate_when(m.extra.ints[ATTACKING] > 0, age);
|
||||
m.anim.states[1].animate_when(m.extra.ints[INVULNERABLE] > 0, age);
|
||||
m.anim.states[2].animate_when(tearing_down(m), age);
|
||||
animate(m);
|
||||
if m.extra.counter & HURT != 0 {
|
||||
// hurtServer: sway, and the heart reacts to a player's hit.
|
||||
if protected(m, w) {
|
||||
@@ -200,18 +215,6 @@ pub fn update(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
}
|
||||
m.extra.counter &= !(HURT | HURT_BY_PLAYER);
|
||||
}
|
||||
// checkEyeBlink: the eyes of a creaking falling apart flicker.
|
||||
if m.death_time > m.extra.ints[NEXT_FLICKER] {
|
||||
let glowing = m.extra.ints[EYES] != 0;
|
||||
let (lo, hi) = if glowing {
|
||||
(2, 8)
|
||||
} else {
|
||||
(m.death_time / 4, m.death_time / 2)
|
||||
};
|
||||
let span = (hi - lo + 1).max(1);
|
||||
m.extra.ints[NEXT_FLICKER] = m.death_time + lo + m.random.next_int_bound(span).unwrap_or(0);
|
||||
m.extra.ints[EYES] = i32::from(!glowing);
|
||||
}
|
||||
if !m.alive() {
|
||||
return;
|
||||
}
|
||||
@@ -226,6 +229,31 @@ pub fn update(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
m.extra.flag2 = !now;
|
||||
}
|
||||
}
|
||||
/// The clocks and keyframe states `Creaking.aiStep`, `setupAnimationStates`
|
||||
/// and `checkEyeBlink` run (the server's and a client's).
|
||||
pub fn animate(m: &mut Mob) {
|
||||
for slot in [INVULNERABLE, ATTACKING] {
|
||||
if m.extra.ints[slot] > 0 {
|
||||
m.extra.ints[slot] -= 1;
|
||||
}
|
||||
}
|
||||
let age = m.age as f32;
|
||||
m.anim.states[0].animate_when(m.extra.ints[ATTACKING] > 0, age);
|
||||
m.anim.states[1].animate_when(m.extra.ints[INVULNERABLE] > 0, age);
|
||||
m.anim.states[2].animate_when(tearing_down(m), age);
|
||||
// checkEyeBlink: the eyes of a creaking falling apart flicker.
|
||||
if m.death_time > m.extra.ints[NEXT_FLICKER] {
|
||||
let glowing = m.extra.ints[EYES] != 0;
|
||||
let (lo, hi) = if glowing {
|
||||
(2, 8)
|
||||
} else {
|
||||
(m.death_time / 4, m.death_time / 2)
|
||||
};
|
||||
let span = (hi - lo + 1).max(1);
|
||||
m.extra.ints[NEXT_FLICKER] = m.death_time + lo + m.random.next_int_bound(span).unwrap_or(0);
|
||||
m.extra.ints[EYES] = i32::from(!glowing);
|
||||
}
|
||||
}
|
||||
/// `Mob.stopInPlace`.
|
||||
pub fn stop_in_place(m: &mut Mob) {
|
||||
m.nav_stop();
|
||||
|
||||
@@ -157,12 +157,16 @@ impl Goal for OfferFlower {
|
||||
fn can_continue(&mut self, _: &mut Mob, _: &mut Cx) -> bool {
|
||||
self.ticks > 0
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
self.ticks = 400;
|
||||
m.extra.counter = 400;
|
||||
// IronGolem.offerFlower(true): entity event 11.
|
||||
entity_event(m, 11, cx);
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
m.extra.counter = 0;
|
||||
// IronGolem.offerFlower(false): entity event 34.
|
||||
entity_event(m, 34, cx);
|
||||
// A copper golem the offer ran out beside takes the poppy on its
|
||||
// antenna (#accepts_iron_golem_gift) when it has none.
|
||||
if self.ticks == 0
|
||||
@@ -198,6 +202,7 @@ impl Goal for OfferFlower {
|
||||
/// the target is thrown upward.
|
||||
pub fn iron_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
m.extra.anim_ticks = 10;
|
||||
entity_event(m, 4, cx);
|
||||
let attack = m.attrs.attack_damage;
|
||||
let amount = if attack as i32 > 0 {
|
||||
attack / 2.0 + m.random.next_int_bound(attack as i32).unwrap_or(0) as f32
|
||||
@@ -224,6 +229,33 @@ pub fn iron_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
1.0,
|
||||
));
|
||||
}
|
||||
/// `Level.broadcastEntityEvent` for an iron golem (guests run `client_event`).
|
||||
fn entity_event(m: &Mob, event: i8, cx: &mut Cx) {
|
||||
cx.events.push(MobEvent::EntityEvent {
|
||||
mob: m.id,
|
||||
event,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
});
|
||||
}
|
||||
/// `IronGolem.handleEntityEvent` on a client: 4 the swing, 11 and 34 the
|
||||
/// poppy offer starting and stopping.
|
||||
pub fn client_event(m: &mut Mob, event: u8) {
|
||||
match event {
|
||||
4 => m.extra.anim_ticks = 10,
|
||||
11 => m.extra.counter = 400,
|
||||
34 => m.extra.counter = 0,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// The swing and offer clocks of `IronGolem.aiStep` on a client.
|
||||
pub fn client_tick(m: &mut Mob) {
|
||||
if m.extra.anim_ticks > 0 {
|
||||
m.extra.anim_ticks -= 1;
|
||||
}
|
||||
if m.extra.counter > 0 {
|
||||
m.extra.counter -= 1;
|
||||
}
|
||||
}
|
||||
/// `IronGolem.aiStep` timers and anger.
|
||||
pub fn iron_ai_step(m: &mut Mob) {
|
||||
if m.extra.anim_ticks > 0 {
|
||||
|
||||
@@ -214,12 +214,9 @@ pub fn travel(m: &mut Mob, w: &MobWorld, input: Vec3, events: &mut Vec<MobEvent>
|
||||
}
|
||||
true
|
||||
}
|
||||
/// `Guardian.aiStep`: the client animations, air, flopping on land, the
|
||||
/// beam's clock, and the spikes' thorns.
|
||||
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if !m.alive() {
|
||||
return;
|
||||
}
|
||||
/// `Guardian.aiStep`'s `clientSideTailAnimation` and
|
||||
/// `clientSideSpikesAnimation` (the server's and a client's).
|
||||
pub fn tail_and_spikes(m: &mut Mob) {
|
||||
let moving = m.extra.flag2;
|
||||
let in_water = m.fluids.in_water;
|
||||
// Tail and spikes (clientSideTailAnimation / clientSideSpikesAnimation).
|
||||
@@ -244,6 +241,16 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
} else {
|
||||
a.v[SPIKES] += (1.0 - a.v[SPIKES]) * 0.06;
|
||||
}
|
||||
}
|
||||
/// `Guardian.aiStep`: the client animations, air, flopping on land, the
|
||||
/// beam's clock, and the spikes' thorns.
|
||||
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if !m.alive() {
|
||||
return;
|
||||
}
|
||||
let moving = m.extra.flag2;
|
||||
let in_water = m.fluids.in_water;
|
||||
tail_and_spikes(m);
|
||||
client_tick(m);
|
||||
if in_water {
|
||||
m.air = 300;
|
||||
@@ -276,17 +283,7 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
None => w.player.as_ref().map(|p| p.eye),
|
||||
};
|
||||
if let Some(look) = look {
|
||||
m.anim.v[EYE_Y] = if look[1] - m.eye_y() > 0.0 { 0.0 } else { 1.0 };
|
||||
let yaw = m.head_yaw.to_radians();
|
||||
let pitch = m.head_pitch.to_radians();
|
||||
let view = [-yaw.msin() * pitch.mcos(), yaw.mcos() * pitch.mcos()];
|
||||
let d = [m.position.x - look[0], m.position.z - look[2]];
|
||||
let len = (d[0] * d[0] + d[1] * d[1]).sqrt().max(1e-9);
|
||||
let (dx, dz) = ((d[0] / len) as f32, (d[1] / len) as f32);
|
||||
// Vec3.yRot(pi / 2) of the direction from the target.
|
||||
let side = [dz, -dx];
|
||||
let dot = view[0] * side[0] + view[1] * side[1];
|
||||
m.anim.v[EYE_X] = dot.abs().sqrt() * 2.0 * dot.signum();
|
||||
look_at(m, look);
|
||||
}
|
||||
// Guardian.hurtServer: a still guardian's spikes hurt a melee attacker.
|
||||
if m.hurt_time == 10
|
||||
@@ -317,6 +314,21 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `GuardianModel.setupAnim`'s eye: it follows `look` (the attack target's
|
||||
/// eye, else the camera's), from where the guardian faces.
|
||||
pub fn look_at(m: &mut Mob, look: [f64; 3]) {
|
||||
m.anim.v[EYE_Y] = if look[1] - m.eye_y() > 0.0 { 0.0 } else { 1.0 };
|
||||
let yaw = m.head_yaw.to_radians();
|
||||
let pitch = m.head_pitch.to_radians();
|
||||
let view = [-yaw.msin() * pitch.mcos(), yaw.mcos() * pitch.mcos()];
|
||||
let d = [m.position.x - look[0], m.position.z - look[2]];
|
||||
let len = (d[0] * d[0] + d[1] * d[1]).sqrt().max(1e-9);
|
||||
let (dx, dz) = ((d[0] / len) as f32, (d[1] / len) as f32);
|
||||
// Vec3.yRot(pi / 2) of the direction from the target.
|
||||
let side = [dz, -dx];
|
||||
let dot = view[0] * side[0] + view[1] * side[1];
|
||||
m.anim.v[EYE_X] = dot.abs().sqrt() * 2.0 * dot.signum();
|
||||
}
|
||||
/// `ElderGuardian.customServerAiStep`: every minute, mining fatigue III for
|
||||
/// players within 50 blocks; a home within 16 blocks.
|
||||
pub fn elder_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
|
||||
@@ -469,6 +469,12 @@ fn find_piglin_repellent(m: &Mob, w: &MobWorld) -> Option<[i32; 3]> {
|
||||
/// `HoglinBase.hurtAndThrowTarget`.
|
||||
pub fn hoglin_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
m.extra.anim_ticks = 10;
|
||||
// Entity event 4: clients start the headbutt.
|
||||
cx.events.push(MobEvent::EntityEvent {
|
||||
mob: m.id,
|
||||
event: 4,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
});
|
||||
let attack = m.attrs.attack_damage;
|
||||
let amount = if !m.is_baby() && attack as i32 > 0 {
|
||||
attack / 2.0 + m.random.next_int_bound(attack as i32).unwrap_or(0) as f32
|
||||
@@ -603,6 +609,19 @@ pub fn piglin_pose(
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// `Hoglin.handleEntityEvent` and `Zoglin`'s event 4 on a client: the
|
||||
/// headbutt, which `aiStep` then counts down.
|
||||
pub fn client_event(m: &mut Mob, event: u8) {
|
||||
if event == 4 {
|
||||
m.extra.anim_ticks = 10;
|
||||
}
|
||||
}
|
||||
/// The headbutt's countdown (`Hoglin.aiStep`, `Zoglin.aiStep`) on a client.
|
||||
pub fn client_tick(m: &mut Mob) {
|
||||
if m.extra.anim_ticks > 0 {
|
||||
m.extra.anim_ticks -= 1;
|
||||
}
|
||||
}
|
||||
/// `HoglinModel.setupAnim`.
|
||||
pub fn hoglin_anim(m: &Mob, s: &State, p: &mut Poses) {
|
||||
let (pos, sp) = (s.pos, s.speed);
|
||||
|
||||
@@ -49,9 +49,14 @@ pub fn register(m: &mut Mob) {
|
||||
pub fn immobile(m: &Mob) -> bool {
|
||||
m.extra.counter > 0 || m.extra.counter2 > 0 || m.extra.anim_ticks > 0
|
||||
}
|
||||
/// `Ravager.doHurtTarget`: the bite animation.
|
||||
/// `Ravager.doHurtTarget`: the bite animation (entity event 4 for clients).
|
||||
pub fn on_attack(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
m.extra.counter = 10;
|
||||
events.push(MobEvent::EntityEvent {
|
||||
mob: m.id,
|
||||
event: 4,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
});
|
||||
events.push(MobEvent::Sound(
|
||||
"entity.ravager.attack",
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
@@ -67,6 +72,12 @@ pub fn blocked(m: &mut Mob, events: &mut Vec<MobEvent>) -> bool {
|
||||
}
|
||||
if m.random.next_double() < 0.5 {
|
||||
m.extra.counter2 = 40;
|
||||
// Entity event 39: the stun starts on clients.
|
||||
events.push(MobEvent::EntityEvent {
|
||||
mob: m.id,
|
||||
event: 39,
|
||||
at: [m.position.x, m.position.y, m.position.z],
|
||||
});
|
||||
events.push(MobEvent::Sound(
|
||||
"entity.ravager.stunned",
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
@@ -155,6 +166,34 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `Ravager.handleEntityEvent` 4 and 39 on a client.
|
||||
pub fn entity_event(m: &mut Mob, event: u8) {
|
||||
match event {
|
||||
4 => m.extra.counter = 10,
|
||||
39 => m.extra.counter2 = 40,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// `Ravager.aiStep`'s clocks on a client: the bite and roar run down, and
|
||||
/// the end of the stun starts the roar (the sounds, particles and the roar's
|
||||
/// damage are the server's).
|
||||
pub fn client_tick(m: &mut Mob) {
|
||||
if !m.alive() {
|
||||
return;
|
||||
}
|
||||
if m.extra.anim_ticks > 0 {
|
||||
m.extra.anim_ticks -= 1;
|
||||
}
|
||||
if m.extra.counter > 0 {
|
||||
m.extra.counter -= 1;
|
||||
}
|
||||
if m.extra.counter2 > 0 {
|
||||
m.extra.counter2 -= 1;
|
||||
if m.extra.counter2 == 0 {
|
||||
m.extra.anim_ticks = 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `Ravager.roar`: 6 damage to everything but illagers within 4 blocks,
|
||||
/// and a strong knockback (players too, through the client).
|
||||
fn roar(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
|
||||
@@ -833,10 +833,15 @@ pub fn base_transform_at(m: &Mob, alpha: f32, origin: glam::Mat4) -> glam::Mat4
|
||||
base *= species_scale(m, alpha);
|
||||
base * glam::Mat4::from_translation(glam::Vec3::new(0.0, -1.501, 0.0))
|
||||
}
|
||||
/// `LivingEntityRenderer.isShaking`: converting zombies, piglins and
|
||||
/// hoglins, and a zombie villager being cured.
|
||||
/// `LivingEntityRenderer.isShaking`: a fully frozen mob (the skeleton's own
|
||||
/// `isShaking` is its stray conversion only), converting zombies, piglins
|
||||
/// and hoglins, a zombie villager being cured and a cold strider.
|
||||
fn shaking(m: &Mob) -> bool {
|
||||
if m.is_fully_frozen() && m.species() != Species::Skeleton {
|
||||
return true;
|
||||
}
|
||||
match m.species() {
|
||||
Species::Strider => super::strider::suffocating(m),
|
||||
Species::ZombieVillager => super::zombie_villager::is_converting(m),
|
||||
Species::Zombie | Species::Husk => m.extra.counter2 > 0,
|
||||
Species::Piglin | Species::PiglinBrute | Species::Hoglin => {
|
||||
|
||||
@@ -297,6 +297,7 @@ pub fn accepts_damage(m: &mut Mob, source: &Damage, amount: f32) -> bool {
|
||||
| DamageKind::Fall
|
||||
| DamageKind::Sting
|
||||
| DamageKind::Cactus
|
||||
| DamageKind::Freeze
|
||||
);
|
||||
if immune {
|
||||
if let Some(from) = source.from {
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
//! 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, armadillo, breeze, camel, shulker, sniffer, warden};
|
||||
use super::{
|
||||
Mob, Species, allay, armadillo, axolotl, breeze, camel, copper_golem, creaking, golem,
|
||||
guardian, piglin, ravager, shulker, sniffer, warden,
|
||||
};
|
||||
|
||||
// `Pose.id` of the poses mobs take.
|
||||
pub const STANDING: u8 = 0;
|
||||
@@ -60,6 +63,23 @@ pub fn client_tick(m: &mut Mob, game_time: i64) {
|
||||
Species::Breeze => breeze::ai_step(m),
|
||||
Species::Camel | Species::CamelHusk => camel::client_tick(m, game_time),
|
||||
Species::Shulker => shulker::client_tick(m),
|
||||
Species::Ravager => ravager::client_tick(m),
|
||||
Species::Hoglin | Species::Zoglin => piglin::client_tick(m),
|
||||
Species::IronGolem => golem::client_tick(m),
|
||||
Species::Creaking => creaking::animate(m),
|
||||
Species::Allay => {
|
||||
m.anim.vo = m.anim.v;
|
||||
allay::animate(m);
|
||||
}
|
||||
Species::Axolotl => axolotl::tick_animation(m),
|
||||
Species::Guardian | Species::ElderGuardian => {
|
||||
m.anim.vo = m.anim.v;
|
||||
guardian::tail_and_spikes(m);
|
||||
}
|
||||
// The head spin's sound is the server's.
|
||||
Species::CopperGolem if !m.no_ai => {
|
||||
copper_golem::animate(m);
|
||||
}
|
||||
Species::Armadillo => armadillo::tick(m),
|
||||
_ => {}
|
||||
}
|
||||
@@ -72,8 +92,8 @@ pub fn entity_event(m: &mut Mob, event: u8) {
|
||||
armadillo::entity_event(m, event);
|
||||
}
|
||||
let age = m.age as f32;
|
||||
if m.species() == Species::Warden {
|
||||
match event {
|
||||
match m.species() {
|
||||
Species::Warden => match event {
|
||||
// Attack: the roar ends, the swing starts.
|
||||
4 => {
|
||||
m.anim.states[warden::ROAR].stop();
|
||||
@@ -84,6 +104,11 @@ pub fn entity_event(m: &mut Mob, event: u8) {
|
||||
// The sonic boom.
|
||||
62 => m.anim.states[warden::SONIC_BOOM].start(age),
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
Species::Ravager => ravager::entity_event(m, event),
|
||||
Species::Hoglin | Species::Zoglin => piglin::client_event(m, event),
|
||||
Species::IronGolem => golem::client_event(m, event),
|
||||
Species::Creaking => creaking::entity_event(m, event),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,6 +796,12 @@ pub fn client_tick(m: &mut Mob) {
|
||||
animate(m, &mut Vec::new());
|
||||
}
|
||||
fn animate(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
let digging_clock = |m: &Mob, slot: usize| {
|
||||
m.anim.states[slot]
|
||||
.millis(m.age as f32)
|
||||
|
||||
Reference in New Issue
Block a user