add creative pick item to packet SClickContainer

This commit is contained in:
Edvin Bryntesson 2024-08-27 10:30:33 +02:00
parent e0157663ed
commit 0f9ac2259c
No known key found for this signature in database
3 changed files with 38 additions and 2 deletions

View File

@ -65,6 +65,8 @@ pub trait Container {
slot: usize,
mouse_click: MouseClick,
);
fn all_slots(&mut self) -> Vec<&mut Option<ItemStack>>;
}
pub fn handle_item_take(
@ -173,4 +175,8 @@ impl<const T: usize> Container for ContainerStruct<T> {
let current_slot = &mut self.slots[slot];
handle_item_change(carried_slot, current_slot, mouse_click)
}
fn all_slots(&mut self) -> Vec<&mut Option<ItemStack>> {
self.slots.iter_mut().collect()
}
}

View File

@ -144,4 +144,8 @@ impl Container for PlayerInventory {
let item_slot = self.get_slot(slot);
handle_item_change(carried_slot, item_slot, mouse_click)
}
fn all_slots(&mut self) -> Vec<&mut Option<ItemStack>> {
self.slots_mut()
}
}

View File

@ -148,7 +148,18 @@ impl Player {
unimplemented!("This is not a valid state")
}
},
_ => todo!(),
ClickType::CreativePickItem => {
if let container_click::Slot::Normal(slot) = click.mode.slot {
self.creative_pick_item(slot)
}
}
ClickType::DoubleClick => {}
ClickType::MouseDrag {
drag_state,
drag_type,
} => {
todo!()
}
}
dbg!(&self.carried_item);
let filled_inventory_slots = self
@ -225,7 +236,6 @@ impl Player {
}
container_click::Slot::OutsideInventory => (),
};
return;
} else {
return;
@ -252,6 +262,22 @@ impl Player {
}
}
}
pub fn creative_pick_item(&mut self, slot: usize) {
let mut container = {
match &mut self.open_container {
Some(container) => {
let mut out = container.all_slots();
out.extend(self.inventory.slots_mut());
out
}
None => self.inventory.slots_mut(),
}
};
if let Some(Some(item)) = container.get_mut(slot) {
self.carried_item = Some(item.to_owned())
}
}
}
/*impl<const SLOTS: usize> ContainerStruct<SLOTS> {