minecraft_command_types/command/
damage.rs

1use crate::coordinate::Coordinates;
2use crate::entity_selector::EntitySelector;
3use minecraft_command_types_derive::HasMacro;
4use std::fmt::{Display, Formatter};
5
6#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
7pub enum DamageType {
8    At(Coordinates),
9    By(EntitySelector, Option<EntitySelector>),
10}
11
12impl Display for DamageType {
13    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
14        match self {
15            DamageType::At(coordinates) => write!(f, "at {}", coordinates),
16            DamageType::By(by, from) => {
17                write!(f, "by {}", by)?;
18
19                if let Some(from) = from {
20                    write!(f, " from {}", from)?;
21                }
22
23                Ok(())
24            }
25        }
26    }
27}