diff --git a/pumpkin-inventory/src/player.rs b/pumpkin-inventory/src/player.rs index ed8a16bfd..dd868249a 100644 --- a/pumpkin-inventory/src/player.rs +++ b/pumpkin-inventory/src/player.rs @@ -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, 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)] diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 35e4d0719..a1de0e10b 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -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,