steel_core/inventory/container/
crafting.rs1use steel_registry::{
4 item_stack::ItemStack,
5 recipe::{CraftingInput, PositionedCraftingInput},
6};
7use steel_utils::{DowncastType, DowncastTypeKey};
8
9use crate::inventory::container::Container;
10
11pub struct CraftingContainer {
16 width: usize,
17 height: usize,
18 items: Vec<ItemStack>,
19}
20
21unsafe impl DowncastType for CraftingContainer {
23 const TYPE_KEY: DowncastTypeKey = DowncastTypeKey::new("steel:container/crafting");
24}
25
26impl CraftingContainer {
27 #[must_use]
29 pub fn new(width: usize, height: usize) -> Self {
30 let size = width * height;
31 Self {
32 width,
33 height,
34 items: vec![ItemStack::empty(); size],
35 }
36 }
37
38 #[must_use]
40 pub const fn width(&self) -> usize {
41 self.width
42 }
43
44 #[must_use]
46 pub const fn height(&self) -> usize {
47 self.height
48 }
49
50 #[must_use]
58 pub fn as_positioned_input(&self) -> PositionedCraftingInput {
59 CraftingInput::positioned(self.width, self.height, self.items.clone())
60 }
61
62 #[must_use]
64 pub fn items(&self) -> &[ItemStack] {
65 &self.items
66 }
67}
68
69impl Container for CraftingContainer {
70 fn items(&self) -> &[ItemStack] {
71 &self.items
72 }
73
74 fn items_mut(&mut self) -> &mut [ItemStack] {
75 &mut self.items
76 }
77
78 fn set_changed(&mut self) {
79 }
82}