Skip to main content

steel_registry/
frog_variant.rs

1use crate::shared_structs::{SpawnConditionEntry, insert_spawn_conditions};
2use rustc_hash::FxHashMap;
3use simdnbt::ToNbtTag;
4use simdnbt::owned::NbtTag;
5use steel_utils::Identifier;
6
7/// Represents a full frog variant definition from a data pack JSON file.
8#[derive(Debug)]
9pub struct FrogVariant {
10    pub key: Identifier,
11    pub asset_id: Identifier,
12    pub spawn_conditions: &'static [SpawnConditionEntry],
13}
14
15impl ToNbtTag for &FrogVariant {
16    fn to_nbt_tag(self) -> NbtTag {
17        use simdnbt::owned::NbtCompound;
18        let mut compound = NbtCompound::new();
19        let asset_id = self.asset_id.to_string();
20        compound.insert("asset_id", asset_id.as_str());
21        compound.insert("baby_asset_id", asset_id.as_str());
22        insert_spawn_conditions(&mut compound, self.spawn_conditions);
23        NbtTag::Compound(compound)
24    }
25}
26
27pub type FrogVariantRef = &'static FrogVariant;
28
29pub struct FrogVariantRegistry {
30    frog_variants_by_id: Vec<FrogVariantRef>,
31    frog_variants_by_key: FxHashMap<Identifier, usize>,
32    allows_registering: bool,
33}
34
35impl FrogVariantRegistry {
36    #[must_use]
37    pub fn new() -> Self {
38        Self {
39            frog_variants_by_id: Vec::new(),
40            frog_variants_by_key: FxHashMap::default(),
41            allows_registering: true,
42        }
43    }
44}
45
46crate::impl_standard_methods!(
47    FrogVariantRegistry,
48    FrogVariantRef,
49    frog_variants_by_id,
50    frog_variants_by_key,
51    allows_registering
52);
53
54crate::impl_registry!(
55    FrogVariantRegistry,
56    FrogVariant,
57    frog_variants_by_id,
58    frog_variants_by_key,
59    frog_variants
60);