Skip to main content

steel_registry/
menu_type.rs

1use rustc_hash::FxHashMap;
2use steel_utils::Identifier;
3
4/// Represents a menu type (container/GUI type) in Minecraft.
5/// Menu types define the different inventory interfaces available,
6/// such as chests, furnaces, anvils, etc.
7#[derive(Debug)]
8pub struct MenuType {
9    pub key: Identifier,
10    /// Total number of slots constructed by the client menu, including the
11    /// player's inventory slots when that menu displays them.
12    pub slot_count: usize,
13}
14
15pub type MenuTypeRef = &'static MenuType;
16
17pub struct MenuTypeRegistry {
18    menu_types_by_id: Vec<MenuTypeRef>,
19    menu_types_by_key: FxHashMap<Identifier, usize>,
20    allows_registering: bool,
21}
22
23impl MenuTypeRegistry {
24    #[must_use]
25    pub fn new() -> Self {
26        Self {
27            menu_types_by_id: Vec::new(),
28            menu_types_by_key: FxHashMap::default(),
29            allows_registering: true,
30        }
31    }
32}
33
34crate::impl_standard_methods!(
35    MenuTypeRegistry,
36    MenuTypeRef,
37    menu_types_by_id,
38    menu_types_by_key,
39    allows_registering
40);
41
42crate::impl_registry!(
43    MenuTypeRegistry,
44    MenuType,
45    menu_types_by_id,
46    menu_types_by_key,
47    menu_types
48);