Skip to content

Commit

Permalink
Fix: Block still placed when empty slot
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Oct 31, 2024
1 parent 3fb191f commit acf2fab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 17 additions & 11 deletions pumpkin-inventory/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit acf2fab

Please sign in to comment.