Added Player inventory (WIP)

This commit is contained in:
Snowiiii committed 2024-08-17 18:52:13 +02:00
1 parent d6fb4ed121
commit 391d5cbcfc
13 files changed
+79 -10

No files matched your search

+4 -1
View File
@@ -5,4 +5,7 @@ edition.workspace = true
[dependencies]
num-traits = "0.2"
num-derive = "0.4"
num-derive = "0.4"
# For items
pumpkin-world = { path = "../pumpkin-world"}
+2
View File
@@ -1,5 +1,7 @@
use num_derive::ToPrimitive;
pub mod player;
/// https://wiki.vg/Inventory
#[derive(Debug, ToPrimitive)]
pub enum WindowType {
+35
View File
@@ -0,0 +1,35 @@
use pumpkin_world::item::Item;
pub struct PlayerInventory {
// Main Inventory + Hotbar
items: [Option<Item>; 36],
armor: [Option<Item>; 4],
offhand: Option<Item>,
// current selected slot in hortbar
selected: i16,
}
impl Default for PlayerInventory {
fn default() -> Self {
Self::new()
}
}
impl PlayerInventory {
pub fn new() -> Self {
Self {
items: [None; 36],
armor: [None; 4],
offhand: None,
// TODO: What when player spawns in with an diffrent index ?
selected: 0,
}
}
pub fn set_slot(slot: u32, item: Item) {}
pub fn set_selected(&mut self, slot: i16) {
assert!((0..9).contains(&slot));
self.selected = slot;
}
}