Skip to main content

yog_event/
particle.rs

1//! Particles: the host's actions.
2
3use crate::Point;
4use yog_data::Schema;
5use yog_ids as ids;
6
7/// What a spawn makes: a particle type (the game's, `minecraft:smoke`, or a
8/// mod's `.yparticle`) and what it's given — the host writes it as its
9/// version takes it.
10#[derive(Debug, Clone, PartialEq, Schema)]
11pub struct ParticleOptions {
12    pub id: String,
13    /// `0xRRGGBB`: a mod's particle's colour, the game's dust's.
14    pub color: Option<u32>,
15    /// The game's dust's size (1 if not given).
16    pub scale: Option<f32>,
17}
18
19impl ParticleOptions {
20    /// Particle `id`, as it is.
21    pub fn plain(id: &str) -> Self {
22        ParticleOptions {
23            id: id.to_owned(),
24            color: None,
25            scale: None,
26        }
27    }
28
29    /// Particle `id` in `color` (`0xRRGGBB`).
30    pub fn colored(id: &str, color: u32) -> Self {
31        ParticleOptions {
32            color: Some(color),
33            ..Self::plain(id)
34        }
35    }
36}
37
38actions! {
39    /// Spawns `count` particles around `pos` (none: one, `spread` its motion).
40    SpawnParticles { dim: String, pos: Point, particle: ParticleOptions, count: i32, spread: Point, speed: f64 } -> bool = ids::service_particle::SPAWN, "YogParticleActions.spawnParticles";
41}