Give blazes and ghasts their attacks, and fix moved textures
Blazes hover toward targets above them, slow their fall, smoke and fire three-fireball volleys; ghasts float about, face their target, cry and shoot exploding fireballs credited to them. The blaze rods spin and ghast tentacles sway. Blazes, endermites, silverfish, experience orbs and the fishing bobber pointed at texture paths 26.3 moved, so they were invisible. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3724,7 +3724,13 @@ impl Game<'_> {
|
||||
.render(&scene, r.block_entities(), &mut out);
|
||||
}
|
||||
// Experience orbs (ExperienceOrbRenderer): pulsing billboards from a 4x4 icon sheet.
|
||||
if let Some(r) = self.res.atlas.sprites.get("entity/experience_orb").copied() {
|
||||
if let Some(r) = self
|
||||
.res
|
||||
.atlas
|
||||
.sprites
|
||||
.get("entity/experience/experience_orb")
|
||||
.copied()
|
||||
{
|
||||
let (yaw, pitch) = (self.yaw.to_radians(), self.pitch.to_radians());
|
||||
let forward = glam::Vec3::new(
|
||||
-yaw.sin() * pitch.cos(),
|
||||
|
||||
@@ -755,6 +755,10 @@ impl Game<'_> {
|
||||
// Mob particle bursts (hearts, smoke, splashes) around a point.
|
||||
if let Some(ty) = horizon_client::particles::ParticleType::from_name(kind) {
|
||||
let options = horizon_client::particles::ParticleOptions::simple(ty);
|
||||
// Count 0: one particle exactly there, at rest.
|
||||
if count == 0 {
|
||||
self.particles.add(&options, at, [0.0; 3]);
|
||||
}
|
||||
for _ in 0..count {
|
||||
let r = &mut self.world.random;
|
||||
let p = [
|
||||
@@ -1234,6 +1238,10 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fireball explosions are caused by the shooter.
|
||||
if let Some(owner) = self.combat.projectile_owner {
|
||||
self.note_attacker("minecraft:explosion", owner);
|
||||
}
|
||||
self.explode(atp, *power as f32)?;
|
||||
}
|
||||
(
|
||||
|
||||
@@ -491,7 +491,7 @@ impl Game<'_> {
|
||||
});
|
||||
}
|
||||
};
|
||||
if let Some(r) = atlas.sprites.get("entity/fishing_hook").copied() {
|
||||
if let Some(r) = atlas.sprites.get("entity/fishing/fishing_hook").copied() {
|
||||
let c = p + glam::DVec3::new(0.0, SIZE / 2.0, 0.0);
|
||||
let s = 0.25;
|
||||
quad(
|
||||
|
||||
@@ -36,7 +36,7 @@ fn pause_icons(w: f32, h: f32) -> [(f32, f32, &'static str); 4] {
|
||||
[
|
||||
(x0, y, "gui/sprites/pause_menu/bug"),
|
||||
(x0 + 24.0, y, "gui/sprites/pause_menu/social_interactions"),
|
||||
(x0 + 48.0, y, "gui/sprites/icon/friends"),
|
||||
(x0 + 48.0, y, "gui/sprites/friends/friends"),
|
||||
(x0 + 72.0, y, "gui/sprites/pause_menu/player_reporting"),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ pub mod hostile;
|
||||
pub mod keyframes;
|
||||
pub mod living;
|
||||
pub mod nav;
|
||||
pub mod nether;
|
||||
pub mod path;
|
||||
pub mod render;
|
||||
pub mod spawning;
|
||||
|
||||
@@ -70,6 +70,8 @@ pub enum Family {
|
||||
Witch,
|
||||
Enderman,
|
||||
Tame,
|
||||
/// Blazes and ghasts.
|
||||
Nether,
|
||||
/// Slimes and magma cubes.
|
||||
Cube,
|
||||
}
|
||||
@@ -97,6 +99,7 @@ pub fn family(s: Species) -> Family {
|
||||
S::Giant => Family::Inert,
|
||||
S::Witch => Family::Witch,
|
||||
S::Wolf | S::Cat => Family::Tame,
|
||||
S::Blaze | S::Ghast => Family::Nether,
|
||||
S::Enderman => Family::Enderman,
|
||||
S::Slime | S::MagmaCube => Family::Cube,
|
||||
_ => Family::Generic,
|
||||
@@ -113,6 +116,8 @@ pub fn register(m: &mut Mob) {
|
||||
Family::Witch => super::witch::register(m),
|
||||
Family::Tame if m.species() == Species::Cat => super::tame::register_cat(m),
|
||||
Family::Tame => super::tame::register(m),
|
||||
Family::Nether if m.species() == Species::Ghast => super::nether::register_ghast(m),
|
||||
Family::Nether => super::nether::register_blaze(m),
|
||||
Family::Enderman => super::enderman::register(m),
|
||||
Family::Cube => super::cube::register(m),
|
||||
}
|
||||
@@ -130,7 +135,10 @@ fn pre_tick(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
}
|
||||
}
|
||||
/// Move controls implemented by the species (MoveKind::Custom).
|
||||
pub fn custom_move_control(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
pub fn custom_move_control(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
if m.species() == Species::Ghast {
|
||||
return super::nether::ghast_move_control(m, w);
|
||||
}
|
||||
match family(m.species()) {
|
||||
Family::Aquatic => aquatic::fish_move_control(m),
|
||||
Family::Cube => super::cube::move_control(m, events),
|
||||
@@ -445,6 +453,7 @@ fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
| Species::Bogged
|
||||
| Species::WitherSkeleton => undead::custom_server_ai_step(m, cx),
|
||||
Species::Enderman => super::enderman::custom_server_ai_step(m, cx),
|
||||
Species::Blaze => super::nether::blaze_server_ai_step(m, cx),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -462,6 +471,7 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
Species::Enderman => super::enderman::ai_step(m, w, events),
|
||||
Species::Wolf => super::tame::ai_step(m, w, events),
|
||||
Species::Cat => super::tame::cat_ai_step(m, events),
|
||||
Species::Blaze => super::nether::blaze_ai_step(m, events),
|
||||
Species::Slime | Species::MagmaCube => super::cube::ai_step(m, w, events),
|
||||
Species::Chicken => farm::chicken_ai_step(m, w, events),
|
||||
Species::Sheep if m.extra.anim_ticks > 0 => {
|
||||
|
||||
@@ -419,6 +419,8 @@ pub fn setup(
|
||||
}
|
||||
Anim::Witch => super::witch::anim(m, s, p),
|
||||
Anim::Wolf => super::tame::anim(m, s, p),
|
||||
Anim::Blaze => super::nether::blaze_anim(s, p),
|
||||
Anim::Ghast => super::nether::ghast_anim(s, p),
|
||||
Anim::Feline if m.species() == super::Species::Cat => super::tame::cat_anim(m, s, p),
|
||||
Anim::Enderman => super::enderman::anim(m, s, p),
|
||||
Anim::Slime | Anim::MagmaCube => super::cube::anim(m, s, p),
|
||||
|
||||
@@ -126,7 +126,7 @@ impl Mob {
|
||||
pub fn move_control_tick(&mut self, w: &MobWorld, events: &mut Vec<super::MobEvent>) {
|
||||
let attr_speed = self.movement_speed();
|
||||
match self.ai.mov.kind {
|
||||
MoveKind::Custom => super::ai::custom_move_control(self, events),
|
||||
MoveKind::Custom => super::ai::custom_move_control(self, w, events),
|
||||
MoveKind::Ground => self.ground_move_tick(w, attr_speed),
|
||||
MoveKind::Flying { max_turn, hovers } => {
|
||||
let m = &mut self.ai.mov;
|
||||
|
||||
@@ -0,0 +1,410 @@
|
||||
//! Nether flyers: blazes (hovering, three-fireball volleys, the spinning
|
||||
//! rods) and ghasts (floating about, charging and shooting large fireballs).
|
||||
use super::{
|
||||
Mob, MobEvent, MobWorld, Who,
|
||||
anim::{Poses, State},
|
||||
control::{MoveKind, Operation},
|
||||
goals::{
|
||||
Cx, Goal, HurtByTarget, LOOK, LookAtPlayer, MOVE, NearestTarget, RandomLookAround, Stroll,
|
||||
goal_clone,
|
||||
},
|
||||
};
|
||||
use crate::projectiles::{Projectile, ProjectileKind};
|
||||
use horizon_core::{
|
||||
geometry::{Aabb, Vec3},
|
||||
random::RandomSource,
|
||||
};
|
||||
use std::f32::consts::PI;
|
||||
|
||||
/// `RandomSource.triangle(mode, deviation)`.
|
||||
fn triangle(m: &mut Mob, mode: f64, deviation: f64) -> f64 {
|
||||
mode + deviation * (m.random.next_double() - m.random.next_double())
|
||||
}
|
||||
|
||||
pub fn register_blaze(m: &mut Mob) {
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(4, BlazeAttack::default());
|
||||
g.add(7, Stroll::avoiding_water(1.0));
|
||||
g.add(8, LookAtPlayer::new(8.0));
|
||||
g.add(8, RandomLookAround::default());
|
||||
m.ai.targets.add(1, HurtByTarget::new().alert());
|
||||
m.ai.targets.add(2, NearestTarget::player(true));
|
||||
}
|
||||
/// `Blaze.BlazeAttackGoal`: melee up close, otherwise a 3-second charge and
|
||||
/// three small fireballs, then a five-second rest.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct BlazeAttack {
|
||||
step: i32,
|
||||
time: i32,
|
||||
last_seen: i32,
|
||||
}
|
||||
impl Goal for BlazeAttack {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE | LOOK
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
m.ai.target
|
||||
.and_then(|t| cx.w.target_info(t))
|
||||
.is_some_and(|t| t.alive && !(t.is_player && t.creative))
|
||||
}
|
||||
fn start(&mut self, _: &mut Mob, _: &mut Cx) {
|
||||
self.step = 0;
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
m.extra.flag = false;
|
||||
self.last_seen = 0;
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
self.time -= 1;
|
||||
let Some(who) = m.ai.target else {
|
||||
return;
|
||||
};
|
||||
let Some(t) = cx.w.target_info(who) else {
|
||||
return;
|
||||
};
|
||||
let sees = m.sees(cx.w, who);
|
||||
if sees {
|
||||
self.last_seen = 0;
|
||||
} else {
|
||||
self.last_seen += 1;
|
||||
}
|
||||
let d2 = m.distance_sqr(t.position);
|
||||
let follow = m.attrs.follow_range;
|
||||
let wanted = [t.position.x, t.position.y, t.position.z];
|
||||
if d2 < 4.0 {
|
||||
if !sees {
|
||||
return;
|
||||
}
|
||||
if self.time <= 0 {
|
||||
self.time = 20;
|
||||
super::ai::do_hurt_target(m, who, cx);
|
||||
}
|
||||
m.ai.mov.set_wanted(wanted[0], wanted[1], wanted[2], 1.0);
|
||||
} else if d2 < follow * follow && sees {
|
||||
let half = f64::from(m.height()) * 0.5;
|
||||
let xd = t.position.x - m.position.x;
|
||||
let yd = (t.bounds.min_position().y + t.bounds.max_position().y) * 0.5
|
||||
- (m.position.y + half);
|
||||
let zd = t.position.z - m.position.z;
|
||||
if self.time <= 0 {
|
||||
self.step += 1;
|
||||
if self.step == 1 {
|
||||
self.time = 60;
|
||||
m.extra.flag = true;
|
||||
} else if self.step <= 4 {
|
||||
self.time = 6;
|
||||
} else {
|
||||
self.time = 100;
|
||||
self.step = 0;
|
||||
m.extra.flag = false;
|
||||
}
|
||||
if self.step > 1 {
|
||||
let sqd = d2.sqrt().sqrt() * 0.5;
|
||||
cx.events.push(MobEvent::Sound(
|
||||
"entity.blaze.shoot",
|
||||
m.center(),
|
||||
1.0,
|
||||
(m.random.next_float() - m.random.next_float()) * 0.2 + 1.0,
|
||||
));
|
||||
let dir = [
|
||||
triangle(m, xd, 2.297 * sqd),
|
||||
yd,
|
||||
triangle(m, zd, 2.297 * sqd),
|
||||
];
|
||||
let start = Vec3::new(m.position.x, m.position.y + half + 0.5, m.position.z);
|
||||
cx.events.push(MobEvent::Projectile(Projectile::fireball(
|
||||
ProjectileKind::SmallFireball,
|
||||
start,
|
||||
Some(Who::Mob(m.id)),
|
||||
dir,
|
||||
)));
|
||||
}
|
||||
}
|
||||
m.look_at_speed([t.position.x, t.eye_y, t.position.z], 10.0, 10.0);
|
||||
} else if self.last_seen < 5 {
|
||||
m.ai.mov.set_wanted(wanted[0], wanted[1], wanted[2], 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `Blaze.aiStep`: slow falling, the burning sound and smoke.
|
||||
pub fn blaze_ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
|
||||
if !m.on_ground && m.velocity.y < 0.0 {
|
||||
m.velocity.y *= 0.6;
|
||||
}
|
||||
if m.random.next_int_bound(24).unwrap_or(1) == 0 {
|
||||
let volume = 1.0 + m.random.next_float();
|
||||
let pitch = m.random.next_float() * 0.7 + 0.3;
|
||||
events.push(MobEvent::Sound(
|
||||
"entity.blaze.burn",
|
||||
m.center(),
|
||||
volume,
|
||||
pitch,
|
||||
));
|
||||
}
|
||||
// getRandomX(0.5), getRandomY(), getRandomZ(0.5), at rest.
|
||||
let (w, h) = (f64::from(m.width()), f64::from(m.height()));
|
||||
for _ in 0..2 {
|
||||
let at = [
|
||||
m.position.x + w * (2.0 * m.random.next_double() - 1.0) * 0.5,
|
||||
m.position.y + h * m.random.next_double(),
|
||||
m.position.z + w * (2.0 * m.random.next_double() - 1.0) * 0.5,
|
||||
];
|
||||
events.push(MobEvent::Particles {
|
||||
kind: "large_smoke",
|
||||
at,
|
||||
count: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
/// `Blaze.customServerAiStep`: rise toward a target above the allowed offset.
|
||||
pub fn blaze_server_ai_step(m: &mut Mob, cx: &mut Cx) {
|
||||
m.extra.counter -= 1;
|
||||
if m.extra.counter <= 0 {
|
||||
m.extra.counter = 100;
|
||||
m.extra.vector[0] = triangle(m, 0.5, 6.891);
|
||||
}
|
||||
if let Some(t) = m.ai.target.and_then(|t| cx.w.target_info(t))
|
||||
&& t.alive
|
||||
&& !(t.is_player && t.creative)
|
||||
&& t.eye_y > m.eye_y() + m.extra.vector[0]
|
||||
{
|
||||
m.velocity.y += (0.3 - m.velocity.y) * 0.3;
|
||||
}
|
||||
}
|
||||
/// `BlazeModel.setupAnim`: three rings of rods circling and bobbing.
|
||||
pub fn blaze_anim(s: &State, p: &mut Poses) {
|
||||
let age = s.age;
|
||||
let mut angle = age * PI * -0.1;
|
||||
for i in 0..4 {
|
||||
let part = p.get(&format!("part{i}"));
|
||||
part[1] = -2.0 + ((i * 2) as f32 + age).mul_add(0.25, 0.0).cos();
|
||||
part[0] = angle.cos() * 9.0;
|
||||
part[2] = angle.sin() * 9.0;
|
||||
angle += PI / 2.0;
|
||||
}
|
||||
angle = PI / 4.0 + age * PI * 0.03;
|
||||
for i in 4..8 {
|
||||
let part = p.get(&format!("part{i}"));
|
||||
part[1] = 2.0 + (((i * 2) as f32 + age) * 0.25).cos();
|
||||
part[0] = angle.cos() * 7.0;
|
||||
part[2] = angle.sin() * 7.0;
|
||||
angle += PI / 2.0;
|
||||
}
|
||||
angle = 0.471_238_94 + age * PI * -0.05;
|
||||
for i in 8..12 {
|
||||
let part = p.get(&format!("part{i}"));
|
||||
part[1] = 11.0 + ((i as f32 * 1.5 + age) * 0.5).cos();
|
||||
part[0] = angle.cos() * 5.0;
|
||||
part[2] = angle.sin() * 5.0;
|
||||
angle += PI / 2.0;
|
||||
}
|
||||
p.yrot("head", s.y_rot.to_radians());
|
||||
p.xrot("head", s.x_rot.to_radians());
|
||||
}
|
||||
|
||||
pub fn register_ghast(m: &mut Mob) {
|
||||
m.ai.mov.kind = MoveKind::Custom;
|
||||
let g = &mut m.ai.goals;
|
||||
g.add(5, RandomFloatAround);
|
||||
g.add(7, GhastLook);
|
||||
g.add(7, GhastShoot { charge: 0 });
|
||||
m.ai.targets.add(
|
||||
1,
|
||||
NearestTarget::player(true).when(|m, w| {
|
||||
w.player
|
||||
.as_ref()
|
||||
.is_some_and(|p| (p.position.y - m.position.y).abs() <= 4.0)
|
||||
}),
|
||||
);
|
||||
}
|
||||
/// `Ghast.GhastMoveControl`: a push toward the wanted point every few ticks.
|
||||
pub fn ghast_move_control(m: &mut Mob, w: &MobWorld) {
|
||||
if m.ai.mov.operation != Operation::MoveTo {
|
||||
return;
|
||||
}
|
||||
m.extra.counter2 -= 1;
|
||||
if m.extra.counter2 > 0 {
|
||||
return;
|
||||
}
|
||||
m.extra.counter2 += m.random.next_int_bound(5).unwrap_or(0) + 2;
|
||||
let [wx, wy, wz] = m.ai.mov.wanted;
|
||||
let travel = Vec3::new(wx - m.position.x, wy - m.position.y, wz - m.position.z);
|
||||
let len = travel.length();
|
||||
if len < 1.0e-6 {
|
||||
return;
|
||||
}
|
||||
// canReach: the swept box stays clear along the way.
|
||||
let b = m.bounds();
|
||||
let steps = len.ceil() as i32;
|
||||
let clear = (1..=steps).all(|i| {
|
||||
let f = f64::from(i) / f64::from(steps);
|
||||
let d = Vec3::new(travel.x * f, travel.y * f, travel.z * f);
|
||||
w.no_collision(Aabb::new(
|
||||
b.min_position().add_vector(d),
|
||||
b.max_position().add_vector(d),
|
||||
))
|
||||
});
|
||||
if clear {
|
||||
// FLYING_SPEED 0.06 * 5 / 3.
|
||||
let speed = 0.06 * 5.0 / 3.0;
|
||||
m.velocity = m.velocity.add_vector(Vec3::new(
|
||||
travel.x / len * speed,
|
||||
travel.y / len * speed,
|
||||
travel.z / len * speed,
|
||||
));
|
||||
} else {
|
||||
m.ai.mov.operation = Operation::Wait;
|
||||
}
|
||||
}
|
||||
/// `Ghast.RandomFloatAroundGoal`.
|
||||
#[derive(Clone, Debug)]
|
||||
struct RandomFloatAround;
|
||||
impl Goal for RandomFloatAround {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
MOVE
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
if !m.ai.mov.has_wanted() {
|
||||
return true;
|
||||
}
|
||||
let [x, y, z] = m.ai.mov.wanted;
|
||||
let d =
|
||||
(x - m.position.x).powi(2) + (y - m.position.y).powi(2) + (z - m.position.z).powi(2);
|
||||
!(1.0..=3600.0).contains(&d)
|
||||
}
|
||||
fn can_continue(&mut self, _: &mut Mob, _: &mut Cx) -> bool {
|
||||
false
|
||||
}
|
||||
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let c = m.position;
|
||||
let mut r = || f64::from(m.random.next_float() * 2.0 - 1.0) * 16.0;
|
||||
let mut t = [c.x + r(), c.y + r(), c.z + r()];
|
||||
let top =
|
||||
cx.w.motion_blocking_height(t[0].floor() as i32, t[2].floor() as i32);
|
||||
if f64::from(top) < t[1].floor() && top > crate::chunk::MIN_Y {
|
||||
t[1] = c.y - (c.y - t[1]).abs();
|
||||
}
|
||||
m.ai.mov.set_wanted(t[0], t[1], t[2], 1.0);
|
||||
}
|
||||
}
|
||||
/// `Ghast.GhastLookGoal`: face the motion, or the target within 64 blocks.
|
||||
#[derive(Clone, Debug)]
|
||||
struct GhastLook;
|
||||
impl Goal for GhastLook {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
LOOK
|
||||
}
|
||||
fn can_use(&mut self, _: &mut Mob, _: &mut Cx) -> bool {
|
||||
true
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
match m.ai.target.and_then(|t| cx.w.target_info(t)) {
|
||||
None => {
|
||||
let v = m.velocity;
|
||||
m.yaw = -(v.x.atan2(v.z) as f32).to_degrees();
|
||||
m.body_yaw = m.yaw;
|
||||
}
|
||||
Some(t) => {
|
||||
if m.distance_sqr(t.position) < 4096.0 {
|
||||
let (dx, dz) = (t.position.x - m.position.x, t.position.z - m.position.z);
|
||||
m.yaw = -(dx.atan2(dz) as f32).to_degrees();
|
||||
m.body_yaw = m.yaw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `Ghast.GhastShootFireballGoal`: a second of charging, then a fireball.
|
||||
#[derive(Clone, Debug)]
|
||||
struct GhastShoot {
|
||||
charge: i32,
|
||||
}
|
||||
impl Goal for GhastShoot {
|
||||
goal_clone!();
|
||||
fn flags(&self) -> u8 {
|
||||
0
|
||||
}
|
||||
fn can_use(&mut self, m: &mut Mob, _: &mut Cx) -> bool {
|
||||
m.ai.target.is_some()
|
||||
}
|
||||
fn start(&mut self, _: &mut Mob, _: &mut Cx) {
|
||||
self.charge = 0;
|
||||
}
|
||||
fn stop(&mut self, m: &mut Mob, _: &mut Cx) {
|
||||
m.extra.flag = false;
|
||||
}
|
||||
fn every_tick(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn tick(&mut self, m: &mut Mob, cx: &mut Cx) {
|
||||
let Some(who) = m.ai.target else {
|
||||
return;
|
||||
};
|
||||
let Some(t) = cx.w.target_info(who) else {
|
||||
return;
|
||||
};
|
||||
if m.distance_sqr(t.position) < 4096.0 && m.sees(cx.w, who) {
|
||||
self.charge += 1;
|
||||
if self.charge == 10 {
|
||||
// LevelEvent 1015: the warning cry.
|
||||
cx.events.push(MobEvent::Sound(
|
||||
"entity.ghast.warn",
|
||||
m.center(),
|
||||
10.0,
|
||||
(m.random.next_float() - m.random.next_float()) * 0.2 + 1.0,
|
||||
));
|
||||
}
|
||||
if self.charge == 20 {
|
||||
let yaw = m.yaw.to_radians();
|
||||
let view = [-f64::from(yaw.sin()), f64::from(yaw.cos())];
|
||||
let half = f64::from(m.height()) * 0.5;
|
||||
let ty = (t.bounds.min_position().y + t.bounds.max_position().y) * 0.5;
|
||||
let dir = [
|
||||
t.position.x - (m.position.x + view[0] * 4.0),
|
||||
ty - (0.5 + m.position.y + half),
|
||||
t.position.z - (m.position.z + view[1] * 4.0),
|
||||
];
|
||||
// LevelEvent 1016: the shot.
|
||||
cx.events.push(MobEvent::Sound(
|
||||
"entity.ghast.shoot",
|
||||
m.center(),
|
||||
10.0,
|
||||
(m.random.next_float() - m.random.next_float()) * 0.2 + 1.0,
|
||||
));
|
||||
let start = Vec3::new(
|
||||
m.position.x + view[0] * 4.0,
|
||||
m.position.y + half + 0.5,
|
||||
m.position.z + view[1] * 4.0,
|
||||
);
|
||||
cx.events.push(MobEvent::Projectile(Projectile::fireball(
|
||||
ProjectileKind::LargeFireball { power: 1 },
|
||||
start,
|
||||
Some(Who::Mob(m.id)),
|
||||
dir,
|
||||
)));
|
||||
self.charge = -40;
|
||||
}
|
||||
} else if self.charge > 0 {
|
||||
self.charge -= 1;
|
||||
}
|
||||
m.extra.flag = self.charge > 10;
|
||||
}
|
||||
}
|
||||
/// `GhastModel.animateTentacles`.
|
||||
pub fn ghast_anim(s: &State, p: &mut Poses) {
|
||||
for i in 0..9 {
|
||||
let name = format!("tentacle{i}");
|
||||
if p.has(&name) {
|
||||
p.xrot(&name, 0.2 * (s.age * 0.3 + i as f32).sin() + 0.4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,14 @@ pub fn body(m: &Mob) -> (String, String) {
|
||||
baby_or(m, "wolf#main", "wolf_baby#main"),
|
||||
super::tame::texture(m),
|
||||
),
|
||||
S::Ghast => (
|
||||
"ghast#main".into(),
|
||||
if m.extra.flag {
|
||||
"entity/ghast/ghast_shooting".into()
|
||||
} else {
|
||||
"entity/ghast/ghast".into()
|
||||
},
|
||||
),
|
||||
S::Cat => (
|
||||
baby_or(m, "cat#main", "cat_baby#main"),
|
||||
super::tame::cat_texture(m),
|
||||
|
||||
@@ -790,7 +790,7 @@ pub const ALL: &[Def] = &[
|
||||
Endermite,
|
||||
"endermite",
|
||||
"endermite#main",
|
||||
"entity/endermite",
|
||||
"entity/endermite/endermite",
|
||||
A::Silverfish,
|
||||
[
|
||||
"entity.endermite.ambient",
|
||||
@@ -804,7 +804,7 @@ pub const ALL: &[Def] = &[
|
||||
Silverfish,
|
||||
"silverfish",
|
||||
"silverfish#main",
|
||||
"entity/silverfish",
|
||||
"entity/silverfish/silverfish",
|
||||
A::Silverfish,
|
||||
[
|
||||
"entity.silverfish.ambient",
|
||||
@@ -978,7 +978,7 @@ pub const ALL: &[Def] = &[
|
||||
Blaze,
|
||||
"blaze",
|
||||
"blaze#main",
|
||||
"entity/blaze",
|
||||
"entity/blaze/blaze",
|
||||
A::Blaze,
|
||||
[
|
||||
"entity.blaze.ambient",
|
||||
|
||||
@@ -19,6 +19,17 @@ pub struct TargetInfo {
|
||||
pub creative: bool,
|
||||
}
|
||||
impl MobWorld<'_> {
|
||||
/// `Heightmap.Types.MOTION_BLOCKING`: above the highest blocking block.
|
||||
pub fn motion_blocking_height(&self, x: i32, z: i32) -> i32 {
|
||||
let top = crate::chunk::MIN_Y + crate::chunk::HEIGHT;
|
||||
(crate::chunk::MIN_Y..top)
|
||||
.rev()
|
||||
.find(|&y| {
|
||||
let f = self.facts.get(self.world.block(x, y, z));
|
||||
f.full_collision || f.fluid != crate::blocks::Fluid::None
|
||||
})
|
||||
.map_or(crate::chunk::MIN_Y, |y| y + 1)
|
||||
}
|
||||
/// BlockState.isSolid (the legacy solid flag).
|
||||
pub fn solid(&self, x: i32, y: i32, z: i32) -> bool {
|
||||
self.data.state(self.world.block(x, y, z)).flags & data::SOLID != 0
|
||||
|
||||
Reference in New Issue
Block a user