Skip to main content

steel_registry/
cat_sound_variant.rs

1use rustc_hash::FxHashMap;
2use simdnbt::ToNbtTag;
3use simdnbt::owned::NbtTag;
4use steel_utils::Identifier;
5
6use crate::sound_event::SoundEventRef;
7
8/// Represents a set of sounds for a cat variant from a data pack JSON file.
9#[derive(Debug)]
10pub struct CatSoundVariant {
11    pub key: Identifier,
12    pub adult_sounds: CatAge,
13    pub baby_sounds: CatAge,
14}
15#[derive(Debug)]
16pub struct CatAge {
17    pub ambient_sound: SoundEventRef,
18    pub beg_for_food_sound: SoundEventRef,
19    pub death_sound: SoundEventRef,
20    pub eat_sound: SoundEventRef,
21    pub hiss_sound: SoundEventRef,
22    pub hurt_sound: SoundEventRef,
23    pub purr_sound: SoundEventRef,
24    pub purreow_sound: SoundEventRef,
25    pub stray_ambient_sound: SoundEventRef,
26}
27
28impl ToNbtTag for &CatAge {
29    fn to_nbt_tag(self) -> NbtTag {
30        use simdnbt::owned::{NbtCompound, NbtTag};
31        let mut component = NbtCompound::new();
32        let s = self.ambient_sound.key.to_string();
33        component.insert("ambient_sound", s.as_str());
34        let s = self.beg_for_food_sound.key.to_string();
35        component.insert("beg_for_food_sound", s.as_str());
36        let s = self.death_sound.key.to_string();
37        component.insert("death_sound", s.as_str());
38        let s = self.eat_sound.key.to_string();
39        component.insert("eat_sound", s.as_str());
40        let s = self.hiss_sound.key.to_string();
41        component.insert("hiss_sound", s.as_str());
42        let s = self.hurt_sound.key.to_string();
43        component.insert("hurt_sound", s.as_str());
44        let s = self.purr_sound.key.to_string();
45        component.insert("purr_sound", s.as_str());
46        let s = self.purreow_sound.key.to_string();
47        component.insert("purreow_sound", s.as_str());
48        let s = self.stray_ambient_sound.key.to_string();
49        component.insert("stray_ambient_sound", s.as_str());
50        NbtTag::Compound(component)
51    }
52}
53
54impl ToNbtTag for &CatSoundVariant {
55    fn to_nbt_tag(self) -> NbtTag {
56        use simdnbt::owned::{NbtCompound, NbtTag};
57        let mut compound = NbtCompound::new();
58        compound.insert("adult_sounds", self.adult_sounds.to_nbt_tag());
59        compound.insert("baby_sounds", self.baby_sounds.to_nbt_tag());
60        NbtTag::Compound(compound)
61    }
62}
63
64pub type CatSoundVariantRef = &'static CatSoundVariant;
65
66pub struct CatSoundVariantRegistry {
67    cat_sound_variants_by_id: Vec<CatSoundVariantRef>,
68    cat_sound_variants_by_key: FxHashMap<Identifier, usize>,
69    allows_registering: bool,
70}
71
72impl CatSoundVariantRegistry {
73    #[must_use]
74    pub fn new() -> Self {
75        Self {
76            cat_sound_variants_by_id: Vec::new(),
77            cat_sound_variants_by_key: FxHashMap::default(),
78            allows_registering: true,
79        }
80    }
81}
82
83crate::impl_standard_methods!(
84    CatSoundVariantRegistry,
85    CatSoundVariantRef,
86    cat_sound_variants_by_id,
87    cat_sound_variants_by_key,
88    allows_registering
89);
90
91crate::impl_registry!(
92    CatSoundVariantRegistry,
93    CatSoundVariant,
94    cat_sound_variants_by_id,
95    cat_sound_variants_by_key,
96    cat_sound_variants
97);