steel_registry/
cow_sound_variant.rs1use rustc_hash::FxHashMap;
2use simdnbt::ToNbtTag;
3use simdnbt::owned::NbtTag;
4use steel_utils::Identifier;
5
6use crate::sound_event::SoundEventRef;
7
8#[derive(Debug)]
10pub struct CowSoundVariant {
11 pub key: Identifier,
12 pub ambient_sound: SoundEventRef,
13 pub death_sound: SoundEventRef,
14 pub hurt_sound: SoundEventRef,
15 pub step_sound: SoundEventRef,
16}
17
18impl ToNbtTag for &CowSoundVariant {
19 fn to_nbt_tag(self) -> NbtTag {
20 use simdnbt::owned::{NbtCompound, NbtTag};
21 let mut compound = NbtCompound::new();
22 let s = self.ambient_sound.key.to_string();
23 compound.insert("ambient_sound", s.as_str());
24 let s = self.death_sound.key.to_string();
25 compound.insert("death_sound", s.as_str());
26 let s = self.hurt_sound.key.to_string();
27 compound.insert("hurt_sound", s.as_str());
28 let s = self.step_sound.key.to_string();
29 compound.insert("step_sound", s.as_str());
30 NbtTag::Compound(compound)
31 }
32}
33
34pub type CowSoundVariantRef = &'static CowSoundVariant;
35
36pub struct CowSoundVariantRegistry {
37 cow_sound_variants_by_id: Vec<CowSoundVariantRef>,
38 cow_sound_variants_by_key: FxHashMap<Identifier, usize>,
39 allows_registering: bool,
40}
41
42impl CowSoundVariantRegistry {
43 #[must_use]
44 pub fn new() -> Self {
45 Self {
46 cow_sound_variants_by_id: Vec::new(),
47 cow_sound_variants_by_key: FxHashMap::default(),
48 allows_registering: true,
49 }
50 }
51}
52
53crate::impl_standard_methods!(
54 CowSoundVariantRegistry,
55 CowSoundVariantRef,
56 cow_sound_variants_by_id,
57 cow_sound_variants_by_key,
58 allows_registering
59);
60
61crate::impl_registry!(
62 CowSoundVariantRegistry,
63 CowSoundVariant,
64 cow_sound_variants_by_id,
65 cow_sound_variants_by_key,
66 cow_sound_variants
67);