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.
|
/// Useful functionality for plugins in the future.
|
||||||
pub fn set_slot(
|
pub fn set_slot(
|
||||||
&mut self,
|
&mut self,
|
||||||
slot: usize,
|
slot: u16,
|
||||||
item: Option<ItemStack>,
|
item: Option<ItemStack>,
|
||||||
item_allowed_override: bool,
|
item_allowed_override: bool,
|
||||||
) -> Result<(), InventoryError> {
|
) -> Result<(), InventoryError> {
|
||||||
if item_allowed_override {
|
if !(0..=45).contains(&slot) {
|
||||||
if !(0..=45).contains(&slot) {
|
return Err(InventoryError::InvalidSlot);
|
||||||
Err(InventoryError::InvalidSlot)?
|
|
||||||
}
|
|
||||||
*self.all_slots()[slot] = item;
|
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
let slot_condition = self.slot_condition(slot)?;
|
|
||||||
if let Some(item) = item {
|
match item_allowed_override {
|
||||||
if slot_condition(&item) {
|
true => {
|
||||||
*self.all_slots()[slot] = Some(item);
|
*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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
|
|||||||
@ -660,9 +660,9 @@ impl Player {
|
|||||||
let valid_slot = packet.slot >= 1 && packet.slot <= 45;
|
let valid_slot = packet.slot >= 1 && packet.slot <= 45;
|
||||||
if valid_slot {
|
if valid_slot {
|
||||||
self.inventory.lock().await.set_slot(
|
self.inventory.lock().await.set_slot(
|
||||||
packet.slot as usize,
|
packet.slot as u16,
|
||||||
packet.clicked_item.to_item(),
|
packet.clicked_item.to_item(),
|
||||||
false,
|
true,
|
||||||
)?;
|
)?;
|
||||||
};
|
};
|
||||||
// TODO: The Item was droped per drag and drop,
|
// TODO: The Item was droped per drag and drop,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user