steel_registry/
chicken_variant.rs1use crate::shared_structs::{SpawnConditionEntry, insert_spawn_conditions};
2use rustc_hash::FxHashMap;
3use simdnbt::ToNbtTag;
4use simdnbt::owned::NbtTag;
5use steel_utils::Identifier;
6
7#[derive(Debug)]
9pub struct ChickenVariant {
10 pub key: Identifier,
11 pub asset_id: Identifier,
12 pub baby_asset_id: Identifier,
13 pub model: ChickenModelType,
14 pub spawn_conditions: &'static [SpawnConditionEntry],
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
19pub enum ChickenModelType {
20 #[default]
21 Normal,
22 Cold,
23}
24
25impl ToNbtTag for &ChickenVariant {
26 fn to_nbt_tag(self) -> NbtTag {
27 use simdnbt::owned::{NbtCompound, NbtTag};
28 let mut compound = NbtCompound::new();
29 compound.insert("asset_id", self.asset_id.clone());
30 compound.insert("baby_asset_id", self.baby_asset_id.clone());
31 compound.insert(
32 "model",
33 match self.model {
34 ChickenModelType::Normal => "normal",
35 ChickenModelType::Cold => "cold",
36 },
37 );
38 insert_spawn_conditions(&mut compound, self.spawn_conditions);
39 NbtTag::Compound(compound)
40 }
41}
42
43pub type ChickenVariantRef = &'static ChickenVariant;
44
45pub struct ChickenVariantRegistry {
46 chicken_variants_by_id: Vec<ChickenVariantRef>,
47 chicken_variants_by_key: FxHashMap<Identifier, usize>,
48 allows_registering: bool,
49}
50
51impl ChickenVariantRegistry {
52 #[must_use]
53 pub fn new() -> Self {
54 Self {
55 chicken_variants_by_id: Vec::new(),
56 chicken_variants_by_key: FxHashMap::default(),
57 allows_registering: true,
58 }
59 }
60}
61
62crate::impl_standard_methods!(
63 ChickenVariantRegistry,
64 ChickenVariantRef,
65 chicken_variants_by_id,
66 chicken_variants_by_key,
67 allows_registering
68);
69
70crate::impl_registry!(
71 ChickenVariantRegistry,
72 ChickenVariant,
73 chicken_variants_by_id,
74 chicken_variants_by_key,
75 chicken_variants
76);