Skip to main content

steel_registry/
trim_pattern.rs

1use rustc_hash::FxHashMap;
2use simdnbt::ToNbtTag;
3use simdnbt::owned::NbtTag;
4use steel_utils::Identifier;
5use text_components::TextComponent;
6
7/// Represents an armor trim pattern definition from the data packs.
8#[derive(Debug)]
9pub struct TrimPattern {
10    pub key: Identifier,
11    pub asset_id: Identifier,
12    pub description: TextComponent,
13    pub decal: bool,
14}
15
16impl ToNbtTag for &TrimPattern {
17    fn to_nbt_tag(self) -> NbtTag {
18        use simdnbt::owned::NbtCompound;
19        let mut compound = NbtCompound::new();
20        let asset_id = self.asset_id.to_string();
21        compound.insert("asset_id", asset_id.as_str());
22        compound.insert("description", (&self.description).to_nbt_tag());
23        compound.insert("decal", self.decal);
24        NbtTag::Compound(compound)
25    }
26}
27
28pub type TrimPatternRef = &'static TrimPattern;
29
30pub struct TrimPatternRegistry {
31    trim_patterns_by_id: Vec<TrimPatternRef>,
32    trim_patterns_by_key: FxHashMap<Identifier, usize>,
33    allows_registering: bool,
34}
35
36impl TrimPatternRegistry {
37    #[must_use]
38    pub fn new() -> Self {
39        Self {
40            trim_patterns_by_id: Vec::new(),
41            trim_patterns_by_key: FxHashMap::default(),
42            allows_registering: true,
43        }
44    }
45}
46
47crate::impl_standard_methods!(
48    TrimPatternRegistry,
49    TrimPatternRef,
50    trim_patterns_by_id,
51    trim_patterns_by_key,
52    allows_registering
53);
54
55crate::impl_registry!(
56    TrimPatternRegistry,
57    TrimPattern,
58    trim_patterns_by_id,
59    trim_patterns_by_key,
60    trim_patterns
61);