mirror of
https://github.com/Pumpkin-MC/Pumpkin
synced 2025-04-13 12:03:52 +00:00
add basic entity NBT storage
This commit is contained in:
assets
pumpkin-data/build
pumpkin-inventory/src
pumpkin-nbt/src
pumpkin-protocol
pumpkin-util
pumpkin
@ -70,7 +70,7 @@ impl OpenContainer {
|
||||
}
|
||||
|
||||
pub fn clear_all_players(&mut self) {
|
||||
self.players = vec![];
|
||||
self.players.clear();
|
||||
}
|
||||
|
||||
pub fn all_player_ids(&self) -> Vec<i32> {
|
||||
|
@ -13,7 +13,7 @@ pub struct PlayerInventory {
|
||||
armor: [Option<ItemStack>; 4],
|
||||
offhand: Option<ItemStack>,
|
||||
// current selected slot in hotbar
|
||||
selected: usize,
|
||||
pub selected: u32,
|
||||
pub state_id: u32,
|
||||
// Notchian server wraps this value at 100, we can just keep it as a u8 that automatically wraps
|
||||
pub total_opened_containers: i32,
|
||||
@ -101,23 +101,23 @@ impl PlayerInventory {
|
||||
_ => Err(InventoryError::InvalidSlot),
|
||||
}
|
||||
}
|
||||
pub fn set_selected(&mut self, slot: usize) {
|
||||
pub fn set_selected(&mut self, slot: u32) {
|
||||
assert!((0..9).contains(&slot));
|
||||
self.selected = slot;
|
||||
}
|
||||
|
||||
pub fn get_selected(&self) -> usize {
|
||||
pub fn get_selected(&self) -> u32 {
|
||||
self.selected + 36
|
||||
}
|
||||
|
||||
pub fn held_item(&self) -> Option<&ItemStack> {
|
||||
debug_assert!((0..9).contains(&self.selected));
|
||||
self.items[self.selected + 36 - 9].as_ref()
|
||||
self.items[self.selected as usize + 36 - 9].as_ref()
|
||||
}
|
||||
|
||||
pub fn held_item_mut(&mut self) -> &mut Option<ItemStack> {
|
||||
debug_assert!((0..9).contains(&self.selected));
|
||||
&mut self.items[self.selected + 36 - 9]
|
||||
&mut self.items[self.selected as usize + 36 - 9]
|
||||
}
|
||||
|
||||
pub fn get_slot_with_item(&self, item_id: u16) -> Option<usize> {
|
||||
@ -131,14 +131,14 @@ impl PlayerInventory {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_pick_item_hotbar_slot(&self) -> usize {
|
||||
if self.items[self.selected + 36 - 9].is_none() {
|
||||
pub fn get_pick_item_hotbar_slot(&self) -> u32 {
|
||||
if self.items[self.selected as usize + 36 - 9].is_none() {
|
||||
return self.selected;
|
||||
}
|
||||
|
||||
for slot in 0..9 {
|
||||
if self.items[slot + 36 - 9].is_none() {
|
||||
return slot;
|
||||
return slot as u32;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user