minecraft_command_types/command/
random.rs

1use crate::command::enums::random_type::RandomType;
2use crate::range::IntegerRange;
3use crate::resource_location::ResourceLocation;
4use minecraft_command_types_derive::HasMacro;
5use std::fmt::{Display, Formatter};
6
7#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
8pub enum RandomResetType {
9    All,
10    Sequence(ResourceLocation),
11}
12
13impl Display for RandomResetType {
14    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
15        match self {
16            RandomResetType::All => f.write_str("*"),
17            RandomResetType::Sequence(sequence) => sequence.fmt(f),
18        }
19    }
20}
21
22#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
23pub enum RandomCommand {
24    ValueRoll(RandomType, IntegerRange, Option<ResourceLocation>),
25    Reset(RandomResetType, Option<i32>, Option<bool>, Option<bool>),
26}
27
28impl Display for RandomCommand {
29    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
30        match self {
31            RandomCommand::ValueRoll(random_type, range, sequence) => {
32                write!(f, "{} {}", random_type, range)?;
33
34                if let Some(sequence) = sequence {
35                    write!(f, " {}", sequence)?;
36                }
37
38                Ok(())
39            }
40            RandomCommand::Reset(reset_type, seed, include_world_seed, include_sequence_id) => {
41                write!(f, "reset {}", reset_type)?;
42
43                if let Some(seed) = seed {
44                    write!(f, " {}", seed)?;
45
46                    if let Some(include_world_seed) = include_world_seed {
47                        write!(f, " {}", include_world_seed)?;
48
49                        if let Some(include_sequence_id) = include_sequence_id {
50                            write!(f, " {}", include_sequence_id)?;
51                        }
52                    }
53                }
54
55                Ok(())
56            }
57        }
58    }
59}