minecraft_command_types/command/
particle.rs

1use crate::command::enums::particle_display_type::ParticleDisplayType;
2use crate::coordinate::Coordinates;
3use crate::entity_selector::EntitySelector;
4use minecraft_command_types_derive::HasMacro;
5use ordered_float::NotNan;
6use std::fmt::{Display, Formatter};
7
8#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
9pub enum ParticleCommand {
10    Regular(String, Option<Coordinates>),
11    Extra(
12        String,
13        Coordinates,
14        Coordinates,
15        NotNan<f32>,
16        i32,
17        Option<ParticleDisplayType>,
18        Option<EntitySelector>,
19    ),
20}
21
22impl Display for ParticleCommand {
23    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
24        match self {
25            ParticleCommand::Regular(name, pos) => {
26                name.fmt(f)?;
27
28                if let Some(pos) = pos {
29                    write!(f, " {}", pos)?;
30                }
31
32                Ok(())
33            }
34            ParticleCommand::Extra(name, pos, delta, speed, count, display_type, viewers) => {
35                write!(f, "{} {} {} {} {}", name, pos, delta, speed, count)?;
36
37                if let Some(display_type) = display_type {
38                    write!(f, " {}", display_type)?;
39
40                    if let Some(viewers) = viewers {
41                        write!(f, " {}", viewers)?;
42                    }
43                }
44
45                Ok(())
46            }
47        }
48    }
49}