Skip to main content

steel_core/inventory/container/
simple.rs

1use steel_registry::item_stack::ItemStack;
2use steel_utils::{DowncastType, DowncastTypeKey};
3
4use crate::inventory::container::Container;
5
6/// A Simple Container
7pub struct SimpleContainer {
8    items: Vec<ItemStack>,
9}
10
11// SAFETY: This key is owned by Steel and uniquely identifies `SimpleContainer`.
12unsafe impl DowncastType for SimpleContainer {
13    const TYPE_KEY: DowncastTypeKey = DowncastTypeKey::new("steel:container/simple");
14}
15
16impl SimpleContainer {
17    /// Creates a new Simple Container
18    #[must_use]
19    pub fn new(size: usize) -> Self {
20        Self {
21            items: vec![ItemStack::empty(); size],
22        }
23    }
24
25    /// Creates a Simple Container with already initialized items
26    #[must_use]
27    pub const fn from_items(items: Vec<ItemStack>) -> Self {
28        Self { items }
29    }
30}
31
32impl Container for SimpleContainer {
33    fn items(&self) -> &[ItemStack] {
34        &self.items
35    }
36
37    fn items_mut(&mut self) -> &mut [ItemStack] {
38        &mut self.items
39    }
40
41    fn set_changed(&mut self) {}
42}