Fix: Block still placed when empty slot

This commit is contained in:
Snowiiii 2024-10-31 18:35:03 +01:00
parent 3fb191fa37
commit acf2fab100
2 changed files with 19 additions and 13 deletions

View File

@ -51,23 +51,29 @@ impl PlayerInventory {
/// Useful functionality for plugins in the future.
pub fn set_slot(
&mut self,
slot: usize,
slot: u16,
item: Option<ItemStack>,
item_allowed_override: bool,
) -> Result<(), InventoryError> {
if item_allowed_override {
if !(0..=45).contains(&slot) {
Err(InventoryError::InvalidSlot)?
return Err(InventoryError::InvalidSlot);
}
*self.all_slots()[slot] = item;
return Ok(());
match item_allowed_override {
true => {
*self.all_slots()[slot as usize] = item;
}
false => {
let slot = slot as usize;
let slot_condition = self.slot_condition(slot)?;
if let Some(item) = item {
if slot_condition(&item) {
*self.all_slots()[slot] = Some(item);
self.all_slots()[slot] = &mut Some(item);
}
}
}
}
Ok(())
}
#[allow(clippy::type_complexity)]

View File

@ -660,9 +660,9 @@ impl Player {
let valid_slot = packet.slot >= 1 && packet.slot <= 45;
if valid_slot {
self.inventory.lock().await.set_slot(
packet.slot as usize,
packet.slot as u16,
packet.clicked_item.to_item(),
false,
true,
)?;
};
// TODO: The Item was droped per drag and drop,