Merge pull request #2690 from kacpherek/fix/mob-ambient-particles
🤖 Agent: Proven in union R1 (branch union/cg19-r1, main + 83 of kacpherek's PRs): the 98 harnesses it can affect, clippy -D warnings, tests, lan_e2e in-frame and on the server thread.
This commit is contained in:
@@ -3139,6 +3139,11 @@ impl Game<'_> {
|
||||
pos,
|
||||
data,
|
||||
} => self.consume_teleport_particles([pos.x, pos.y, pos.z], data),
|
||||
LevelEvent::LevelEvent {
|
||||
id: 2018,
|
||||
pos,
|
||||
data,
|
||||
} => self.enderman_teleport_particles([pos.x, pos.y, pos.z], data),
|
||||
LevelEvent::LevelEvent { id: 2003, pos, .. } => {
|
||||
self.eye_break_particles([pos.x, pos.y, pos.z]);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@ impl Game<'_> {
|
||||
return;
|
||||
}
|
||||
let mut events = Vec::new();
|
||||
let random = self.particles.level_random();
|
||||
for m in self.mobs.iter_mut().filter(|m| !m.removed) {
|
||||
ambient::client_ai_step(m, &mut events);
|
||||
ambient::client_particles(m, random, &mut events);
|
||||
}
|
||||
for event in events {
|
||||
match event {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//! Level events whose client handler (`LevelEventHandler`) spawns particles
|
||||
//! on a block: bone meal's growth (1505), dragon egg teleportation (2015), a
|
||||
//! consumable's teleport (2017), electric sparks (3002), waxing (3003), wax
|
||||
//! off (3004) and scraping (3005), plus the smoke, drips, egg and dragon
|
||||
//! fireball particles of 1501, 1502, 1504, 2006, 2009, 2012 and 3009.
|
||||
//! consumable's teleport (2017), an enderman's (2018), electric sparks (3002),
|
||||
//! waxing (3003), wax off (3004) and scraping (3005), plus the smoke, drips,
|
||||
//! egg and dragon fireball particles of 1501, 1502, 1504, 2006, 2009, 2012
|
||||
//! and 3009.
|
||||
use super::Game;
|
||||
use horizon_client::items::ItemStack;
|
||||
use horizon_client::particles::{self, ParticleOptions, ParticleType};
|
||||
@@ -24,6 +25,11 @@ impl Game<'_> {
|
||||
self.particles
|
||||
.block_teleportation(pos, data, [127, 127, 127]);
|
||||
}
|
||||
/// Event 2018: an enderman's portal trail.
|
||||
pub(super) fn enderman_teleport_particles(&mut self, pos: [i32; 3], data: i32) {
|
||||
self.particles
|
||||
.enderman_teleportation(pos, data, self.settings.particles);
|
||||
}
|
||||
/// `LevelEventHandler.levelEvent` 3002 to 3005, drawing from the client
|
||||
/// level's random.
|
||||
pub(super) fn block_particle_event(&mut self, id: i32, pos: BlockPos, data: i32) {
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
//! `level().isClientSide()` branches of `aiStep`: nothing of it reaches the
|
||||
//! server or goes over the network, so the window's game runs it, whether it
|
||||
//! simulates the world (in-frame) or follows a server.
|
||||
use super::{Mob, MobEvent, Species};
|
||||
use super::{Mob, MobEvent, Species, bee};
|
||||
use horizon_core::geometry::trig::Mth;
|
||||
use horizon_core::random::RandomSource;
|
||||
use std::f32::consts::PI;
|
||||
|
||||
/// `Enderman.aiStep`, `Endermite.aiStep` and `Blaze.aiStep` on a client:
|
||||
/// two portal particles a tick around endermen and endermites; two large
|
||||
@@ -53,3 +55,67 @@ pub fn client_ai_step(m: &mut Mob, out: &mut Vec<MobEvent>) {
|
||||
out.push(MobEvent::ParticleAt { kind, at, velocity });
|
||||
}
|
||||
}
|
||||
|
||||
/// `Phantom.tick` and `Bee.tick` on a client, which draw from the client
|
||||
/// level's random (`random`) and never from the mob's own, so a window that
|
||||
/// simulates the world keeps the mob's draws as the server has them: a
|
||||
/// phantom's wings leave mycelium dust, a bee carrying nectar now and then
|
||||
/// drips it.
|
||||
pub fn client_particles(m: &Mob, random: &mut impl RandomSource, out: &mut Vec<MobEvent>) {
|
||||
match m.species() {
|
||||
Species::Phantom => {
|
||||
// The wings flap every phantom in a different phase
|
||||
// (`getUniqueFlapTickOffset`).
|
||||
let flap = ((m.id.wrapping_mul(3).wrapping_add(m.age)) as i32 as f32
|
||||
* 7.448451
|
||||
* (PI / 180.0)
|
||||
+ PI)
|
||||
.mcos();
|
||||
let width = m.width() * 1.48;
|
||||
let yaw = m.yaw * (PI / 180.0);
|
||||
let (c, s) = (yaw.mcos() * width, yaw.msin() * width);
|
||||
let h = (0.3 + flap * 0.45) * m.height() * 2.5;
|
||||
let p = m.position;
|
||||
for (dx, dz) in [(c, s), (-c, -s)] {
|
||||
out.push(MobEvent::ParticleAt {
|
||||
kind: "mycelium",
|
||||
at: [p.x + f64::from(dx), p.y + f64::from(h), p.z + f64::from(dz)],
|
||||
velocity: [0.0; 3],
|
||||
});
|
||||
}
|
||||
}
|
||||
Species::Bee => {
|
||||
if !bee::has_nectar(m)
|
||||
|| !bee::get(m).is_some_and(|b| b.crops_grown < 10)
|
||||
|| random.next_float() >= 0.05
|
||||
{
|
||||
return;
|
||||
}
|
||||
// `for (i = 0; i < nextInt(2) + 1; i++)` rolls the bound each time.
|
||||
let mut i = 0;
|
||||
while i < random.next_int_bound(2).unwrap_or(0) + 1 {
|
||||
// Mth.lerp(level.random.nextDouble(), x - 0.3F, x + 0.3F).
|
||||
let spread = f64::from(0.3_f32);
|
||||
let lerp = |delta: f64, from: f64, to: f64| from + delta * (to - from);
|
||||
let x = lerp(
|
||||
random.next_double(),
|
||||
m.position.x - spread,
|
||||
m.position.x + spread,
|
||||
);
|
||||
let z = lerp(
|
||||
random.next_double(),
|
||||
m.position.z - spread,
|
||||
m.position.z + spread,
|
||||
);
|
||||
out.push(MobEvent::ParticleAt {
|
||||
kind: "falling_nectar",
|
||||
// getY(0.5).
|
||||
at: [x, m.position.y + f64::from(m.height()) * 0.5, z],
|
||||
velocity: [0.0; 3],
|
||||
});
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,10 +97,26 @@ pub fn teleport_to(
|
||||
return false;
|
||||
}
|
||||
let old = m.center();
|
||||
let old_block = [
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
];
|
||||
m.position = Vec3::new(x, ny, z);
|
||||
m.previous = m.position;
|
||||
m.velocity = Vec3::ZERO;
|
||||
m.ai.nav.stop();
|
||||
if !m.silent {
|
||||
// Level event 2018: the portal trail, from the old block to the new
|
||||
// one, packed as `BlockUtil.clampedPackDifferenceInPosition` does.
|
||||
let new_block = [x.floor() as i32, ny.floor() as i32, z.floor() as i32];
|
||||
let packed = |k: usize| ((new_block[k] - old_block[k]).clamp(-127, 127) + 127) & 255;
|
||||
events.push(MobEvent::LevelEvent {
|
||||
id: 2018,
|
||||
pos: old_block,
|
||||
data: packed(0) << 16 | packed(1) << 8 | packed(2),
|
||||
});
|
||||
}
|
||||
events.push(MobEvent::Sound("entity.enderman.teleport", old, 1.0, 1.0));
|
||||
events.push(MobEvent::Sound(
|
||||
"entity.enderman.teleport",
|
||||
|
||||
@@ -1199,6 +1199,43 @@ impl ParticleEngine {
|
||||
self.add(&options, position, velocity);
|
||||
}
|
||||
}
|
||||
/// `LevelEventHandler.levelEvent` 2018: an enderman's portal trail from
|
||||
/// where it was (`from`) to where it went, which `data` packs within
|
||||
/// (127, 127, 127). 128 portal particles along the way, spread about the
|
||||
/// width and height of an enderman.
|
||||
pub fn enderman_teleportation(&mut self, from: [i32; 3], data: i32, particle_level: u8) {
|
||||
// EntityTypes.ENDERMAN's dimensions.
|
||||
const WIDTH: f64 = 0.6_f32 as f64;
|
||||
const HEIGHT: f64 = 2.9_f32 as f64;
|
||||
let to = [
|
||||
from[0].wrapping_add(((data >> 16) & 255) - 127),
|
||||
from[1].wrapping_add(((data >> 8) & 255) - 127),
|
||||
from[2].wrapping_add((data & 255) - 127),
|
||||
]
|
||||
.map(f64::from);
|
||||
let from = from.map(f64::from);
|
||||
let options = ParticleOptions::simple(ParticleType::Portal);
|
||||
for _ in 0..128 {
|
||||
let r = &mut self.level_random;
|
||||
let t = r.next_double();
|
||||
let velocity = std::array::from_fn(|_| f64::from((r.next_float() - 0.5) * 0.2));
|
||||
// Mth.lerp(t, to, from).
|
||||
let position = [
|
||||
to[0] + t * (from[0] - to[0]) + (r.next_double() - 0.5) * WIDTH * 2.0,
|
||||
to[1] + t * (from[1] - to[1]) + r.next_double() * HEIGHT,
|
||||
to[2] + t * (from[2] - to[2]) + (r.next_double() - 0.5) * WIDTH * 2.0,
|
||||
];
|
||||
// The option roll shares the level random and precedes the distance check.
|
||||
let limited = match particle_level {
|
||||
1 => r.next_int_bound(3).unwrap_or(0) == 0,
|
||||
2 => true,
|
||||
_ => false,
|
||||
};
|
||||
if !limited {
|
||||
self.add(&options, position, velocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// `ClientPacketListener.handleExplosion` + `ClientExplosionTracker`: the
|
||||
/// explosion particle (the emitter unless `ServerExplosion.isSmall`) and up
|
||||
/// to 512 poof/smoke particles thrown from air inside the radius.
|
||||
|
||||
Reference in New Issue
Block a user