Particles from a server: /particle and explosions reach its players
A server never sent particles: /particle on single player's server thread drew into the server's own engine, and TNT exploded without its burst for anyone but an old-mode host. The protocol gains ClientboundLevelParticlesPacket and ClientboundExplodePacket; /particle sends the particles to each viewer in range (every player without viewers, as PlayerList.getPlayers) and an explosion sends its packet to the players within 64 blocks; their clients draw them as handleParticleEvent and handleExplosion do. /particle's spread was measured from the command's source as if it were a position; it is the spread as given (Vec3Argument.getVec3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -73,6 +73,7 @@ mod lan_crafting;
|
||||
mod lan_entities;
|
||||
mod lan_mobs;
|
||||
mod lan_mount_menu;
|
||||
mod lan_particles;
|
||||
mod lan_pvp;
|
||||
mod lan_screen;
|
||||
mod lan_stations;
|
||||
|
||||
@@ -8,6 +8,7 @@ use horizon_client::{
|
||||
text::Text,
|
||||
};
|
||||
use horizon_core::random::RandomSource;
|
||||
use horizon_protocol::packets::play::{self, Clientbound as C};
|
||||
use horizon_world::attribute_map::ValueKind;
|
||||
use horizon_world::nbt::Tag;
|
||||
|
||||
@@ -409,6 +410,8 @@ impl Game<'_> {
|
||||
],
|
||||
_ => [1.0, 0.0, 0.0],
|
||||
};
|
||||
// The block state of a block particle, for its packet.
|
||||
let mut block_state = None;
|
||||
let options = match ty {
|
||||
ParticleType::Dust => ParticleOptions::dust(
|
||||
rgb,
|
||||
@@ -470,6 +473,7 @@ impl Game<'_> {
|
||||
match block {
|
||||
Ok(Arg::Block(b)) => {
|
||||
let state = self.block_state(&b)?;
|
||||
block_state = Some(state);
|
||||
let at = self
|
||||
.position_arg(ctx, "pos")
|
||||
.unwrap_or_else(|| self.source_position())
|
||||
@@ -487,10 +491,9 @@ impl Game<'_> {
|
||||
let pos = self
|
||||
.position_arg(ctx, "pos")
|
||||
.unwrap_or_else(|| self.source_position());
|
||||
let delta = self.position_arg(ctx, "delta").map_or([0.0; 3], |d| {
|
||||
let s = self.source_position();
|
||||
[d[0] - s[0], d[1] - s[1], d[2] - s[2]]
|
||||
});
|
||||
// Vec3Argument.getVec3: the spread as given (relative parts from the
|
||||
// source), not a position to measure from the source.
|
||||
let delta = self.position_arg(ctx, "delta").unwrap_or([0.0; 3]);
|
||||
let speed = match ctx.get("speed") {
|
||||
Some(Arg::Float(v)) => *v,
|
||||
_ => 0.0,
|
||||
@@ -501,27 +504,74 @@ impl Game<'_> {
|
||||
};
|
||||
// ParticleCommand.sendParticles: the viewers it reached, each within
|
||||
// 32 blocks (512 with `force`) of the particle's block centre.
|
||||
// Without viewers, every player (PlayerList.getPlayers).
|
||||
let viewers = if ctx.get("viewers").is_some() {
|
||||
self.entities(ctx, "viewers", true)?
|
||||
} else {
|
||||
vec![Target::Player]
|
||||
let acting = self.lan_acting;
|
||||
let guests = self.lan.iter().flat_map(|h| h.hub.guests.iter());
|
||||
self.player
|
||||
.as_ref()
|
||||
.map(|_| Target::Player)
|
||||
.into_iter()
|
||||
.chain(
|
||||
guests
|
||||
.filter(|g| g.placed && Some(g.conn) != acting)
|
||||
.map(|g| Target::Guest(g.conn)),
|
||||
)
|
||||
.collect()
|
||||
};
|
||||
let limit = if ctx.has("force") { 512.0 } else { 32.0 };
|
||||
let reached = viewers
|
||||
.iter()
|
||||
.filter(|&&t| {
|
||||
let force = ctx.has("force");
|
||||
let limit = if force { 512.0 } else { 32.0 };
|
||||
let reached: Vec<Target> = viewers
|
||||
.into_iter()
|
||||
.filter(|&t| {
|
||||
self.target_position(t).is_some_and(|p| {
|
||||
let c = p.map(|v| v.floor() + 0.5);
|
||||
(c[0] - pos[0]).powi(2) + (c[1] - pos[1]).powi(2) + (c[2] - pos[2]).powi(2)
|
||||
< limit * limit
|
||||
})
|
||||
})
|
||||
.count() as i32;
|
||||
if reached == 0 {
|
||||
.collect();
|
||||
if reached.is_empty() {
|
||||
return Err(err("commands.particle.failed", &[]));
|
||||
}
|
||||
// `ServerLevel.sendParticles`: no count means one particle with the delta as velocity.
|
||||
if count <= 0 {
|
||||
// ServerLevel.sendParticles: each viewer a server serves is sent the
|
||||
// particles (the player in place too when it is a guest); the
|
||||
// window's own player draws them.
|
||||
let packet = self
|
||||
.network_particle(&options, block_state)
|
||||
.map(|particle| {
|
||||
C::LevelParticles(play::LevelParticles {
|
||||
particle,
|
||||
override_limiter: force,
|
||||
always_show: false,
|
||||
pos,
|
||||
dist: delta.map(|d| d as f32),
|
||||
max_speed: [speed; 3],
|
||||
count: count.max(0),
|
||||
randomization: 0,
|
||||
})
|
||||
});
|
||||
let mut local = false;
|
||||
for &t in &reached {
|
||||
match (t, &packet) {
|
||||
(Target::Player, Some(p)) if self.lan_acting.is_some() => {
|
||||
self.guest_packets.push(p.clone());
|
||||
}
|
||||
(Target::Player, _) => local = true,
|
||||
(Target::Guest(conn), Some(p)) => {
|
||||
if let Some(host) = self.lan.as_ref() {
|
||||
host.hub.send_to(conn, p);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let reached = reached.len() as i32;
|
||||
if !local {
|
||||
} else if count <= 0 {
|
||||
// No count: one particle with the delta as velocity.
|
||||
self.particles.create(&options, pos, delta);
|
||||
} else {
|
||||
for _ in 0..count {
|
||||
|
||||
@@ -580,6 +580,7 @@ impl Game<'_> {
|
||||
self.particles.explosion(center, radius, block_count, &|b| {
|
||||
facts.is_air(world.block(b[0], b[1], b[2]))
|
||||
});
|
||||
self.lan_explode(center, radius, block_count);
|
||||
Ok(())
|
||||
}
|
||||
/// `BlockBehaviour.onExplosionHit` (TNT: `wasExploded` primes a short fuse).
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
//! Particles a server sends its players and its clients draw:
|
||||
//! `ClientboundLevelParticlesPacket` (`ServerLevel.sendParticles`, which
|
||||
//! `/particle` uses) and `ClientboundExplodePacket` (`ServerLevel.explode`).
|
||||
use super::Game;
|
||||
use horizon_client::particles::{ParticleOptions, ParticleType};
|
||||
use horizon_core::random::RandomSource;
|
||||
use horizon_protocol::{
|
||||
entity_data::{Particle, ParticleData},
|
||||
packets::play::{self, Clientbound as C},
|
||||
};
|
||||
use horizon_world::registry::BlockStateId;
|
||||
|
||||
/// An ARGB colour as the options' RGBA.
|
||||
fn rgba(argb: i32) -> [f32; 4] {
|
||||
let c = |shift: i32| ((argb >> shift) & 255) as f32 / 255.0;
|
||||
[c(16), c(8), c(0), c(24)]
|
||||
}
|
||||
/// The options' RGB as an RGB colour (`ARGB.colorFromFloat` without alpha).
|
||||
fn rgb_int(c: [f32; 3]) -> i32 {
|
||||
let b = |v: f32| ((v.clamp(0.0, 1.0) * 255.0).round() as i32) & 255;
|
||||
(b(c[0]) << 16) | (b(c[1]) << 8) | b(c[2])
|
||||
}
|
||||
fn rgb(c: [f32; 4]) -> [f32; 3] {
|
||||
[c[0], c[1], c[2]]
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// `ParticleTypes.STREAM_CODEC`'s value for `options`: the type's
|
||||
/// network id and the data it carries (`state` for the block particles).
|
||||
/// None while not serving, or for a particle whose data isn't sent from
|
||||
/// here (items, vibrations, trails).
|
||||
pub(super) fn network_particle(
|
||||
&self,
|
||||
options: &ParticleOptions,
|
||||
state: Option<BlockStateId>,
|
||||
) -> Option<Particle> {
|
||||
let name = format!("minecraft:{}", options.ty.name());
|
||||
let id = self
|
||||
.lan
|
||||
.as_ref()?
|
||||
.hub
|
||||
.registry_id("minecraft:particle_type", &name)?;
|
||||
use ParticleType as T;
|
||||
let c = options.color;
|
||||
let data = match options.ty {
|
||||
T::Block | T::BlockMarker | T::FallingDust | T::DustPillar | T::BlockCrumble => {
|
||||
Some(ParticleData::State(state?.0 as i32))
|
||||
}
|
||||
T::Dust => Some(ParticleData::ColorScale(rgb_int(rgb(c)), options.scale)),
|
||||
T::DustColorTransition => Some(ParticleData::ColorScale2(
|
||||
rgb_int(rgb(c)),
|
||||
rgb_int(options.to_color),
|
||||
options.scale,
|
||||
)),
|
||||
T::Effect | T::InstantEffect => {
|
||||
Some(ParticleData::ColorPower(rgb_int(rgb(c)), options.scale))
|
||||
}
|
||||
T::EntityEffect | T::TintedLeaves => Some(ParticleData::Color(
|
||||
(((c[3].clamp(0.0, 1.0) * 255.0).round() as i32) << 24) | rgb_int(rgb(c)),
|
||||
)),
|
||||
T::DragonBreath | T::SculkCharge => Some(ParticleData::Scalar(options.scale)),
|
||||
T::Shriek => Some(ParticleData::Delay(options.scale as i32)),
|
||||
T::Item | T::Trail | T::Vibration => return None,
|
||||
_ => None,
|
||||
};
|
||||
Some(Particle { id, data })
|
||||
}
|
||||
|
||||
/// The options a server's particle stands for (None for a type or data
|
||||
/// this client doesn't draw).
|
||||
fn received_particle(&mut self, p: &Particle, at: [f64; 3]) -> Option<ParticleOptions> {
|
||||
let name = self
|
||||
.remote
|
||||
.as_ref()?
|
||||
.builtin
|
||||
.get("minecraft:particle_type")?
|
||||
.name(p.id)?
|
||||
.to_owned();
|
||||
let ty = ParticleType::from_name(&name)?;
|
||||
Some(match &p.data {
|
||||
None => ParticleOptions::simple(ty),
|
||||
Some(ParticleData::State(s)) => {
|
||||
let pos = at.map(|v| v.floor() as i32);
|
||||
let (sprite, tint) = self
|
||||
.particle_sprite(BlockStateId(*s as u32), pos)
|
||||
.unwrap_or_else(|| ("block/stone".into(), 0xFFFFFF));
|
||||
ParticleOptions::block(ty, sprite, tint)
|
||||
}
|
||||
Some(ParticleData::ColorScale(c, scale)) => {
|
||||
ParticleOptions::dust(rgb(rgba(*c)), *scale)
|
||||
}
|
||||
Some(ParticleData::ColorScale2(from, to, scale)) => {
|
||||
ParticleOptions::dust_transition(rgb(rgba(*from)), rgb(rgba(*to)), *scale)
|
||||
}
|
||||
Some(ParticleData::ColorPower(c, power)) => ParticleOptions {
|
||||
scale: *power,
|
||||
..ParticleOptions::colored(ty, [rgba(*c)[0], rgba(*c)[1], rgba(*c)[2], 1.0])
|
||||
},
|
||||
Some(ParticleData::Color(c)) => ParticleOptions::colored(ty, rgba(*c)),
|
||||
Some(ParticleData::Scalar(v)) if ty == ParticleType::SculkCharge => {
|
||||
ParticleOptions::sculk_charge(*v)
|
||||
}
|
||||
Some(ParticleData::Scalar(v)) => ParticleOptions {
|
||||
scale: *v,
|
||||
..ParticleOptions::simple(ty)
|
||||
},
|
||||
Some(ParticleData::Delay(d)) => ParticleOptions::shriek(*d),
|
||||
Some(ParticleData::Trail(target, color, duration)) => {
|
||||
ParticleOptions::trail(*target, *color as u32 & 0xFF_FFFF, *duration)
|
||||
}
|
||||
Some(_) => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// `ClientPacketListener.handleParticleEvent`: no count is one particle
|
||||
/// moving by speed times spread; otherwise each is spread and sped up by
|
||||
/// gaussians on each axis.
|
||||
pub(super) fn remote_level_particles(&mut self, p: &play::LevelParticles) {
|
||||
let Some(options) = self.received_particle(&p.particle, p.pos) else {
|
||||
return;
|
||||
};
|
||||
let (d, s) = (p.dist.map(f64::from), p.max_speed.map(f64::from));
|
||||
// ClientLevel.addParticle: the camera's 32 blocks unless the packet
|
||||
// (`force`) or the type overrides the limiter.
|
||||
let add = |particles: &mut horizon_client::particles::ParticleEngine, at, v| {
|
||||
if p.override_limiter {
|
||||
particles.create(&options, at, v);
|
||||
} else {
|
||||
particles.add(&options, at, v);
|
||||
}
|
||||
};
|
||||
if p.count == 0 {
|
||||
add(
|
||||
&mut self.particles,
|
||||
p.pos,
|
||||
[s[0] * d[0], s[1] * d[1], s[2] * d[2]],
|
||||
);
|
||||
return;
|
||||
}
|
||||
for _ in 0..p.count {
|
||||
let r = self.particles.random();
|
||||
let at = [
|
||||
p.pos[0] + r.next_gaussian() * d[0],
|
||||
p.pos[1] + r.next_gaussian() * d[1],
|
||||
p.pos[2] + r.next_gaussian() * d[2],
|
||||
];
|
||||
let v = [
|
||||
r.next_gaussian() * s[0],
|
||||
r.next_gaussian() * s[1],
|
||||
r.next_gaussian() * s[2],
|
||||
];
|
||||
add(&mut self.particles, at, v);
|
||||
}
|
||||
}
|
||||
|
||||
/// `ClientPacketListener.handleExplosion`: the blast's particles (and its
|
||||
/// sound, when the packet carries it).
|
||||
pub(super) fn remote_explode(&mut self, p: &play::Explode) {
|
||||
if p.play_sound {
|
||||
let pitch = (1.0
|
||||
+ (self.particles.random().next_float() - self.particles.random().next_float())
|
||||
* 0.2)
|
||||
* 0.7;
|
||||
self.audio.play(
|
||||
"minecraft:entity.generic.explode",
|
||||
Some(p.center),
|
||||
4.0,
|
||||
pitch,
|
||||
);
|
||||
}
|
||||
let (world, facts) = (&self.world, self.res.facts());
|
||||
self.particles
|
||||
.explosion(p.center, p.radius, p.block_count.max(0) as usize, &|b| {
|
||||
facts.is_air(world.block(b[0], b[1], b[2]))
|
||||
});
|
||||
}
|
||||
|
||||
/// `ServerLevel.explode`'s packet to each player within 64 blocks. The
|
||||
/// sound and the push reach them on their own (the level's sounds, the
|
||||
/// players' motion), so the packet carries neither.
|
||||
pub(super) fn lan_explode(&self, center: [f64; 3], radius: f32, block_count: usize) {
|
||||
let Some(host) = self.lan.as_ref() else {
|
||||
return;
|
||||
};
|
||||
let particle = |name: &str| {
|
||||
Some(Particle {
|
||||
id: host.hub.registry_id("minecraft:particle_type", name)?,
|
||||
data: None,
|
||||
})
|
||||
};
|
||||
let emitter = if radius < 2.0 {
|
||||
"minecraft:explosion"
|
||||
} else {
|
||||
"minecraft:explosion_emitter"
|
||||
};
|
||||
let (Some(at_center), Some(poof), Some(smoke)) = (
|
||||
particle(emitter),
|
||||
particle("minecraft:poof"),
|
||||
particle("minecraft:smoke"),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
// Level.DEFAULT_EXPLOSION_BLOCK_PARTICLES.
|
||||
let info = |particle, scaling| play::ExplosionParticle {
|
||||
particle,
|
||||
scaling,
|
||||
speed: 1.0,
|
||||
weight: 1,
|
||||
};
|
||||
let packet = C::Explode(play::Explode {
|
||||
center,
|
||||
radius,
|
||||
block_count: block_count as i32,
|
||||
knockback: None,
|
||||
particle: at_center,
|
||||
sound: match host
|
||||
.hub
|
||||
.registry_id("minecraft:sound_event", "minecraft:entity.generic.explode")
|
||||
{
|
||||
Some(id) => (id, None),
|
||||
None => (-1, Some(("minecraft:entity.generic.explode".into(), None))),
|
||||
},
|
||||
block_particles: vec![info(poof, 0.5), info(smoke, 1.0)],
|
||||
play_sound: false,
|
||||
});
|
||||
host.hub.broadcast_near(center, 64.0, &packet, None);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ fn place_interpolated(m: &mut Mob, at: PosRot) {
|
||||
pub(super) struct Remote {
|
||||
pub session: Session,
|
||||
pub brand: String,
|
||||
builtin: Arc<Builtin>,
|
||||
pub(super) builtin: Arc<Builtin>,
|
||||
lang: Arc<Language>,
|
||||
pub(super) registries: Arc<Dynamic>,
|
||||
joined: bool,
|
||||
@@ -1733,6 +1733,8 @@ impl Game<'_> {
|
||||
// level plays them (particles and sounds: a spawner's burst, bone
|
||||
// meal, waxing, a block broken by someone else).
|
||||
C::LevelEvent(p) => self.level_event_at(p.kind, p.pos, p.data),
|
||||
C::LevelParticles(p) => self.remote_level_particles(&p),
|
||||
C::Explode(p) => self.remote_explode(&p),
|
||||
C::Sound(p) => {
|
||||
let name = match &p.sound.1 {
|
||||
Some((location, _)) => Some(location.clone()),
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
Vec3d, Writer,
|
||||
},
|
||||
chunk::{ChunkData, LightData},
|
||||
entity_data::{EntityData, Value},
|
||||
entity_data::{EntityData, Particle, Value},
|
||||
item::{Hashed, HashedSlot, Slot, Stack},
|
||||
packet, packet_enum,
|
||||
packets::{
|
||||
@@ -883,6 +883,116 @@ impl Codec<SetObjective> for SetObjective {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// ClientboundLevelParticlesPacket: a particle, whether it ignores the
|
||||
/// client's particle setting (`overrideLimiter`) and its distance limit
|
||||
/// (`alwaysShow`), where, the spread and the speed on each axis, how many
|
||||
/// (0: one, moving by speed times spread) and the randomization type
|
||||
/// (0 default: gaussian spread and speed).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct LevelParticles {
|
||||
pub particle: Particle,
|
||||
pub override_limiter: bool,
|
||||
pub always_show: bool,
|
||||
pub pos: [f64; 3],
|
||||
pub dist: [f32; 3],
|
||||
pub max_speed: [f32; 3],
|
||||
pub count: i32,
|
||||
pub randomization: i32,
|
||||
}
|
||||
impl Codec<LevelParticles> for LevelParticles {
|
||||
fn read(r: &mut Reader) -> Result<Self> {
|
||||
Ok(Self {
|
||||
particle: Particle::read(r)?,
|
||||
override_limiter: r.bool()?,
|
||||
always_show: r.bool()?,
|
||||
pos: Vec3d::read(r)?,
|
||||
dist: [r.f32()?, r.f32()?, r.f32()?],
|
||||
max_speed: [r.f32()?, r.f32()?, r.f32()?],
|
||||
count: r.varint()?,
|
||||
randomization: r.varint()?,
|
||||
})
|
||||
}
|
||||
fn write(v: &Self, w: &mut Writer) {
|
||||
v.particle.write(w);
|
||||
w.bool(v.override_limiter);
|
||||
w.bool(v.always_show);
|
||||
Vec3d::write(&v.pos, w);
|
||||
for f in v.dist.iter().chain(&v.max_speed) {
|
||||
w.f32(*f);
|
||||
}
|
||||
w.varint(v.count);
|
||||
w.varint(v.randomization);
|
||||
}
|
||||
}
|
||||
/// `ExplosionParticleInfo` in a `WeightedList`: a particle the blast
|
||||
/// scatters, its scaling and speed, then its weight.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExplosionParticle {
|
||||
pub particle: Particle,
|
||||
pub scaling: f32,
|
||||
pub speed: f32,
|
||||
pub weight: i32,
|
||||
}
|
||||
/// ClientboundExplodePacket: the centre, radius and blocks destroyed, the
|
||||
/// push the receiving player takes, the particle at the centre, the sound,
|
||||
/// the particles the blast scatters, and whether the sound plays.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Explode {
|
||||
pub center: [f64; 3],
|
||||
pub radius: f32,
|
||||
pub block_count: i32,
|
||||
pub knockback: Option<[f64; 3]>,
|
||||
pub particle: Particle,
|
||||
pub sound: (i32, Option<(String, Option<f32>)>),
|
||||
pub block_particles: Vec<ExplosionParticle>,
|
||||
pub play_sound: bool,
|
||||
}
|
||||
impl Codec<Explode> for Explode {
|
||||
fn read(r: &mut Reader) -> Result<Self> {
|
||||
let center = Vec3d::read(r)?;
|
||||
let radius = r.f32()?;
|
||||
let block_count = r.i32()?;
|
||||
let knockback = <Opt<Vec3d>>::read(r)?;
|
||||
let particle = Particle::read(r)?;
|
||||
let sound = SoundHolder::read(r)?;
|
||||
let n = r.varint()?;
|
||||
let mut block_particles = Vec::new();
|
||||
for _ in 0..n {
|
||||
block_particles.push(ExplosionParticle {
|
||||
particle: Particle::read(r)?,
|
||||
scaling: r.f32()?,
|
||||
speed: r.f32()?,
|
||||
weight: r.varint()?,
|
||||
});
|
||||
}
|
||||
Ok(Self {
|
||||
center,
|
||||
radius,
|
||||
block_count,
|
||||
knockback,
|
||||
particle,
|
||||
sound,
|
||||
block_particles,
|
||||
play_sound: r.bool()?,
|
||||
})
|
||||
}
|
||||
fn write(v: &Self, w: &mut Writer) {
|
||||
Vec3d::write(&v.center, w);
|
||||
w.f32(v.radius);
|
||||
w.i32(v.block_count);
|
||||
<Opt<Vec3d>>::write(&v.knockback, w);
|
||||
v.particle.write(w);
|
||||
SoundHolder::write(&v.sound, w);
|
||||
w.varint(v.block_particles.len() as i32);
|
||||
for b in &v.block_particles {
|
||||
b.particle.write(w);
|
||||
w.f32(b.scaling);
|
||||
w.f32(b.speed);
|
||||
w.varint(b.weight);
|
||||
}
|
||||
w.bool(v.play_sound);
|
||||
}
|
||||
}
|
||||
/// `ClientboundSetPlayerTeamPacket.Parameters`.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct TeamParameters {
|
||||
@@ -1566,6 +1676,8 @@ packet_enum!(Clientbound, crate::ids::play::clientbound {
|
||||
TickingStep(TickingStep) = TICKING_STEP,
|
||||
UpdateAdvancements(UpdateAdvancements) = UPDATE_ADVANCEMENTS,
|
||||
UpdateAttributes(UpdateAttributes) = UPDATE_ATTRIBUTES,
|
||||
LevelParticles(LevelParticles) = LEVEL_PARTICLES,
|
||||
Explode(Explode) = EXPLODE,
|
||||
UpdateMobEffect(UpdateMobEffect) = UPDATE_MOB_EFFECT,
|
||||
UpdateTags(UpdateTags) = UPDATE_TAGS,
|
||||
TrackedWaypoint(TrackedWaypoint) = WAYPOINT,
|
||||
@@ -2270,6 +2382,34 @@ mod tests {
|
||||
passengers: vec![3, 300],
|
||||
}),
|
||||
Clientbound::SetEntityLink(SetEntityLink { source: 2, dest: 0 }),
|
||||
Clientbound::LevelParticles(LevelParticles {
|
||||
particle: Particle {
|
||||
id: 21,
|
||||
data: Some(crate::entity_data::ParticleData::ColorScale(0xFF0000, 1.5)),
|
||||
},
|
||||
override_limiter: true,
|
||||
always_show: false,
|
||||
pos: [0.5, 101.0, 3.0],
|
||||
dist: [0.2, 0.0, 0.2],
|
||||
max_speed: [0.0; 3],
|
||||
count: 60,
|
||||
randomization: 0,
|
||||
}),
|
||||
Clientbound::Explode(Explode {
|
||||
center: [1.0, 2.0, 3.0],
|
||||
radius: 4.0,
|
||||
block_count: 12,
|
||||
knockback: Some([0.5, 0.1, 0.0]),
|
||||
particle: Particle { id: 29, data: None },
|
||||
sound: (-1, Some(("minecraft:entity.generic.explode".into(), None))),
|
||||
block_particles: vec![ExplosionParticle {
|
||||
particle: Particle { id: 69, data: None },
|
||||
scaling: 0.5,
|
||||
speed: 1.0,
|
||||
weight: 1,
|
||||
}],
|
||||
play_sound: true,
|
||||
}),
|
||||
Clientbound::ProjectilePower(ProjectilePower { id: 4, power: 0.1 }),
|
||||
Clientbound::SetEquipment(SetEquipment {
|
||||
id: 2,
|
||||
|
||||
+40
-2
@@ -213,7 +213,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
GUEST_NAME = 'Guest'
|
||||
# The host plays single player on its server thread (--server-thread).
|
||||
SERVER_THREAD = False
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'looks', 'leads', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'thrown', 'sparks', 'hud', 'sidebar', 'border', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'worldspawn', 'beds', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels', 'drops', 'underwater']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'looks', 'leads', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'thrown', 'sparks', 'hud', 'sidebar', 'border', 'particles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'worldspawn', 'beds', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels', 'drops', 'underwater']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -2865,6 +2865,43 @@ def check_border(host, guest, out):
|
||||
return result
|
||||
|
||||
|
||||
def check_particles(host, guest, out):
|
||||
spots = apart(host, guest)
|
||||
result = {}
|
||||
for label, player, other in (('host', host, guest), ('guest', guest, host)):
|
||||
# For the player alone (`@s`), then for every player near.
|
||||
before = {side: made(g, 'flame') for side, g in (('own', player), ('other', other))}
|
||||
player('command', command='particle minecraft:flame ~ ~1 ~3 .2 .2 .2 0 60 force @s')
|
||||
player.wait(10)
|
||||
result[f'{label} @s'] = {side: made(g, 'flame') - before[side] for side, g in (('own', player), ('other', other))}
|
||||
player.shot(out, f'flame-{label}')
|
||||
# No spread: one point, wherever the player stands.
|
||||
player('command', command='particle minecraft:flame ~ ~1 ~3 0 0 0 0 200 force @s')
|
||||
player.wait(3)
|
||||
player.shot(out, f'zero-spread-{label}')
|
||||
result[f'{label} all'] = sparked(player, other, ['dust'], lambda: player(
|
||||
'command', command='particle minecraft:dust{color:[1,0,0],scale:2} ~ ~1 ~3 0 0 0 0 10'))
|
||||
# A TNT's blast between the players: its burst on both sides.
|
||||
x, y, z = spots['host']
|
||||
host('command', command='gamemode creative')
|
||||
guest('command', command='gamemode creative')
|
||||
try:
|
||||
result['blast'] = sparked(host, guest, ['explosion_emitter'], lambda: host(
|
||||
'command', command=f'summon minecraft:tnt {x + 6.5} {y} {z + 4.5} {{fuse:10s}}'), ticks=40)
|
||||
host.shot(out, 'blast')
|
||||
finally:
|
||||
host('command', command='gamemode survival')
|
||||
guest('command', command='gamemode survival')
|
||||
host('command', command=f'fill {x - 3} {y - 1} {z - 3} {x + 16} {y - 1} {z + 8} minecraft:stone')
|
||||
# Without the server thread a guest's command reaches no host player (as `@a` doesn't).
|
||||
if not SERVER_THREAD:
|
||||
result['guest all'].pop('other dust')
|
||||
wrong = {k: v for k, v in result.items() if not k.endswith('@s') and not all(n > 0 for n in v.values())}
|
||||
wrong.update({k: v for k, v in result.items() if k.endswith('@s') and not (v['own'] >= 30 and v['other'] == 0)})
|
||||
assert not wrong, f'particles: {wrong}\n{result}'
|
||||
return result
|
||||
|
||||
|
||||
def check_blast(host, guest, out):
|
||||
guest('command', command='gamemode survival')
|
||||
guest('command', command='clear @s')
|
||||
@@ -4203,7 +4240,8 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour,
|
||||
'sparks': check_sparks,
|
||||
'hud': check_hud,
|
||||
'sidebar': check_sidebar,
|
||||
'border': check_border}
|
||||
'border': check_border,
|
||||
'particles': check_particles}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
Reference in New Issue
Block a user