Skip to main content

steel_registry/
wolf_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 wolf variant from a data pack JSON file.
9#[derive(Debug)]
10pub struct WolfSoundVariant {
11    pub key: Identifier,
12    pub adult_sounds: WolfAge,
13    pub baby_sounds: WolfAge,
14}
15#[derive(Debug)]
16pub struct WolfAge {
17    pub ambient_sound: SoundEventRef,
18    pub death_sound: SoundEventRef,
19    pub growl_sound: SoundEventRef,
20    pub hurt_sound: SoundEventRef,
21    pub pant_sound: SoundEventRef,
22    pub step_sound: SoundEventRef,
23    pub whine_sound: SoundEventRef,
24}
25
26impl ToNbtTag for &WolfAge {
27    fn to_nbt_tag(self) -> NbtTag {
28        use simdnbt::owned::{NbtCompound, NbtTag};
29        let mut compound = NbtCompound::new();
30        let s = self.ambient_sound.key.to_string();
31        compound.insert("ambient_sound", s.as_str());
32        let s = self.death_sound.key.to_string();
33        compound.insert("death_sound", s.as_str());
34        let s = self.growl_sound.key.to_string();
35        compound.insert("growl_sound", s.as_str());
36        let s = self.hurt_sound.key.to_string();
37        compound.insert("hurt_sound", s.as_str());
38        let s = self.pant_sound.key.to_string();
39        compound.insert("pant_sound", s.as_str());
40        let s = self.step_sound.key.to_string();
41        compound.insert("step_sound", s.as_str());
42        let s = self.whine_sound.key.to_string();
43        compound.insert("whine_sound", s.as_str());
44        NbtTag::Compound(compound)
45    }
46}
47
48impl ToNbtTag for &WolfSoundVariant {
49    fn to_nbt_tag(self) -> NbtTag {
50        use simdnbt::owned::{NbtCompound, NbtTag};
51        let mut compound = NbtCompound::new();
52        compound.insert("adult_sounds", self.adult_sounds.to_nbt_tag());
53        compound.insert("baby_sounds", self.baby_sounds.to_nbt_tag());
54        NbtTag::Compound(compound)
55    }
56}
57
58pub type WolfSoundVariantRef = &'static WolfSoundVariant;
59
60pub struct WolfSoundVariantRegistry {
61    wolf_sound_variants_by_id: Vec<WolfSoundVariantRef>,
62    wolf_sound_variants_by_key: FxHashMap<Identifier, usize>,
63    allows_registering: bool,
64}
65
66impl WolfSoundVariantRegistry {
67    #[must_use]
68    pub fn new() -> Self {
69        Self {
70            wolf_sound_variants_by_id: Vec::new(),
71            wolf_sound_variants_by_key: FxHashMap::default(),
72            allows_registering: true,
73        }
74    }
75}
76
77crate::impl_standard_methods!(
78    WolfSoundVariantRegistry,
79    WolfSoundVariantRef,
80    wolf_sound_variants_by_id,
81    wolf_sound_variants_by_key,
82    allows_registering
83);
84
85crate::impl_registry!(
86    WolfSoundVariantRegistry,
87    WolfSoundVariant,
88    wolf_sound_variants_by_id,
89    wolf_sound_variants_by_key,
90    wolf_sound_variants
91);