minecraft_command_types/command/
advancement.rs

1use crate::resource_location::ResourceLocation;
2use minecraft_command_types_derive::HasMacro;
3use std::fmt::{Display, Formatter};
4
5#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
6pub enum AdvancementCommand {
7    /// Adds or removes all loaded advancements.
8    Everything,
9    /// Adds or removes a single advancement or criterion.
10    Only(ResourceLocation, Option<String>),
11    /// Adds or removes an advancement and all its child advancements.
12    /// Think of specifying everything from that advancement to the end.
13    /// The exact order the operation is carried out in is `specified advancement > child > child's child > ...` When it operates on a child that branches, it iterates through all its children before continuing.
14    From(ResourceLocation),
15    /// Specifies an advancement, and adds or removes all its parent advancements, and all its child advancements.
16    /// Think of specifying everything through the specified advancement, going both backward and forward.
17    /// The exact order the operation is as if the command were executed with "until" specified, then with "from" specified: `parent > parent's parent > ... > root > specified advancement > child > child's child > ...`
18    Through(ResourceLocation),
19    /// Adds or removes an advancement and all its parent advancements until the root for addition/removal.
20    /// Think of specifying everything from the start until that advancement.
21    /// The exact order the operation is carried out in is: `parent > parent's parent > ... > root > specified advancement`.
22    Until(ResourceLocation),
23}
24
25impl Display for AdvancementCommand {
26    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27        match self {
28            AdvancementCommand::Everything => f.write_str("everything"),
29            AdvancementCommand::Only(advancement, criterion) => {
30                advancement.fmt(f)?;
31
32                if let Some(criterion) = criterion {
33                    write!(f, " {}", criterion)?;
34                }
35
36                Ok(())
37            }
38            AdvancementCommand::From(advancement) => advancement.fmt(f),
39            AdvancementCommand::Through(advancement) => advancement.fmt(f),
40            AdvancementCommand::Until(advancement) => advancement.fmt(f),
41        }
42    }
43}