Fix: Block still placed when empty slot
This commit is contained in:
parent
3fb191fa37
commit
acf2fab100
@ -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)?
|
||||
}
|
||||
*self.all_slots()[slot] = item;
|
||||
return Ok(());
|
||||
if !(0..=45).contains(&slot) {
|
||||
return Err(InventoryError::InvalidSlot);
|
||||
}
|
||||
let slot_condition = self.slot_condition(slot)?;
|
||||
if let Some(item) = item {
|
||||
if slot_condition(&item) {
|
||||
*self.all_slots()[slot] = Some(item);
|
||||
|
||||
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] = &mut Some(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
#[allow(clippy::type_complexity)]
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user