Send more mob state to the single player window
A client of a server only draws what the server sends. Send and read the synched data for sleeping villagers (pose and bed), horses grazing and rearing, invisible mobs, a carried enderman block, swimming drowned, zombie villager cures, the villager head shake, zombie drowning conversion, hoglin and piglin conversion, charged blazes, turtle eggs, baby zoglins and the wither's side head targets. A wither's side heads also need a line of sight to shoot, as in vanilla.
This commit is contained in:
@@ -7132,7 +7132,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],
|
||||
|
||||
@@ -14,7 +14,7 @@ use horizon_client::{
|
||||
hub::{HostEvent, HostState, Hub, HubConfig, TickCtx},
|
||||
playerdata,
|
||||
},
|
||||
mobs::{Mob, Who, leash::Holder},
|
||||
mobs::{Mob, Species, Who, leash::Holder},
|
||||
text::Text,
|
||||
};
|
||||
use horizon_core::geometry::Vec3;
|
||||
@@ -140,6 +140,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"
|
||||
@@ -166,8 +167,13 @@ fn mob_meta(
|
||||
defaults: &mut Vec<(u8, i32, Value)>,
|
||||
) {
|
||||
let kind = m.kind.id.as_str();
|
||||
if m.fire_ticks > 0 {
|
||||
meta.push((0, serializer::BYTE, Value::Byte(1)));
|
||||
// Entity.DATA_SHARED_FLAGS_ID: on fire 1, swimming 16 (a drowned under
|
||||
// water, `Drowned.setSwimming`) and invisible 32 (the effect's flag).
|
||||
let flags = 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;
|
||||
if flags != 0 {
|
||||
meta.push((0, serializer::BYTE, Value::Byte(flags)));
|
||||
}
|
||||
// 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).
|
||||
@@ -175,6 +181,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,
|
||||
@@ -288,10 +300,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 {
|
||||
@@ -316,6 +334,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)) = (
|
||||
@@ -399,7 +426,7 @@ fn mob_meta(
|
||||
}
|
||||
defaults.push((18, serializer::BYTE, Value::Byte(16)));
|
||||
}
|
||||
// Enderman.DATA_CARRY_STATE.
|
||||
// Enderman.DATA_CARRY_STATE (0 for none).
|
||||
"minecraft:enderman" => {
|
||||
if let Some(state) = e.carried {
|
||||
meta.push((
|
||||
@@ -408,6 +435,60 @@ fn mob_meta(
|
||||
Value::Id(state.0 as i32),
|
||||
));
|
||||
}
|
||||
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: with the
|
||||
// dimension it makes them shake.
|
||||
"minecraft:hoglin" | "minecraft:piglin" | "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)));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -425,6 +506,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)));
|
||||
}
|
||||
|
||||
/// The equipment a mob shows (ClientboundSetEquipmentPacket slots: main hand,
|
||||
/// off hand, feet, legs, chest, head, body, saddle).
|
||||
fn mob_equipment(
|
||||
|
||||
@@ -3489,6 +3489,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;
|
||||
};
|
||||
@@ -3596,6 +3624,24 @@ impl Game<'_> {
|
||||
}
|
||||
// The animation states a server computes in its own `ai_step`.
|
||||
horizon_client::mobs::sync::client_tick(m, game_time);
|
||||
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);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
for o in self.orbs.iter_mut().filter(|_| running) {
|
||||
o.previous = o.position;
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
//! 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, camel, sniffer, sync, tame};
|
||||
use horizon_client::mobs::{
|
||||
Mob, Species, Who, bat, camel, equine, illusioner, sniffer, sync, tame, zombie_villager,
|
||||
};
|
||||
use horizon_protocol::entity_data::Value;
|
||||
use horizon_protocol::registry::Builtin;
|
||||
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).
|
||||
@@ -19,7 +22,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
|
||||
@@ -104,6 +121,42 @@ 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);
|
||||
}
|
||||
// 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,
|
||||
@@ -153,8 +206,19 @@ 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);
|
||||
if let Some(code) = bed
|
||||
&& m.species() == Species::Villager
|
||||
{
|
||||
m.extra.ints[1] = code;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,6 +448,9 @@ pub fn tick_swing(m: &mut Mob) {
|
||||
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;
|
||||
|
||||
@@ -501,6 +501,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.
|
||||
@@ -657,6 +677,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);
|
||||
}
|
||||
|
||||
@@ -455,6 +455,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 {
|
||||
@@ -472,6 +477,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>) {
|
||||
|
||||
@@ -294,6 +294,13 @@ fn hoglin_repellent(m: &mut Mob, w: &MobWorld) {
|
||||
m.ai.target = None;
|
||||
}
|
||||
}
|
||||
/// `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>) {
|
||||
|
||||
@@ -813,6 +813,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.
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
//! 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};
|
||||
use super::{
|
||||
Mob, Species, breeze, camel, equine, illusioner, 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 SITTING: u8 = 10;
|
||||
pub const ROARING: u8 = 11;
|
||||
@@ -36,6 +39,8 @@ pub fn pose_id(m: &Mob) -> u8 {
|
||||
Species::Warden => warden::pose_id(m),
|
||||
Species::Breeze => breeze::pose_id(m),
|
||||
Species::Camel | Species::CamelHusk if camel::sitting(m) => SITTING,
|
||||
// LivingEntity.startSleeping: the pose, with the bed in index 14.
|
||||
Species::Villager if villager::sleeping(m) => SLEEPING,
|
||||
_ => STANDING,
|
||||
}
|
||||
}
|
||||
@@ -60,6 +65,10 @@ 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),
|
||||
s if equine::grazes(s) => equine::client_tick(m),
|
||||
Species::Drowned => undead::drowned_client_tick(m),
|
||||
// Illusioner.aiStep runs on a client: the mirror images move there.
|
||||
Species::Illusioner => illusioner::tick(m, &mut Vec::new()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -169,13 +169,12 @@ fn target_pos(w: &MobWorld, id: i32) -> Option<([f64; 3], f64, bool)> {
|
||||
.map(|s| ([s.position.x, s.position.y, s.position.z], s.eye_y, false)),
|
||||
}
|
||||
}
|
||||
/// `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();
|
||||
@@ -187,6 +186,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);
|
||||
@@ -263,11 +274,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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user