Add evokers, vexes and evoker fangs
Evoker: the spellcaster goals with their warm-ups and intervals (summoning three vexes for 30 to 120 seconds, fangs in a ring when the target is close or a line of sixteen toward it, turning blue sheep red), fleeing players, the spellcasting arm pose. Vex: flying through blocks around its bound origin, charging its target with an iron sword, copying its evoker's target, wasting away after its life. Evoker fangs rise from the floor after their delay and bite for 6. Guardian beams are only drawn for guardians. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -246,6 +246,14 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
|
||||
}
|
||||
map.insert("equipment".into(), Tag::Compound(equipment));
|
||||
}
|
||||
"minecraft:vex" => {
|
||||
if let Some(h) = m.extra.home {
|
||||
map.insert("bound_pos".into(), Tag::IntArray(h.to_vec()));
|
||||
}
|
||||
if m.extra.egg_time > 0 {
|
||||
map.insert("life_ticks".into(), Tag::Int(m.extra.egg_time));
|
||||
}
|
||||
}
|
||||
"minecraft:shulker" => {
|
||||
map.insert("AttachFace".into(), Tag::Byte(m.extra.variant3 as i8));
|
||||
map.insert("Peek".into(), Tag::Byte(m.extra.counter as i8));
|
||||
@@ -400,6 +408,14 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
.unwrap_or(0) as u8;
|
||||
}
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Vex {
|
||||
if let Some(Tag::IntArray(v)) = tag.get("bound_pos")
|
||||
&& v.len() == 3
|
||||
{
|
||||
m.extra.home = Some([v[0], v[1], v[2]]);
|
||||
}
|
||||
m.extra.egg_time = number(tag.get("life_ticks")).map_or(-1, |v| v as i32);
|
||||
}
|
||||
if m.species() == crate::mobs::Species::Shulker {
|
||||
m.extra.variant3 = number(tag.get("AttachFace")).unwrap_or(0).clamp(0, 5) as u8;
|
||||
m.extra.counter = number(tag.get("Peek")).unwrap_or(0).clamp(0, 100) as i32;
|
||||
|
||||
@@ -18,6 +18,7 @@ mod dragon;
|
||||
mod enchant_effects;
|
||||
mod end;
|
||||
mod explosion;
|
||||
mod fangs;
|
||||
mod fireworks;
|
||||
mod fishing;
|
||||
mod fov;
|
||||
@@ -628,6 +629,7 @@ struct Game<'a> {
|
||||
stats_ui: stats_screen::StatsUi,
|
||||
adv_ui: advancements_screen::AdvUi,
|
||||
camera_type: perspective::CameraType,
|
||||
fangs: fangs::FangState,
|
||||
/// Structure `spawn_overrides`: structure -> category -> (piece only, spawns).
|
||||
spawn_overrides:
|
||||
HashMap<String, HashMap<String, (bool, Vec<horizon_client::biome::SpawnEntry>)>>,
|
||||
@@ -3744,6 +3746,7 @@ impl Game<'_> {
|
||||
// Mobs and their projectiles.
|
||||
self.mob_geometry(camera, alpha, &mut out);
|
||||
self.player_model_geometry(camera, alpha, &mut out);
|
||||
self.fangs_geometry(camera, alpha, &mut out);
|
||||
self.name_tag_geometry(camera, alpha, &mut out);
|
||||
// Arrows: two crossed quads along the flight direction.
|
||||
if let Some(r) = self
|
||||
@@ -7676,6 +7679,7 @@ pub fn run() -> Result<()> {
|
||||
stats_ui: Default::default(),
|
||||
adv_ui: Default::default(),
|
||||
camera_type: Default::default(),
|
||||
fangs: Default::default(),
|
||||
spawn_overrides: HashMap::new(),
|
||||
player_model: None,
|
||||
};
|
||||
|
||||
@@ -108,10 +108,11 @@ fn seen(m: &Mob) -> Seen {
|
||||
target: m.ai.target,
|
||||
health: m.health,
|
||||
variant: m.extra.variant,
|
||||
color: m.extra.color,
|
||||
}
|
||||
}
|
||||
impl Game<'_> {
|
||||
fn player_view(&self) -> Option<PlayerView> {
|
||||
pub(super) fn player_view(&self) -> Option<PlayerView> {
|
||||
let p = self.player.as_ref()?;
|
||||
let w = f64::from(p.dimensions.width) / 2.0;
|
||||
let bounds = Aabb::new(
|
||||
@@ -576,6 +577,7 @@ impl Game<'_> {
|
||||
}
|
||||
self.handle_mob_events(events)?;
|
||||
self.tick_projectiles()?;
|
||||
self.tick_fangs();
|
||||
self.tick_player_effects();
|
||||
self.piglin_pickups();
|
||||
Ok(())
|
||||
@@ -693,6 +695,18 @@ impl Game<'_> {
|
||||
self.mob_hits_player(amount, from, kind)
|
||||
}
|
||||
MobEvent::ElderCurse { at } => self.elder_curse(at),
|
||||
MobEvent::Wololo { mob } => {
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == mob) {
|
||||
// DyeColor.RED.
|
||||
m.extra.color = 14;
|
||||
}
|
||||
}
|
||||
MobEvent::Fangs {
|
||||
at,
|
||||
yaw,
|
||||
delay,
|
||||
owner,
|
||||
} => self.add_fangs(at, yaw, delay, owner),
|
||||
MobEvent::Shoot(..) => {}
|
||||
MobEvent::Explode(at, radius) => {
|
||||
// The exploding mob causes the damage (Creeper.explodeCreeper).
|
||||
@@ -908,6 +922,15 @@ impl Game<'_> {
|
||||
if let Some(v) = setup.variant {
|
||||
m.extra.variant = v;
|
||||
}
|
||||
if let Some(owner) = setup.owner_mob {
|
||||
m.extra.counter2 = owner as i32;
|
||||
}
|
||||
if let Some(home) = setup.home {
|
||||
m.extra.home = Some(home);
|
||||
}
|
||||
if let Some(life) = setup.life {
|
||||
m.extra.egg_time = life;
|
||||
}
|
||||
}
|
||||
/// Animal.spawnChildFromBreeding
|
||||
fn breed(&mut self, parent: u32, partner: u32) {
|
||||
@@ -1062,6 +1085,10 @@ impl Game<'_> {
|
||||
.play("minecraft:entity.elder_guardian.curse", Some(at), 1.0, 1.0);
|
||||
self.creatures.elder_apparition = 30;
|
||||
}
|
||||
/// Damage of a given type to the player from a point.
|
||||
pub(super) fn mob_hits_player_kind(&mut self, amount: f32, from: [f64; 3], kind: &str) {
|
||||
self.mob_hits_player(amount, from, kind);
|
||||
}
|
||||
fn mob_hits_player(&mut self, amount: f32, from: [f64; 3], damage_type: &str) {
|
||||
if self.creative {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
//! Evoker fangs (`EvokerFangs`): rising out of the floor after a delay,
|
||||
//! biting what stands on them for 6 damage, sinking back after 22 ticks.
|
||||
use super::Game;
|
||||
use horizon_client::mobs::{Part, Species, anim::Poses};
|
||||
use horizon_core::geometry::Vec3;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(super) struct Fangs {
|
||||
pos: [f64; 3],
|
||||
yaw: f32,
|
||||
warmup: i32,
|
||||
life: i32,
|
||||
owner: u32,
|
||||
started: bool,
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub(super) struct FangState {
|
||||
pub list: Vec<Fangs>,
|
||||
model: Option<Arc<Part>>,
|
||||
}
|
||||
impl Game<'_> {
|
||||
pub(super) fn add_fangs(&mut self, at: [f64; 3], yaw: f32, delay: i32, owner: u32) {
|
||||
if self.fangs.model.is_none() {
|
||||
self.fangs.model = horizon_client::mobs::load_model(
|
||||
&self.options.resources,
|
||||
"minecraft:evoker_fangs#main",
|
||||
)
|
||||
.map(Arc::new);
|
||||
}
|
||||
self.fangs.list.push(Fangs {
|
||||
pos: at,
|
||||
yaw,
|
||||
warmup: delay,
|
||||
life: 22,
|
||||
owner,
|
||||
started: false,
|
||||
});
|
||||
}
|
||||
/// `EvokerFangs.tick`.
|
||||
pub(super) fn tick_fangs(&mut self) {
|
||||
let mut list = std::mem::take(&mut self.fangs.list);
|
||||
list.retain_mut(|f| {
|
||||
f.warmup -= 1;
|
||||
if f.warmup >= 0 {
|
||||
return true;
|
||||
}
|
||||
if f.warmup == -8 {
|
||||
self.fangs_bite(f);
|
||||
}
|
||||
if !f.started {
|
||||
f.started = true;
|
||||
self.audio.play(
|
||||
"minecraft:entity.evoker_fangs.attack",
|
||||
Some(f.pos),
|
||||
1.0,
|
||||
1.0,
|
||||
);
|
||||
}
|
||||
f.life -= 1;
|
||||
f.life >= 0
|
||||
});
|
||||
self.fangs.list = list;
|
||||
}
|
||||
/// `dealDamageTo` everything alive in the fangs' box (0.5 x 0.8,
|
||||
/// inflated 0.2 sideways) but the evoker's allies.
|
||||
fn fangs_bite(&mut self, f: &Fangs) {
|
||||
let half = 0.25 + 0.2;
|
||||
let lo = Vec3::new(f.pos[0] - half, f.pos[1], f.pos[2] - half);
|
||||
let hi = Vec3::new(f.pos[0] + half, f.pos[1] + 0.8, f.pos[2] + half);
|
||||
let b = horizon_core::geometry::Aabb::new(lo, hi);
|
||||
if let Some(p) = self.player_view()
|
||||
&& p.alive
|
||||
&& p.bounds.intersects(b)
|
||||
{
|
||||
self.mob_hits_player_kind(6.0, f.pos, "minecraft:indirect_magic");
|
||||
}
|
||||
for m in &mut self.mobs {
|
||||
let ally = matches!(
|
||||
m.species(),
|
||||
Species::Evoker
|
||||
| Species::Vex
|
||||
| Species::Pillager
|
||||
| Species::Vindicator
|
||||
| Species::Witch
|
||||
);
|
||||
if m.id != f.owner && !ally && m.alive() && m.bounds().intersects(b) {
|
||||
m.damage(
|
||||
6.0,
|
||||
horizon_client::mobs::Damage {
|
||||
kind: horizon_client::mobs::DamageKind::Magic,
|
||||
attacker: Some(horizon_client::mobs::Who::Mob(f.owner)),
|
||||
from: Some(f.pos),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `EvokerFangsRenderer`: the jaws snapping up and closing.
|
||||
pub(super) fn fangs_geometry(
|
||||
&self,
|
||||
camera: glam::DVec3,
|
||||
alpha: f64,
|
||||
out: &mut Vec<horizon_client::mesher::Vertex>,
|
||||
) {
|
||||
let Some(model) = self.fangs.model.as_ref() else {
|
||||
return;
|
||||
};
|
||||
let Some(r) = self
|
||||
.res
|
||||
.atlas
|
||||
.sprites
|
||||
.get("entity/illager/evoker_fangs")
|
||||
.copied()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let partial = alpha as f32;
|
||||
for f in &self.fangs.list {
|
||||
if !f.started {
|
||||
continue;
|
||||
}
|
||||
// getAnimationProgress.
|
||||
let i = f.life - 2;
|
||||
let bite = if i <= 0 {
|
||||
1.0
|
||||
} else {
|
||||
1.0 - (i as f32 - partial) / 20.0
|
||||
};
|
||||
if bite == 0.0 {
|
||||
continue;
|
||||
}
|
||||
let mut poses = Poses::new(model);
|
||||
let amount = (bite * 2.0).min(1.0);
|
||||
let amount = 1.0 - amount * amount * amount;
|
||||
let pi = std::f32::consts::PI;
|
||||
p_zrot(&mut poses, "upper_jaw", pi - amount * 0.35 * pi);
|
||||
p_zrot(&mut poses, "lower_jaw", pi + amount * 0.35 * pi);
|
||||
poses.get("base")[1] -= (bite + (bite * 2.7).sin()) * 7.2;
|
||||
let pre = if bite > 0.9 { (1.0 - bite) / 0.1 } else { 1.0 };
|
||||
let root = poses.get("root");
|
||||
root[1] = 24.0 - 20.0 * pre;
|
||||
root[6] = pre;
|
||||
root[7] = pre;
|
||||
root[8] = pre;
|
||||
let light = self.world.light(
|
||||
f.pos[0].floor() as i32,
|
||||
f.pos[1].floor() as i32,
|
||||
f.pos[2].floor() as i32,
|
||||
);
|
||||
let packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8);
|
||||
let base =
|
||||
glam::Mat4::from_translation((glam::DVec3::from_array(f.pos) - camera).as_vec3())
|
||||
* glam::Mat4::from_rotation_y((90.0 - f.yaw).to_radians())
|
||||
* glam::Mat4::from_scale(glam::Vec3::new(-1.0, -1.0, 1.0))
|
||||
* glam::Mat4::from_translation(glam::Vec3::new(0.0, -1.501, 0.0));
|
||||
horizon_client::mobs::render::draw(
|
||||
model,
|
||||
base,
|
||||
&poses,
|
||||
[r.u0, r.v0, r.u1, r.v1],
|
||||
0xFFFF_FFFF,
|
||||
packed,
|
||||
0,
|
||||
out,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn p_zrot(p: &mut Poses, part: &str, v: f32) {
|
||||
p.zrot(part, v);
|
||||
}
|
||||
@@ -32,6 +32,7 @@ pub mod spawning;
|
||||
pub mod species;
|
||||
pub mod tame;
|
||||
pub mod undead;
|
||||
pub mod vex;
|
||||
pub mod witch;
|
||||
mod world;
|
||||
|
||||
@@ -521,6 +522,17 @@ pub enum MobEvent {
|
||||
ElderCurse {
|
||||
at: [f64; 3],
|
||||
},
|
||||
/// `EvokerWololoSpellGoal`: a blue sheep turns red.
|
||||
Wololo {
|
||||
mob: u32,
|
||||
},
|
||||
/// `EvokerFangs` rising at a point after `delay` ticks.
|
||||
Fangs {
|
||||
at: [f64; 3],
|
||||
yaw: f32,
|
||||
delay: i32,
|
||||
owner: u32,
|
||||
},
|
||||
Shoot([f64; 3], [f64; 3]),
|
||||
Explode([f64; 3], f32),
|
||||
/// Melee or ranged damage to another mob.
|
||||
@@ -634,6 +646,10 @@ pub struct SpawnSetup {
|
||||
pub variant: Option<u8>,
|
||||
/// Zombified piglins and zoglins wake up nauseous (`ConversionParams`).
|
||||
pub nausea: bool,
|
||||
/// Vexes: the summoning mob, the bound origin and the life in ticks.
|
||||
pub owner_mob: Option<u32>,
|
||||
pub home: Option<[i32; 3]>,
|
||||
pub life: Option<i32>,
|
||||
}
|
||||
/// A snapshot of another entity mobs can see this tick.
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -651,6 +667,8 @@ pub struct Seen {
|
||||
pub target: Option<Who>,
|
||||
pub health: f32,
|
||||
pub variant: u8,
|
||||
/// Dye colour (sheep).
|
||||
pub color: u8,
|
||||
}
|
||||
/// The player as mobs see it.
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -82,6 +82,7 @@ pub enum Family {
|
||||
Cube,
|
||||
Guardian,
|
||||
Shulker,
|
||||
Vex,
|
||||
}
|
||||
pub fn family(s: Species) -> Family {
|
||||
use Species as S;
|
||||
@@ -110,7 +111,8 @@ pub fn family(s: Species) -> Family {
|
||||
S::Wolf | S::Cat => Family::Tame,
|
||||
S::Blaze | S::Ghast => Family::Nether,
|
||||
S::IronGolem | S::SnowGolem => Family::Golem,
|
||||
S::Pillager | S::Vindicator => Family::Illager,
|
||||
S::Pillager | S::Vindicator | S::Evoker => Family::Illager,
|
||||
S::Vex => Family::Vex,
|
||||
S::Piglin | S::PiglinBrute | S::Hoglin | S::Zoglin => Family::Piglin,
|
||||
S::Horse | S::Donkey | S::Mule | S::SkeletonHorse | S::ZombieHorse => Family::Equine,
|
||||
S::Phantom => Family::Phantom,
|
||||
@@ -137,6 +139,7 @@ pub fn register(m: &mut Mob) {
|
||||
Family::Golem if m.species() == Species::IronGolem => super::golem::register_iron(m),
|
||||
Family::Golem => super::golem::register_snow(m),
|
||||
Family::Illager if m.species() == Species::Pillager => super::illager::register_pillager(m),
|
||||
Family::Illager if m.species() == Species::Evoker => super::illager::register_evoker(m),
|
||||
Family::Illager => super::illager::register_vindicator(m),
|
||||
Family::Equine => super::equine::register(m),
|
||||
Family::Phantom => super::phantom::register(m),
|
||||
@@ -150,6 +153,7 @@ pub fn register(m: &mut Mob) {
|
||||
Family::Cube => super::cube::register(m),
|
||||
Family::Guardian => super::guardian::register(m),
|
||||
Family::Shulker => super::shulker::register(m),
|
||||
Family::Vex => super::vex::register(m),
|
||||
}
|
||||
}
|
||||
/// Mob.tick additions that run before the entity tick (creeper fuse, puffing).
|
||||
@@ -175,6 +179,9 @@ pub fn custom_move_control(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>
|
||||
if family(m.species()) == Family::Guardian {
|
||||
return super::guardian::move_control(m);
|
||||
}
|
||||
if m.species() == Species::Vex {
|
||||
return super::vex::move_control(m);
|
||||
}
|
||||
match family(m.species()) {
|
||||
Family::Aquatic => aquatic::fish_move_control(m),
|
||||
Family::Cube => super::cube::move_control(m, events),
|
||||
@@ -501,6 +508,8 @@ fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
Species::Enderman => super::enderman::custom_server_ai_step(m, cx),
|
||||
Species::Blaze => super::nether::blaze_server_ai_step(m, cx),
|
||||
Species::ElderGuardian => super::guardian::elder_server_ai_step(m, cx),
|
||||
// SpellcasterIllager.customServerAiStep.
|
||||
Species::Evoker if m.extra.counter > 0 => m.extra.counter -= 1,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -527,6 +536,7 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
s if super::equine::is_equine(s) => super::equine::ai_step(m, w),
|
||||
Species::Phantom => super::phantom::flap_sound(m, events),
|
||||
Species::Guardian | Species::ElderGuardian => super::guardian::ai_step(m, w, events),
|
||||
Species::Vex => super::vex::ai_step(m, w),
|
||||
Species::Shulker => {
|
||||
super::shulker::tick(m, w, events);
|
||||
super::shulker::ai_step(m, w, events);
|
||||
@@ -722,6 +732,7 @@ pub fn custom_travel(m: &mut Mob, w: &MobWorld, input: Vec3, events: &mut Vec<Mo
|
||||
Family::Guardian => super::guardian::travel(m, w, input, events),
|
||||
// Shulkers never move on their own.
|
||||
Family::Shulker => true,
|
||||
Family::Vex => super::vex::travel(m),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::f32::consts::PI;
|
||||
/// The setupAnim implementation a model uses.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Anim {
|
||||
Vex,
|
||||
Guardian,
|
||||
Shulker,
|
||||
Quadruped,
|
||||
@@ -456,6 +457,7 @@ pub fn setup(
|
||||
Anim::Piglin => super::piglin::piglin_anim(m, s, p),
|
||||
Anim::Phantom => super::phantom::anim(m, s, p),
|
||||
Anim::Guardian => super::guardian::anim(m, s, p),
|
||||
Anim::Vex => super::vex::anim(m, s, p),
|
||||
Anim::Shulker => super::shulker::anim(m, s, p),
|
||||
Anim::Horse => {
|
||||
super::equine::anim(m, s, p);
|
||||
|
||||
@@ -331,7 +331,8 @@ pub fn elder_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
/// The beam's clock for rendering: (attack time with the partial tick,
|
||||
/// attack scale), while a target is locked.
|
||||
pub fn beam(m: &Mob, partial: f32) -> Option<(f32, f32)> {
|
||||
if !m.extra.flag || m.ai.target.is_none() {
|
||||
let guardian = matches!(m.species(), Species::Guardian | Species::ElderGuardian);
|
||||
if !guardian || !m.extra.flag || m.ai.target.is_none() {
|
||||
return None;
|
||||
}
|
||||
let time = m.extra.counter2 as f32 + partial;
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::{
|
||||
anim::{Poses, State},
|
||||
goals::{
|
||||
Cx, Float, Goal, HurtByTarget, LOOK, LookAtPlayer, MOVE, MeleeAttack, NearestTarget, Prey,
|
||||
Stroll, goal_clone,
|
||||
Stroll, goal_clone, reduced,
|
||||
},
|
||||
};
|
||||
use crate::projectiles::{Projectile, ProjectileKind};
|
||||
@@ -14,11 +14,20 @@ use std::f32::consts::PI;
|
||||
|
||||
/// The species raiders do not fight (`Raider`'s allies).
|
||||
fn raider(s: Species) -> bool {
|
||||
matches!(s, Species::Pillager | Species::Vindicator | Species::Witch)
|
||||
matches!(
|
||||
s,
|
||||
Species::Pillager | Species::Vindicator | Species::Witch | Species::Evoker
|
||||
)
|
||||
}
|
||||
fn targets(m: &mut Mob, villagers_seen: bool) {
|
||||
let mut hurt = HurtByTarget::new().alert();
|
||||
hurt.ignore = vec![Species::Pillager, Species::Vindicator, Species::Witch];
|
||||
hurt.ignore = vec![
|
||||
Species::Pillager,
|
||||
Species::Vindicator,
|
||||
Species::Witch,
|
||||
Species::Evoker,
|
||||
Species::Vex,
|
||||
];
|
||||
m.ai.targets.add(1, hurt);
|
||||
m.ai.targets.add(2, NearestTarget::player(true));
|
||||
m.ai.targets.add(
|
||||
@@ -54,6 +63,289 @@ pub fn register_vindicator(m: &mut Mob) {
|
||||
.when(|m, _| m.custom_name.as_deref() == Some("Johnny")),
|
||||
);
|
||||
}
|
||||
// Evoker state: `counter` spellCastingTickCount, `variant2` the spell
|
||||
// being cast (0 none, 1 vexes, 2 fangs, 3 wololo), `counter2` the wololo
|
||||
// sheep's id.
|
||||
pub fn register_evoker(m: &mut Mob) {
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(0, Float);
|
||||
g.add(1, CastingSpell);
|
||||
g.add(
|
||||
2,
|
||||
super::goals::AvoidEntity::new(super::goals::Avoid::Player, 8.0, 0.6, 1.0),
|
||||
);
|
||||
g.add(4, UseSpell::new(Spell::Vexes));
|
||||
g.add(5, UseSpell::new(Spell::Fangs));
|
||||
g.add(6, UseSpell::new(Spell::Wololo));
|
||||
g.add(8, Stroll::new(0.6));
|
||||
g.add(9, LookAtPlayer::new(3.0).probability(1.0));
|
||||
targets(m, false);
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Spell {
|
||||
Vexes = 1,
|
||||
Fangs = 2,
|
||||
Wololo = 3,
|
||||
}
|
||||
/// `SpellcasterCastingSpellGoal`: stand still facing the target while a
|
||||
/// spell is cast.
|
||||
#[derive(Clone, Debug)]
|
||||
struct CastingSpell;
|
||||
impl Goal for CastingSpell {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE | LOOK
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _cx: &mut Cx) -> bool {
|
||||
m.extra.counter > 0
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, _cx: &mut Cx) {
|
||||
m.ai.nav.stop();
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _cx: &mut Cx) {
|
||||
m.extra.variant2 = 0;
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let look = match m.target_info(cx.w) {
|
||||
Some(t) => Some([t.position.x, t.eye_y, t.position.z]),
|
||||
None => {
|
||||
let id = m.extra.counter2 as u32;
|
||||
cx.w.others
|
||||
.iter()
|
||||
.find(|s| s.id == id)
|
||||
.map(|s| [s.position.x, s.eye_y, s.position.z])
|
||||
}
|
||||
};
|
||||
if let Some(at) = look {
|
||||
let (y, x) = (m.kind.head_rot_speed, m.kind.max_head_x_rot);
|
||||
m.look_at_speed(at, y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `SpellcasterUseSpellGoal` with the evoker's three spells.
|
||||
#[derive(Clone, Debug)]
|
||||
struct UseSpell {
|
||||
spell: Spell,
|
||||
warmup: i32,
|
||||
next: i64,
|
||||
}
|
||||
impl UseSpell {
|
||||
fn new(spell: Spell) -> Self {
|
||||
Self {
|
||||
spell,
|
||||
warmup: 0,
|
||||
next: 0,
|
||||
}
|
||||
}
|
||||
/// (warm-up, casting time, interval, prepare sound).
|
||||
fn timing(&self) -> (i32, i32, i64, &'static str) {
|
||||
match self.spell {
|
||||
Spell::Vexes => (20, 100, 340, "entity.evoker.prepare_summon"),
|
||||
Spell::Fangs => (20, 40, 100, "entity.evoker.prepare_attack"),
|
||||
Spell::Wololo => (40, 60, 140, "entity.evoker.prepare_wololo"),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Goal for UseSpell {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
0
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
let age = i64::from(m.age);
|
||||
if self.spell == Spell::Wololo {
|
||||
// EvokerWololoSpellGoal.canUse: a blue sheep within 16 (4 up or
|
||||
// down), no target, griefing on.
|
||||
if m.ai.target.is_some() || m.extra.counter > 0 || age < self.next || !cx.w.mob_griefing
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let p = m.position;
|
||||
let sheep: Vec<u32> =
|
||||
cx.w.others
|
||||
.iter()
|
||||
.filter(|s| {
|
||||
s.species == Species::Sheep
|
||||
&& s.alive
|
||||
&& s.color == 11
|
||||
&& (s.position.x - p.x).abs() <= 16.0
|
||||
&& (s.position.y - p.y).abs() <= 4.0
|
||||
&& (s.position.z - p.z).abs() <= 16.0
|
||||
})
|
||||
.map(|s| s.id)
|
||||
.collect();
|
||||
if sheep.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let pick = m.random.next_int_bound(sheep.len() as i32).unwrap_or(0) as usize;
|
||||
m.extra.counter2 = sheep[pick] as i32;
|
||||
return true;
|
||||
}
|
||||
if !m.target_info(cx.w).is_some_and(|t| t.alive) || m.extra.counter > 0 || age < self.next {
|
||||
return false;
|
||||
}
|
||||
if self.spell == Spell::Vexes {
|
||||
// EvokerSummonSpellGoal: fewer vexes nearby than a roll of 1..8.
|
||||
let p = m.position;
|
||||
let vexes =
|
||||
cx.w.others
|
||||
.iter()
|
||||
.filter(|s| {
|
||||
s.species == Species::Vex
|
||||
&& s.alive
|
||||
&& s.position.distance_squared(p) <= 16.0 * 16.0 * 3.0
|
||||
})
|
||||
.count() as i32;
|
||||
return m.random.next_int_bound(8).unwrap_or(0) + 1 > vexes;
|
||||
}
|
||||
true
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
if self.spell == Spell::Wololo {
|
||||
return m.extra.counter2 != 0 && self.warmup > 0;
|
||||
}
|
||||
m.target_info(cx.w).is_some_and(|t| t.alive) && self.warmup > 0
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let (warmup, casting, interval, sound) = self.timing();
|
||||
self.warmup = reduced(warmup);
|
||||
m.extra.counter = casting;
|
||||
self.next = i64::from(m.age) + interval;
|
||||
cx.events.push(MobEvent::Sound(
|
||||
sound,
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
1.0,
|
||||
1.0,
|
||||
));
|
||||
m.extra.variant2 = self.spell as u8;
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _cx: &mut Cx) {
|
||||
if self.spell == Spell::Wololo {
|
||||
m.extra.counter2 = 0;
|
||||
}
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
self.warmup -= 1;
|
||||
if self.warmup != 0 {
|
||||
return;
|
||||
}
|
||||
match self.spell {
|
||||
Spell::Vexes => summon_vexes(m, cx),
|
||||
Spell::Fangs => cast_fangs(m, cx),
|
||||
Spell::Wololo => {
|
||||
let id = m.extra.counter2 as u32;
|
||||
if id != 0 {
|
||||
cx.events.push(MobEvent::Wololo { mob: id });
|
||||
}
|
||||
}
|
||||
}
|
||||
cx.events.push(MobEvent::Sound(
|
||||
"entity.evoker.cast_spell",
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
1.0,
|
||||
1.0,
|
||||
));
|
||||
}
|
||||
}
|
||||
/// `EvokerSummonSpellGoal.performSpellCasting`: three vexes nearby for 30
|
||||
/// to 120 seconds.
|
||||
fn summon_vexes(m: &mut Mob, cx: &mut Cx) {
|
||||
let base = [
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
];
|
||||
for _ in 0..3 {
|
||||
let r = &mut m.random;
|
||||
let p = [
|
||||
base[0] - 2 + r.next_int_bound(5).unwrap_or(2),
|
||||
base[1] + 1,
|
||||
base[2] - 2 + r.next_int_bound(5).unwrap_or(2),
|
||||
];
|
||||
let life = 20 * (30 + r.next_int_bound(90).unwrap_or(0));
|
||||
cx.events.push(MobEvent::SpawnKind {
|
||||
kind: "minecraft:vex".into(),
|
||||
at: [f64::from(p[0]), f64::from(p[1]), f64::from(p[2])],
|
||||
setup: super::SpawnSetup {
|
||||
owner_mob: Some(m.id),
|
||||
home: Some(p),
|
||||
life: Some(life),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
/// `EvokerAttackSpellGoal.performSpellCasting`: a ring of fangs when the
|
||||
/// target is close, else a line of sixteen toward it.
|
||||
fn cast_fangs(m: &mut Mob, cx: &mut Cx) {
|
||||
let Some(t) = m.target_info(cx.w) else {
|
||||
return;
|
||||
};
|
||||
let min_y = t.position.y.min(m.position.y);
|
||||
let max_y = t.position.y.max(m.position.y) + 1.0;
|
||||
let angle = (t.position.z - m.position.z).atan2(t.position.x - m.position.x) as f32;
|
||||
let mut place = |x: f64, z: f64, a: f32, delay: i32| {
|
||||
if let Some(y) = fang_floor(cx.w, x, z, min_y, max_y) {
|
||||
cx.events.push(MobEvent::Fangs {
|
||||
at: [x, y, z],
|
||||
yaw: a.to_degrees(),
|
||||
delay,
|
||||
owner: m.id,
|
||||
});
|
||||
}
|
||||
};
|
||||
let (x, z) = (m.position.x, m.position.z);
|
||||
if m.distance_sqr(t.position) < 9.0 {
|
||||
for i in 0..5 {
|
||||
let a = angle + i as f32 * PI * 0.4;
|
||||
place(
|
||||
x + f64::from(a.cos()) * 1.5,
|
||||
z + f64::from(a.sin()) * 1.5,
|
||||
a,
|
||||
0,
|
||||
);
|
||||
}
|
||||
for i in 0..8 {
|
||||
let a = angle + i as f32 * PI * 2.0 / 8.0 + PI * 2.0 / 5.0;
|
||||
place(
|
||||
x + f64::from(a.cos()) * 2.5,
|
||||
z + f64::from(a.sin()) * 2.5,
|
||||
a,
|
||||
3,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for i in 0..16 {
|
||||
let reach = 1.25 * f64::from(i + 1);
|
||||
place(
|
||||
x + f64::from(angle.cos()) * reach,
|
||||
z + f64::from(angle.sin()) * reach,
|
||||
angle,
|
||||
i,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `createSpellEntity`: the first sturdy floor going down from `max_y`,
|
||||
/// standing on the top of any block in the way.
|
||||
fn fang_floor(w: &super::MobWorld, x: f64, z: f64, min_y: f64, max_y: f64) -> Option<f64> {
|
||||
let (bx, bz) = (x.floor() as i32, z.floor() as i32);
|
||||
let mut y = max_y.floor() as i32;
|
||||
while y >= min_y.floor() as i32 - 1 {
|
||||
let below = w.facts.get(w.world.block(bx, y - 1, bz));
|
||||
if below.full_collision {
|
||||
let here = w.world.block(bx, y, bz);
|
||||
let top = if w.facts.is_air(here) {
|
||||
0.0
|
||||
} else {
|
||||
f64::from(w.data.state(here).top)
|
||||
};
|
||||
return Some(f64::from(y) + top);
|
||||
}
|
||||
y -= 1;
|
||||
}
|
||||
None
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Crossbow {
|
||||
Uncharged,
|
||||
@@ -235,6 +527,7 @@ fn shoot_crossbow(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
}
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum ArmPose {
|
||||
Spellcasting,
|
||||
Crossed,
|
||||
Neutral,
|
||||
Attacking,
|
||||
@@ -255,6 +548,8 @@ fn arm_pose(m: &Mob) -> ArmPose {
|
||||
ArmPose::Neutral
|
||||
}
|
||||
}
|
||||
Species::Evoker if m.extra.variant2 != 0 => ArmPose::Spellcasting,
|
||||
Species::Evoker => ArmPose::Crossed,
|
||||
_ => {
|
||||
if m.ai.aggressive {
|
||||
ArmPose::Attacking
|
||||
@@ -342,6 +637,19 @@ pub fn anim(m: &Mob, s: &State, p: &mut Poses) {
|
||||
p.yrot("left_arm", 0.4 + (0.85 - 0.4) * a);
|
||||
p.xrot("left_arm", -0.970_796_35 + (-PI / 2.0 + 0.970_796_35) * a);
|
||||
}
|
||||
ArmPose::Spellcasting => {
|
||||
for (arm, x, z_rot) in [
|
||||
("right_arm", -5.0, PI * 0.75),
|
||||
("left_arm", 5.0, -PI * 0.75),
|
||||
] {
|
||||
let v = p.get(arm);
|
||||
v[2] = 0.0;
|
||||
v[0] = x;
|
||||
v[3] = (s.age * 0.6662).cos() * 0.25;
|
||||
v[4] = 0.0;
|
||||
v[5] = z_rot;
|
||||
}
|
||||
}
|
||||
ArmPose::Crossed | ArmPose::Neutral => {}
|
||||
}
|
||||
if pose == ArmPose::Crossed {
|
||||
|
||||
@@ -118,6 +118,7 @@ pub fn body(m: &Mob) -> (String, String) {
|
||||
super::tame::texture(m),
|
||||
),
|
||||
S::Shulker => ("shulker#main".into(), super::shulker::texture(m)),
|
||||
S::Vex => ("vex#main".into(), super::vex::texture(m).into()),
|
||||
S::Ghast => (
|
||||
"ghast#main".into(),
|
||||
if m.extra.flag {
|
||||
|
||||
@@ -76,6 +76,8 @@ pub enum Species {
|
||||
Guardian,
|
||||
ElderGuardian,
|
||||
Shulker,
|
||||
Evoker,
|
||||
Vex,
|
||||
}
|
||||
/// Baby bounding boxes (each class's BABY_DIMENSIONS).
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -865,6 +867,30 @@ pub const ALL: &[Def] = &[
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
def!(
|
||||
Evoker,
|
||||
"evoker",
|
||||
"evoker#main",
|
||||
"entity/illager/evoker",
|
||||
A::Illager,
|
||||
[
|
||||
"entity.evoker.ambient",
|
||||
"entity.evoker.hurt",
|
||||
"entity.evoker.death"
|
||||
],
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
def!(
|
||||
Vex,
|
||||
"vex",
|
||||
"vex#main",
|
||||
"entity/illager/vex",
|
||||
A::Vex,
|
||||
["entity.vex.ambient", "entity.vex.hurt", "entity.vex.death"],
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
def!(
|
||||
Shulker,
|
||||
"shulker",
|
||||
@@ -1244,6 +1270,8 @@ impl Def {
|
||||
| S::Guardian
|
||||
| S::ElderGuardian
|
||||
| S::Shulker
|
||||
| S::Evoker
|
||||
| S::Vex
|
||||
)
|
||||
}
|
||||
/// The item tag Animal.isFood tests.
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
//! Vexes (`Vex`): summoned by evokers, flying through walls around their
|
||||
//! bound origin, charging at their target, and wasting away after their
|
||||
//! limited life.
|
||||
use super::{
|
||||
Damage, DamageKind, Mob, MobEvent, Species, Who,
|
||||
anim::{Poses, State},
|
||||
control::Operation,
|
||||
goals::{
|
||||
Cx, Float, Goal, HurtByTarget, LookAtPlayer, MOVE, NearestTarget, goal_clone, reduced,
|
||||
},
|
||||
};
|
||||
use horizon_core::{geometry::Vec3, random::RandomSource};
|
||||
use std::f32::consts::PI;
|
||||
|
||||
// Vex state: `flag` charging, `counter2` the owner's mob id (0 none),
|
||||
// `home` the bound origin, `egg_time` the life left (-1 unlimited).
|
||||
|
||||
pub fn register(m: &mut Mob) {
|
||||
m.no_gravity = true;
|
||||
m.ai.mov.kind = super::control::MoveKind::Custom;
|
||||
m.extra.main_hand = Some("minecraft:iron_sword".into());
|
||||
if m.extra.egg_time == 0 {
|
||||
m.extra.egg_time = -1;
|
||||
}
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(0, Float);
|
||||
g.add(4, Charge);
|
||||
g.add(8, RandomMove);
|
||||
g.add(9, LookAtPlayer::new(3.0).probability(1.0));
|
||||
let mut hurt = HurtByTarget::new().alert();
|
||||
hurt.ignore = vec![
|
||||
Species::Pillager,
|
||||
Species::Vindicator,
|
||||
Species::Evoker,
|
||||
Species::Witch,
|
||||
Species::Vex,
|
||||
];
|
||||
m.ai.targets.add(1, hurt);
|
||||
m.ai.targets.add(2, CopyOwnerTarget);
|
||||
m.ai.targets.add(3, NearestTarget::player(true));
|
||||
}
|
||||
fn has_wanted(m: &Mob) -> bool {
|
||||
m.ai.mov.operation == Operation::MoveTo
|
||||
}
|
||||
fn set_wanted(m: &mut Mob, at: [f64; 3], speed: f64) {
|
||||
m.ai.mov.wanted = at;
|
||||
m.ai.mov.speed_modifier = speed;
|
||||
m.ai.mov.operation = Operation::MoveTo;
|
||||
}
|
||||
/// `VexChargeAttackGoal`.
|
||||
#[derive(Clone, Debug)]
|
||||
struct Charge;
|
||||
impl Goal for Charge {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
let Some(t) = m.target_info(cx.w).filter(|t| t.alive) else {
|
||||
return false;
|
||||
};
|
||||
!has_wanted(m)
|
||||
&& m.random.next_int_bound(reduced(7)).unwrap_or(1) == 0
|
||||
&& m.distance_sqr(t.position) > 4.0
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
has_wanted(m) && m.extra.flag && m.target_info(cx.w).is_some_and(|t| t.alive)
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
if let Some(t) = m.target_info(cx.w) {
|
||||
set_wanted(m, [t.position.x, t.eye_y, t.position.z], 1.0);
|
||||
}
|
||||
m.extra.flag = true;
|
||||
cx.events.push(MobEvent::Sound(
|
||||
"entity.vex.charge",
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
1.0,
|
||||
1.0,
|
||||
));
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _cx: &mut Cx) {
|
||||
m.extra.flag = false;
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let (Some(who), Some(t)) = (m.ai.target, m.target_info(cx.w)) else {
|
||||
return;
|
||||
};
|
||||
if m.bounds().intersects(t.bounds) {
|
||||
super::ai::do_hurt_target(m, who, cx);
|
||||
m.extra.flag = false;
|
||||
} else if m.distance_sqr(t.position) < 9.0 {
|
||||
set_wanted(m, [t.position.x, t.eye_y, t.position.z], 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `VexRandomMoveGoal`: drift to an empty block near the bound origin.
|
||||
#[derive(Clone, Debug)]
|
||||
struct RandomMove;
|
||||
impl Goal for RandomMove {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _cx: &mut Cx) -> bool {
|
||||
!has_wanted(m) && m.random.next_int_bound(reduced(7)).unwrap_or(1) == 0
|
||||
}
|
||||
fn can_continue(&mut self, _m: &mut Mob, _cx: &mut Cx) -> bool {
|
||||
false
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
// Ticked once: the goal never continues.
|
||||
let origin = m.extra.home.unwrap_or([
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
]);
|
||||
for _ in 0..3 {
|
||||
let r = &mut m.random;
|
||||
let p = [
|
||||
origin[0] + r.next_int_bound(15).unwrap_or(7) - 7,
|
||||
origin[1] + r.next_int_bound(11).unwrap_or(5) - 5,
|
||||
origin[2] + r.next_int_bound(15).unwrap_or(7) - 7,
|
||||
];
|
||||
if cx.w.facts.is_air(cx.w.world.block(p[0], p[1], p[2])) {
|
||||
let at = [
|
||||
f64::from(p[0]) + 0.5,
|
||||
f64::from(p[1]) + 0.5,
|
||||
f64::from(p[2]) + 0.5,
|
||||
];
|
||||
set_wanted(m, at, 0.25);
|
||||
if m.ai.target.is_none() {
|
||||
m.look_at_speed(at, 180.0, 20.0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `VexCopyOwnerTargetGoal`: the evoker's target.
|
||||
#[derive(Clone, Debug)]
|
||||
struct CopyOwnerTarget;
|
||||
impl Goal for CopyOwnerTarget {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
super::goals::TARGET
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
let owner = m.extra.counter2 as u32;
|
||||
owner != 0
|
||||
&& cx
|
||||
.w
|
||||
.others
|
||||
.iter()
|
||||
.find(|s| s.id == owner)
|
||||
.and_then(|s| s.target)
|
||||
.is_some_and(|t| t != Who::Mob(m.id))
|
||||
}
|
||||
fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
m.target_info(cx.w).is_some_and(|t| t.alive)
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let owner = m.extra.counter2 as u32;
|
||||
m.ai.target =
|
||||
cx.w.others
|
||||
.iter()
|
||||
.find(|s| s.id == owner)
|
||||
.and_then(|s| s.target);
|
||||
}
|
||||
}
|
||||
/// `VexMoveControl`: accelerate straight at the wanted point.
|
||||
pub fn move_control(m: &mut Mob) {
|
||||
if m.ai.mov.operation != Operation::MoveTo {
|
||||
return;
|
||||
}
|
||||
let [wx, wy, wz] = m.ai.mov.wanted;
|
||||
let d = Vec3::new(wx - m.position.x, wy - m.position.y, wz - m.position.z);
|
||||
let len = (d.x * d.x + d.y * d.y + d.z * d.z).sqrt();
|
||||
let b = m.bounds();
|
||||
let (lo, hi) = (b.min_position(), b.max_position());
|
||||
let size = ((hi.x - lo.x) + (hi.y - lo.y) + (hi.z - lo.z)) / 3.0;
|
||||
if len < size {
|
||||
m.ai.mov.operation = Operation::Wait;
|
||||
m.velocity = m.velocity.scale(0.5);
|
||||
return;
|
||||
}
|
||||
m.velocity = m
|
||||
.velocity
|
||||
.add_vector(d.scale(m.ai.mov.speed_modifier * 0.05 / len));
|
||||
let yaw = match m.extra.point.filter(|_| m.ai.target.is_some()) {
|
||||
Some(t) => -((t[0] - m.position.x).atan2(t[2] - m.position.z) as f32).to_degrees(),
|
||||
None => -(m.velocity.x.atan2(m.velocity.z) as f32).to_degrees(),
|
||||
};
|
||||
m.yaw = yaw;
|
||||
m.body_yaw = yaw;
|
||||
}
|
||||
/// `Vex` travel with `noPhysics`: straight through blocks, air friction.
|
||||
pub fn travel(m: &mut Mob) -> bool {
|
||||
m.position = m.position.add_vector(m.velocity);
|
||||
m.velocity = Vec3::new(
|
||||
m.velocity.x * 0.91,
|
||||
m.velocity.y * 0.98,
|
||||
m.velocity.z * 0.91,
|
||||
);
|
||||
m.on_ground = false;
|
||||
true
|
||||
}
|
||||
/// `Vex.tick`: the limited life costs a heart a second once spent.
|
||||
pub fn ai_step(m: &mut Mob, w: &super::MobWorld) {
|
||||
m.extra.point = m
|
||||
.target_info(w)
|
||||
.map(|t| [t.position.x, t.position.y, t.position.z]);
|
||||
if m.extra.egg_time > 0 {
|
||||
m.extra.egg_time -= 1;
|
||||
if m.extra.egg_time == 0 {
|
||||
m.extra.egg_time = 20;
|
||||
m.damage(1.0, Damage::of(DamageKind::Generic));
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `VexModel.setupAnim`.
|
||||
pub fn anim(m: &Mob, s: &State, p: &mut Poses) {
|
||||
p.yrot("head", s.y_rot.to_radians());
|
||||
p.xrot("head", s.x_rot.to_radians());
|
||||
let bob = (s.age * 5.5).to_radians().cos() * 0.1;
|
||||
p.zrot("right_arm", PI / 5.0 + bob);
|
||||
p.zrot("left_arm", -(PI / 5.0 + bob));
|
||||
if m.extra.flag {
|
||||
p.xrot("body", 0.0);
|
||||
// Holding the sword in the right hand.
|
||||
p.xrot("right_arm", PI * 7.0 / 6.0);
|
||||
p.yrot("right_arm", PI / 12.0);
|
||||
p.zrot("right_arm", -0.471_238_88 - bob);
|
||||
} else {
|
||||
p.xrot("body", PI / 20.0);
|
||||
}
|
||||
let wing = 1.099_557_4 + (s.age * 45.836_624).to_radians().cos() * 16.2_f32.to_radians();
|
||||
p.yrot("left_wing", wing);
|
||||
p.yrot("right_wing", -wing);
|
||||
p.xrot("left_wing", 0.471_238_88);
|
||||
p.zrot("left_wing", -0.471_238_88);
|
||||
p.xrot("right_wing", 0.471_238_88);
|
||||
p.zrot("right_wing", 0.471_238_88);
|
||||
}
|
||||
/// The vex's texture: brighter while charging.
|
||||
pub fn texture(m: &Mob) -> &'static str {
|
||||
if m.extra.flag {
|
||||
"entity/illager/vex_charging"
|
||||
} else {
|
||||
"entity/illager/vex"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user