Merge pull request #2685 from kacpherek/fix/mob-state-sync-3

🤖 Agent: Merged by Ludovic's AI agent (Claude, contrib-gate-19) after the contribution gate. Checked against vanilla 26.3 and proven in union/cg19-r2 and union/cg19-r3. After this batch it was merged with main again and proven in union/cg19-r4 (clippy, 1726 tests, 121/121 harnesses). Thanks @kacpherek.
This commit is contained in:
Ludovic Marie
2026-10-27 19:09:21 +01:00
committed by GitHub
14 changed files with 351 additions and 25 deletions
+3 -1
View File
@@ -7774,7 +7774,9 @@ impl Game<'_> {
self.yaw
};
for m in &self.mobs {
if m.fire_ticks > 0 && !m.removed {
// Blaze.isOnFire: a charged blaze burns.
let blazing = m.species() == horizon_client::mobs::Species::Blaze && m.extra.flag;
if (m.fire_ticks > 0 || blazing) && !m.removed {
let at = m.previous.lerp(m.position, alpha);
horizon_client::fire_render::flames(
[at.x, at.y, at.z],
+107 -8
View File
@@ -14,7 +14,7 @@ use horizon_client::{
hub::{BodyFlags, HostEvent, HostState, Hub, HubConfig, TickCtx},
playerdata,
},
mobs::{Mob, Who, leash::Holder},
mobs::{Mob, Species, Who, leash::Holder},
text::Text,
};
use horizon_core::geometry::Vec3;
@@ -168,6 +168,7 @@ pub(super) fn baby_index(kind: &str) -> Option<u8> {
| "minecraft:zombie_villager"
| "minecraft:zombified_piglin"
| "minecraft:hoglin"
| "minecraft:zoglin"
| "minecraft:goat"
| "minecraft:ocelot"
| "minecraft:turtle"
@@ -324,9 +325,13 @@ fn mob_meta(
defaults: &mut Vec<(u8, i32, Value)>,
) {
let kind = m.kind.id.as_str();
// Entity.DATA_SHARED_FLAGS_ID: on fire 0x01, glowing 0x40
// (LivingEntity.updateGlowingStatus).
let shared = i8::from(m.fire_ticks > 0) | i8::from(m.is_currently_glowing()) << 6;
// Entity.DATA_SHARED_FLAGS_ID: on fire 0x01, swimming 0x10 (a drowned
// under water, `Drowned.setSwimming`), invisible 0x20 (the effect's flag)
// and glowing 0x40 (LivingEntity.updateGlowingStatus).
let shared = i8::from(m.fire_ticks > 0)
| i8::from(m.species() == Species::Drowned && m.extra.flag) << 4
| i8::from(m.invisible || horizon_client::mobs::trader::is_invisible(m)) << 5
| i8::from(m.is_currently_glowing()) << 6;
if shared != 0 {
meta.push((0, serializer::BYTE, Value::Byte(shared)));
}
@@ -336,6 +341,12 @@ fn mob_meta(
if pose != 0 {
meta.push((6, serializer::POSE, Value::Id(i32::from(pose))));
}
// LivingEntity.DATA_SLEEPING_POS_ID: the bed a sleeping villager lies in.
if horizon_client::mobs::villager::sleeping(m)
&& let Some(bed) = m.extra.bed
{
meta.push((14, serializer::OPTIONAL_BLOCK_POS, Value::OptPos(Some(bed))));
}
if let Some(name) = &m.custom_name {
meta.push((
2,
@@ -430,8 +441,14 @@ fn mob_meta(
}
defaults.push((17, serializer::INT, Value::Int(0)));
}
// Piglin.DATA_IS_DANCING (after the baby flag and the crossbow charge).
// AbstractPiglin.DATA_IMMUNE_TO_ZOMBIFICATION (16: with the dimension it
// makes it shake) and Piglin.DATA_IS_DANCING (after the baby flag and
// the crossbow charge).
"minecraft:piglin" => {
if e.flag2 {
meta.push((16, serializer::BOOLEAN, Value::Bool(true)));
}
defaults.push((16, serializer::BOOLEAN, Value::Bool(false)));
if e.scratch[0] > 0 {
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
}
@@ -518,10 +535,16 @@ fn mob_meta(
| "minecraft:skeleton_horse"
| "minecraft:zombie_horse"
| "minecraft:camel" => {
// AbstractHorse.DATA_ID_FLAGS: tame 2.
if e.tame {
meta.push((18, serializer::BYTE, Value::Byte(2)));
// AbstractHorse.DATA_ID_FLAGS: tame 2, eating 16 (grazing), standing
// 32 (rearing).
let grazes = horizon_client::mobs::equine::grazes(m.species());
let flags = if e.tame { 2 } else { 0 }
| if grazes && e.flag { 16 } else { 0 }
| if grazes && e.counter > 0 { 32 } else { 0 };
if flags != 0 {
meta.push((18, serializer::BYTE, Value::Byte(flags)));
}
defaults.push((18, serializer::BYTE, Value::Byte(0)));
if kind == "minecraft:horse" {
let v = i32::from(e.variant) | i32::from(e.variant2) << 8;
if v != 0 {
@@ -554,6 +577,15 @@ fn mob_meta(
// Villager.DATA_VILLAGER_DATA and ZombieVillager's (after Zombie's three).
"minecraft:villager" | "minecraft:zombie_villager" => {
use horizon_client::mobs::render::{PROFESSIONS, VILLAGER_TYPES};
if kind == "minecraft:villager" {
unhappy_counter(m, meta, defaults);
} else {
// ZombieVillager.DATA_CONVERTING_ID: the cure's shaking.
if horizon_client::mobs::zombie_villager::is_converting(m) {
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
}
defaults.push((19, serializer::BOOLEAN, Value::Bool(false)));
}
let villager_type = VILLAGER_TYPES[e.variant as usize % VILLAGER_TYPES.len()];
let profession = PROFESSIONS[e.variant2 as usize % PROFESSIONS.len()];
if let (Some(t), Some(p)) = (
@@ -761,6 +793,60 @@ fn mob_meta(
meta.push((17, serializer::BOOLEAN, Value::Bool(true)));
}
defaults.push((17, serializer::BOOLEAN, Value::Bool(false)));
defaults.push((16, serializer::OPTIONAL_BLOCK_STATE, Value::Id(0)));
}
// Zombie.DATA_DROWNED_CONVERSION_ID (after DATA_BABY_ID and
// DATA_SPECIAL_TYPE_ID): the shaking of the conversion under water.
"minecraft:zombie" | "minecraft:husk" => {
if e.counter2 > 0 {
meta.push((18, serializer::BOOLEAN, Value::Bool(true)));
}
defaults.push((18, serializer::BOOLEAN, Value::Bool(false)));
}
// AbstractVillager.DATA_UNHAPPY_COUNTER (after AgeableMob's two).
"minecraft:wandering_trader" => unhappy_counter(m, meta, defaults),
// Hoglin.DATA_IMMUNE_TO_ZOMBIFICATION (after AgeableMob's two) and
// AbstractPiglin's, the first entry of its subclasses (the piglin's is
// in its own arm): with the dimension it makes them shake.
"minecraft:hoglin" | "minecraft:piglin_brute" => {
let index = if kind == "minecraft:hoglin" { 18 } else { 16 };
if e.flag2 {
meta.push((index, serializer::BOOLEAN, Value::Bool(true)));
}
defaults.push((index, serializer::BOOLEAN, Value::Bool(false)));
}
// Blaze.DATA_FLAGS_ID: charged 1, which makes it burn.
"minecraft:blaze" => {
if e.flag {
meta.push((16, serializer::BYTE, Value::Byte(1)));
}
defaults.push((16, serializer::BYTE, Value::Byte(0)));
}
// Turtle.HAS_EGG and LAYING_EGG (after AgeableMob's two).
"minecraft:turtle" => {
if e.flag {
meta.push((18, serializer::BOOLEAN, Value::Bool(true)));
}
if e.flag2 {
meta.push((19, serializer::BOOLEAN, Value::Bool(true)));
}
defaults.push((18, serializer::BOOLEAN, Value::Bool(false)));
defaults.push((19, serializer::BOOLEAN, Value::Bool(false)));
}
// WitherBoss.DATA_TARGET_B and DATA_TARGET_C (after DATA_TARGET_A, the
// main target): the entities the side heads look at, by id.
"minecraft:wither" => {
for (k, index) in [(0, 17), (1, 18)] {
let target = match e.ints[k] {
0 => None,
-1 => player_entity,
id => Some(id),
};
if let Some(target) = target {
meta.push((index, serializer::INT, Value::Int(target)));
}
defaults.push((index, serializer::INT, Value::Int(0)));
}
}
_ => {}
}
@@ -778,6 +864,19 @@ fn mob_meta(
}
}
/// AbstractVillager.DATA_UNHAPPY_COUNTER (after AgeableMob's two): the head
/// shake of a villager saying no counts it down from 40.
fn unhappy_counter(
m: &Mob,
meta: &mut Vec<(u8, i32, Value)>,
defaults: &mut Vec<(u8, i32, Value)>,
) {
if m.extra.ints[0] > 0 {
meta.push((18, serializer::INT, Value::Int(m.extra.ints[0])));
}
defaults.push((18, serializer::INT, Value::Int(0)));
}
/// 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).
+48 -2
View File
@@ -3935,6 +3935,34 @@ impl Game<'_> {
}
}
let game_time = self.world.game_time;
// `AbstractPiglin.isConverting`: the dimension is not piglin safe.
let nether = self.dim == super::Dim::Nether;
// What a wither's side heads can look at, by network entity id: the
// mobs and the player (position and eye height).
let wither_targets: Vec<(i32, [f64; 3], f64)> = if self
.mobs
.iter()
.any(|m| m.species() == horizon_client::mobs::Species::Wither)
{
let own = self
.remote
.as_ref()
.zip(self.eye_position())
.map(|(r, eye)| (r.entity_id, eye, eye[1]));
self.mobs
.iter()
.map(|m| {
(
m.id as i32,
[m.position.x, m.position.y, m.position.z],
m.eye_y(),
)
})
.chain(own)
.collect()
} else {
Vec::new()
};
let Some(r) = self.remote.as_mut() else {
return;
};
@@ -4093,8 +4121,26 @@ impl Game<'_> {
}
// The animation states a server computes in its own `ai_step`.
horizon_client::mobs::sync::client_tick(m, game_time);
if m.species() == horizon_client::mobs::Species::Panda {
horizon_client::mobs::panda::client_tick(m, thundering);
match m.species() {
// WitherBoss.aiStep: the side heads turn toward their targets.
horizon_client::mobs::Species::Wither => {
horizon_client::mobs::wither::client_tick(m, |id| {
wither_targets
.iter()
.find(|t| t.0 == id)
.map(|t| (t.1, t.2))
});
}
// Hoglin and piglin `isConverting` outside the Nether.
horizon_client::mobs::Species::Hoglin
| horizon_client::mobs::Species::Piglin
| horizon_client::mobs::Species::PiglinBrute => {
horizon_client::mobs::piglin::client_converting(m, nether);
}
horizon_client::mobs::Species::Panda => {
horizon_client::mobs::panda::client_tick(m, thundering);
}
_ => {}
}
}
for o in self.orbs.iter_mut().filter(|_| running) {
@@ -5,11 +5,13 @@
use super::Game;
use horizon_client::mobs::render::{PROFESSIONS, VILLAGER_TYPES};
use horizon_client::mobs::{
Mob, Species, Who, armadillo, bat, bee, camel, creaking, finalize, panda, sniffer, sync, tame,
Mob, Species, Who, armadillo, bat, bee, camel, creaking, equine, finalize, illusioner, panda,
sniffer, sync, tame, zombie_villager,
};
use horizon_client::particles::{ParticleOptions, ParticleType};
use horizon_protocol::entity_data::{Particle, ParticleData, Value};
use horizon_protocol::registry::{Builtin, Dynamic};
use horizon_world::registry::BlockStateId;
/// The values `apply` takes from one SetEntityData packet, by vanilla's entry
/// indices (Entity 0..=7, LivingEntity 8..=14, Mob 15, then the subclasses).
@@ -31,7 +33,21 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_enti
// Entity.DATA_SHARED_FLAGS_ID's FLAG_ONFIRE: Entity.isOnFire on a
// 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),
(0, Value::Byte(flags)) => {
m.fire_ticks = i32::from(flags & 1);
// Drowned.setSwimming: the shared flag of swimming.
if species == Species::Drowned {
m.extra.flag = flags & 16 != 0;
}
// The shared flag of invisibility: Entity.isInvisible hides
// the model (an illusioner shows its mirror images).
let invisible = flags & 32 != 0;
if species == Species::Illusioner {
illusioner::set_invisible(m, invisible);
} else if &*m.kind.id != "minecraft:player" {
m.invisible = invisible;
}
}
// 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
@@ -218,6 +234,42 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_enti
(Species::CopperGolem, 16, Value::Id(state)) => {
m.extra.variant = (*state).clamp(0, 3) as u8;
}
// AbstractHorse.DATA_ID_FLAGS: eating 16 and standing 32 (the
// graze and the rear), which `sync::client_tick` animates.
(s, 18, Value::Byte(flags)) if equine::grazes(s) => equine::set_flags(m, *flags as u8),
// Enderman.DATA_CARRY_STATE (0 for none): the block it holds.
(Species::Enderman, 16, Value::Id(state)) => {
m.extra.carried = (*state > 0).then_some(BlockStateId(*state as u32));
}
// Zombie.DATA_DROWNED_CONVERSION_ID (after DATA_BABY_ID and
// DATA_SPECIAL_TYPE_ID): the conversion's shaking.
(Species::Zombie | Species::Husk, 18, Value::Bool(converting)) => {
m.extra.counter2 = i32::from(*converting);
}
// ZombieVillager.DATA_CONVERTING_ID (before its villager data).
(Species::ZombieVillager, 19, Value::Bool(converting)) => {
zombie_villager::set_converting(m, *converting);
}
// AbstractVillager.DATA_UNHAPPY_COUNTER (after AgeableMob's two):
// the head shake of `no`, which the server counts down.
(Species::Villager | Species::WanderingTrader, 18, Value::Int(ticks)) => {
m.extra.ints[0] = *ticks;
}
// Hoglin.DATA_IMMUNE_TO_ZOMBIFICATION (after AgeableMob's two) and
// AbstractPiglin's: `sync`'s conversion shake reads it.
(Species::Hoglin, 18, Value::Bool(immune))
| (Species::Piglin | Species::PiglinBrute, 16, Value::Bool(immune)) => {
m.extra.flag2 = *immune;
}
// Blaze.DATA_FLAGS_ID: charged 1, which makes it burn.
(Species::Blaze, 16, Value::Byte(flags)) => m.extra.flag = flags & 1 != 0,
// Turtle.HAS_EGG and LAYING_EGG (after AgeableMob's two).
(Species::Turtle, 18, Value::Bool(has_egg)) => m.extra.flag = *has_egg,
(Species::Turtle, 19, Value::Bool(laying)) => m.extra.flag2 = *laying,
// WitherBoss.DATA_TARGET_B and _C (after DATA_TARGET_A): the
// entities the side heads turn toward in `wither::client_tick`.
(Species::Wither, 17, Value::Int(id)) => m.extra.ints[0] = *id,
(Species::Wither, 18, Value::Int(id)) => m.extra.ints[1] = *id,
// Pillager.IS_CHARGING_CROSSBOW: the charge pose (Raider's
// IS_CELEBRATING takes 16).
(Species::Pillager, 17, Value::Bool(charging)) => m.extra.flag = *charging,
@@ -360,9 +412,20 @@ impl Game<'_> {
let Some(r) = &self.remote else {
return;
};
// LivingEntity.onSyncedDataUpdated(SLEEPING_POS_ID): a villager lies
// in its bed the way the bed faces, or gets up.
let bed = values.iter().find_map(|v| match v {
(14, _, Value::OptPos(bed)) => Some(bed.map_or(0, |b| self.bed_facing(b))),
_ => None,
});
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == id as u32) {
apply(m, values, &r.builtin, r.entity_id);
apply_registry_data(m, values, &r.registries, self.world.game_time);
if let Some(code) = bed
&& m.species() == Species::Villager
{
m.extra.ints[1] = code;
}
}
}
}
+3
View File
@@ -635,6 +635,9 @@ fn axolotl_air_supply(m: &mut Mob, w: &MobWorld) {
fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
m.was_eye_in_water = m.fluids.eye_in_water;
m.update_fluids(w, events);
if m.species() == Species::Drowned {
super::undead::drowned_update_swimming(m, w);
}
let fire = crate::motion::environment::fire_contact(w.world, w.registry, m.bounds());
if fire > 0.0 {
m.ticks_frozen = 0;
+23
View File
@@ -540,6 +540,26 @@ fn rot_lerp_rad(a: f32, from: f32, to: f32) -> f32 {
}
from + a * diff
}
/// `DrownedModel.setupSwimAnimation`: the arms reach up and sway, the legs
/// kick and the head lies straight.
fn drowned_swim(p: &mut Poses, s: &State, amount: f32) {
if amount <= 0.0 {
return;
}
let sway = amount * 0.35 * (0.1 * s.age).msin();
let kick = amount * 0.55 * (0.1 * s.age).msin();
let reach = -PI * 4.0 / 5.0;
let (right_x, left_x) = (p.get("right_arm")[3], p.get("left_arm")[3]);
let (right_z, left_z) = (p.get("right_arm")[5], p.get("left_arm")[5]);
p.xrot("right_arm", rot_lerp_rad(amount, right_x, reach) + sway);
p.xrot("left_arm", rot_lerp_rad(amount, left_x, reach) - sway);
p.zrot("right_arm", rot_lerp_rad(amount, right_z, -0.15));
p.zrot("left_arm", rot_lerp_rad(amount, left_z, 0.15));
let (left_leg, right_leg) = (p.get("left_leg")[3], p.get("right_leg")[3]);
p.xrot("left_leg", left_leg - kick);
p.xrot("right_leg", right_leg + kick);
p.xrot("head", 0.0);
}
/// `HumanoidModel.setupSwimAnimation`: the stroke of both arms over 26
/// walk-animation units, the head down and a slow flutter kick. The left arm
/// eases the short way round, the right one linearly, as in vanilla.
@@ -697,6 +717,9 @@ pub fn setup(
h.crouching = m.extra.crouching;
h.passenger = m.extra.passenger;
humanoid(p, s, &h);
if m.kind.anim == Anim::Drowned {
drowned_swim(p, s, m.extra.swim.amount(s.partial));
}
if m.kind.anim == Anim::ZombifiedPiglin {
super::piglin::ears(p, s);
}
+21
View File
@@ -471,6 +471,11 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
if m.extra.counter > 0 {
m.extra.counter -= 1;
}
animate(m);
}
/// `AbstractHorse.tick`'s eat, stand and mouth animations, which follow the
/// eating and standing flags (`flag` and `counter > 0`).
pub fn animate(m: &mut Mob) {
let (eating, standing) = (m.extra.flag, m.extra.counter > 0);
let v = &mut m.anim.v;
if standing {
@@ -488,6 +493,22 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
v[MOUTH] = (v[MOUTH] - v[MOUTH] * 0.7 - 0.05).max(0.0);
}
/// `AbstractHorse.tick` on a client that is not the server: the animations
/// follow the flags of the synched data (`set_flags`).
pub fn client_tick(m: &mut Mob) {
m.anim.vo = m.anim.v;
animate(m);
}
/// `AbstractHorse.DATA_ID_FLAGS` on a client: eating 16 and standing 32.
pub fn set_flags(m: &mut Mob, flags: u8) {
m.extra.flag = flags & 16 != 0;
m.extra.counter = i32::from(flags & 32 != 0);
}
/// Whether `ai_step` above runs this species' grazing and rearing, so that
/// the server's flags 16 and 32 mean eating and standing.
pub fn grazes(s: Species) -> bool {
is_equine(s) && !super::camel::is_camel(s) && !super::llama::is_llama(s)
}
/// Body texture and the markings overlay.
pub fn texture(m: &Mob) -> String {
let baby = if m.is_baby() { "_baby" } else { "" };
@@ -146,6 +146,15 @@ impl Goal for Spell {
}
}
/// `Entity.isInvisible` of an illusioner on a client: the shared flag stands
/// in for the effect the server holds, which draws the mirror images.
pub fn set_invisible(m: &mut Mob, on: bool) {
m.extra.effects.retain(|e| e.0 != INVISIBILITY);
if on {
m.extra.effects.push((INVISIBILITY, i32::MAX, 0));
}
}
/// The client-side half of `Illusioner.aiStep`: new image offsets when
/// hurt and once a minute, with a puff of cloud and a sound.
pub fn tick(m: &mut Mob, events: &mut Vec<MobEvent>) {
+7
View File
@@ -465,6 +465,13 @@ pub fn celebrate(m: &mut Mob, w: &MobWorld) {
t.position.z.floor() as i32,
]);
}
/// `Hoglin.isConverting` and `AbstractPiglin.isConverting` on a client: in a
/// dimension that is not piglin safe (`nether` is false), a mob that is not
/// immune (`flag2`) and has AI shakes. `counter2 > 0` draws the shake, as it
/// does on the server while the zombification counts up.
pub fn client_converting(m: &mut Mob, nether: bool) {
m.extra.counter2 = i32::from(!nether && !m.extra.flag2 && !m.no_ai);
}
/// Per-tick piglin and hoglin state: admiring, anger, zombification and the
/// hoglin attack animation. Returns a conversion when it happens.
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
+11
View File
@@ -923,6 +923,17 @@ pub fn base_transform_at(m: &Mob, alpha: f32, origin: glam::Mat4) -> glam::Mat4
(sign * horizon_core::jmath::acos(dot.abs().min(1.0))) as f32,
);
}
} else if m.species() == Species::Drowned {
// DrownedRenderer.setupRotations: tip toward the look pitch about
// the middle of the box while swimming.
let amount = m.extra.swim.amount(alpha);
if amount > 0.0 {
let pitch = m.previous_head_pitch + (m.head_pitch - m.previous_head_pitch) * alpha;
let middle = glam::Vec3::new(0.0, m.height() / 2.0, 0.0);
base *= glam::Mat4::from_translation(middle)
* glam::Mat4::from_rotation_x((amount * (-10.0 - pitch)).to_radians())
* glam::Mat4::from_translation(-middle);
}
} else if m.extra.swim.amount(alpha) > 0.0 {
// AvatarRenderer.setupRotations: tip forward with the swim amount,
// following the pitch in water, then lie along the swimming box.
+7 -2
View File
@@ -16,12 +16,13 @@
//! - 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, allay, armadillo, axolotl, breeze, camel, copper_golem, creaking, frog, goat,
golem, guardian, piglin, ravager, shulker, sniffer, warden,
Mob, Species, allay, armadillo, axolotl, breeze, camel, copper_golem, creaking, equine, frog,
goat, golem, guardian, piglin, ravager, shulker, sniffer, undead, villager, warden,
};
// `Pose.id` of the poses mobs take.
pub const STANDING: u8 = 0;
pub const SLEEPING: u8 = 2;
pub const LONG_JUMPING: u8 = 6;
pub const CROAKING: u8 = 8;
pub const USING_TONGUE: u8 = 9;
@@ -42,6 +43,8 @@ pub fn pose_id(m: &Mob) -> u8 {
Species::Breeze => breeze::pose_id(m),
Species::Camel | Species::CamelHusk if camel::sitting(m) => SITTING,
Species::Frog => m.extra.pose,
// LivingEntity.startSleeping: the pose, with the bed in index 14.
Species::Villager if villager::sleeping(m) => SLEEPING,
_ => STANDING,
}
}
@@ -87,6 +90,8 @@ pub fn client_tick(m: &mut Mob, game_time: i64) {
Species::Armadillo => armadillo::tick(m),
Species::Frog => frog::tick(m),
Species::Goat => goat::tick(m),
s if equine::grazes(s) => equine::client_tick(m),
Species::Drowned => undead::drowned_client_tick(m),
_ => {}
}
}
+11
View File
@@ -181,6 +181,17 @@ fn drowned_ok_target(m: &Mob, w: &super::MobWorld) -> bool {
pub fn drowned_wants_to_swim(m: &Mob, w: &super::MobWorld) -> bool {
m.extra.flag2 || m.target_info(w).is_some_and(|t| in_water_at(w, t.position))
}
/// `Drowned.updateSwimming`: swimming under water while it wants to. `flag`
/// holds `isSwimming`, which clients take from the entity's shared flags.
pub fn drowned_update_swimming(m: &mut Mob, w: &super::MobWorld) {
m.extra.flag =
!m.no_ai && m.was_eye_in_water && m.fluids.in_water && drowned_wants_to_swim(m, w);
}
/// A drowned on a client: `LivingEntity.updateSwimAmount` follows the
/// swimming flag (`Drowned.isVisuallySwimming`).
pub fn drowned_client_tick(m: &mut Mob) {
m.extra.swim.tick(m.extra.flag, m.fluids.in_water);
}
/// Drowned.DrownedMoveControl
pub fn drowned_move_control(m: &mut Mob, w: &super::MobWorld) {
let target = m.target_info(w);
+28 -10
View File
@@ -170,9 +170,7 @@ fn target_pos(w: &MobWorld, id: i32) -> Option<([f64; 3], f64, bool)> {
}
}
/// `WitherBoss.aiStep` on a client of a server: the smoke about each head
/// (`radius` 0.3 of the wither's scale, which is 1 here). The heads' turning
/// and the coloured particles need the server's targets and invulnerable
/// ticks, which a client is not sent.
/// (`radius` 0.3 of the wither's scale, which is 1 here).
pub fn client_smoke(m: &mut Mob, events: &mut Vec<MobEvent>) {
for i in 0..3 {
let h = head_pos(m, i);
@@ -189,13 +187,12 @@ pub fn client_smoke(m: &mut Mob, events: &mut Vec<MobEvent>) {
});
}
}
/// `WitherBoss.aiStep` after `super.aiStep()`: the side heads turn, smoke
/// rises from the heads (the particle offsets are drawn on the server too).
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
// Side heads turn toward their targets, else back to the body.
/// The side heads turn toward their targets, else back to the body. `find`
/// gives the position and eye height of the entity a head's target id names.
fn turn_heads(m: &mut Mob, find: impl Fn(i32) -> Option<([f64; 3], f64)>) {
for i in 0..2 {
match target_pos(w, m.extra.ints[i]) {
Some((p, eye, _)) => {
match find(m.extra.ints[i]) {
Some((p, eye)) => {
let h = head_pos(m, i + 1);
let (xd, yd, zd) = (p[0] - h[0], eye - h[1], p[2] - h[2]);
let sd = (xd * xd + zd * zd).sqrt();
@@ -207,6 +204,18 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
None => m.anim.v[i] = rotlerp(m.anim.v[i], m.body_yaw, 10.0),
}
}
}
/// `WitherBoss.aiStep` on a client that is not the server: the side heads
/// turn toward the targets of the synched data (`DATA_TARGET_B` and `_C`,
/// kept in `ints[0]` and `ints[1]` as network entity ids).
pub fn client_tick(m: &mut Mob, find: impl Fn(i32) -> Option<([f64; 3], f64)>) {
m.anim.vo = m.anim.v;
turn_heads(m, find);
}
/// `WitherBoss.aiStep` after `super.aiStep()`: the side heads turn, smoke
/// rises from the heads (the particle offsets are drawn on the server too).
pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
turn_heads(m, |id| target_pos(w, id).map(|(p, eye, _)| (p, eye)));
let powered = powered(m);
for i in 0..3 {
let h = head_pos(m, i);
@@ -284,11 +293,20 @@ pub fn custom_server_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEven
let id = m.extra.ints[k];
if id != 0 {
match target_pos(w, id) {
// `hasLineOfSight` too: no volley through a wall.
Some((p, eye, _))
if (p[0] - m.position.x).powi(2)
+ (p[1] - m.position.y).powi(2)
+ (p[2] - m.position.z).powi(2)
<= 900.0 =>
<= 900.0
&& m.sees(
w,
if id == -1 {
Who::Player
} else {
Who::Mob(id as u32)
},
) =>
{
let at = [p[0], p[1] + (eye - p[1]) * 0.5, p[2]];
shoot(m, i + 1, at, false, events);
@@ -24,6 +24,14 @@ pub struct Cure {
pub fn cure(m: &Mob) -> Option<&Cure> {
villager::ext(m).and_then(|e| e.cure.as_ref())
}
/// `ZombieVillager.DATA_CONVERTING_ID` on a client: only `is_converting`
/// (the cure's shaking) reads the cure, so its time does not matter.
pub fn set_converting(m: &mut Mob, on: bool) {
villager::ext_mut(m).cure = on.then_some(Cure {
time: 0,
starter: None,
});
}
pub fn is_converting(m: &Mob) -> bool {
m.species() == Species::ZombieVillager && cure(m).is_some()
}