steel_core/inventory/container/
simple.rs1use steel_registry::item_stack::ItemStack;
2use steel_utils::{DowncastType, DowncastTypeKey};
3
4use crate::inventory::container::Container;
5
6pub struct SimpleContainer {
8 items: Vec<ItemStack>,
9 times_changed: u32,
10}
11
12unsafe impl DowncastType for SimpleContainer {
14 const TYPE_KEY: DowncastTypeKey = DowncastTypeKey::new("steel:container/simple");
15}
16
17impl SimpleContainer {
18 #[must_use]
20 pub fn new(size: usize) -> Self {
21 Self {
22 items: vec![ItemStack::empty(); size],
23 times_changed: 0,
24 }
25 }
26
27 #[must_use]
29 pub const fn from_items(items: Vec<ItemStack>) -> Self {
30 Self {
31 items,
32 times_changed: 0,
33 }
34 }
35
36 #[must_use]
38 pub const fn times_changed(&self) -> u32 {
39 self.times_changed
40 }
41}
42
43impl Container for SimpleContainer {
44 fn items(&self) -> &[ItemStack] {
45 &self.items
46 }
47
48 fn items_mut(&mut self) -> &mut [ItemStack] {
49 &mut self.items
50 }
51
52 fn set_changed(&mut self) {
53 self.times_changed = self.times_changed.wrapping_add(1);
54 }
55}