minecraft_command_types/command/
attribute.rs1use crate::command::enums::attribute::AttributeAddModifier;
2use crate::resource_location::ResourceLocation;
3use minecraft_command_types_derive::HasMacro;
4use ordered_float::NotNan;
5use std::fmt::{Display, Formatter};
6
7type F32 = NotNan<f32>;
8
9#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
10pub enum BaseAttributeCommand {
11 Get(Option<F32>),
13 Set(F32),
15 Reset,
17}
18
19impl Display for BaseAttributeCommand {
20 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21 match self {
22 BaseAttributeCommand::Get(scale) => {
23 f.write_str("get")?;
24
25 if let Some(scale) = scale {
26 write!(f, " {}", scale)?;
27 }
28
29 Ok(())
30 }
31 BaseAttributeCommand::Set(value) => write!(f, "set {}", value),
32 BaseAttributeCommand::Reset => f.write_str("reset"),
33 }
34 }
35}
36
37#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
38pub enum ModifierAttributeCommand {
39 Add(ResourceLocation, F32, AttributeAddModifier),
41 Remove(ResourceLocation),
43 Get(ResourceLocation, Option<F32>),
45}
46
47impl Display for ModifierAttributeCommand {
48 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49 match self {
50 ModifierAttributeCommand::Add(id, value, add_modifier) => {
51 write!(f, "add {} {} {}", id, value, add_modifier)
52 }
53 ModifierAttributeCommand::Remove(id) => {
54 write!(f, "remove {}", id)
55 }
56 ModifierAttributeCommand::Get(id, scale) => {
57 write!(f, "value get {}", id)?;
58
59 if let Some(scale) = scale {
60 write!(f, " {}", scale)?;
61 }
62
63 Ok(())
64 }
65 }
66 }
67}
68
69#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
70pub enum AttributeCommand {
71 Get(Option<F32>),
73 Base(BaseAttributeCommand),
74 Modifier(ModifierAttributeCommand),
75}
76
77impl Display for AttributeCommand {
78 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
79 match self {
80 AttributeCommand::Get(scale) => {
81 f.write_str("get")?;
82
83 if let Some(scale) = scale {
84 write!(f, " {}", scale)?;
85 }
86
87 Ok(())
88 }
89 AttributeCommand::Base(base_command) => {
90 write!(f, "base {}", base_command)
91 }
92 AttributeCommand::Modifier(modifier_command) => {
93 write!(f, "modifier {}", modifier_command)
94 }
95 }
96 }
97}