Skip to main content

steel_registry/
world_clock.rs

1use rustc_hash::FxHashMap;
2use simdnbt::ToNbtTag;
3use simdnbt::owned::{NbtCompound, NbtTag};
4use steel_utils::Identifier;
5
6/// Represents a world_clock definition from a data pack JSON file.
7#[derive(Debug)]
8pub struct WorldClock {
9    pub key: Identifier,
10}
11
12impl ToNbtTag for &WorldClock {
13    fn to_nbt_tag(self) -> NbtTag {
14        NbtTag::Compound(NbtCompound::new())
15    }
16}
17
18pub type WorldClockRef = &'static WorldClock;
19
20pub struct WorldClockRegistry {
21    world_clocks_by_id: Vec<WorldClockRef>,
22    world_clocks_by_key: FxHashMap<Identifier, usize>,
23    tags: FxHashMap<Identifier, Vec<Identifier>>,
24    allows_registering: bool,
25}
26
27impl WorldClockRegistry {
28    #[must_use]
29    pub fn new() -> Self {
30        Self {
31            world_clocks_by_id: Vec::new(),
32            world_clocks_by_key: FxHashMap::default(),
33            tags: FxHashMap::default(),
34            allows_registering: true,
35        }
36    }
37}
38
39crate::impl_standard_methods!(
40    WorldClockRegistry,
41    WorldClockRef,
42    world_clocks_by_id,
43    world_clocks_by_key,
44    allows_registering
45);
46
47crate::impl_registry!(
48    WorldClockRegistry,
49    WorldClock,
50    world_clocks_by_id,
51    world_clocks_by_key,
52    world_clocks
53);
54
55crate::impl_tagged_registry!(WorldClockRegistry, world_clocks_by_key, "World Clock");