From deb0cee8a0467434e21afea87a776b0d9caf38d5 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 1 Nov 2020 16:49:13 +0300 Subject: [PATCH] BaseInventory::canAddItem(): consider item max stack size (#3881) this fixes addItem() failing when canAddItem() reported that an item can be added. --- src/pocketmine/inventory/BaseInventory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index f1d8bb987..cde92cc4a 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -252,11 +252,11 @@ abstract class BaseInventory implements Inventory{ for($i = 0, $size = $this->getSize(); $i < $size; ++$i){ $slot = $this->getItem($i); if($item->equals($slot)){ - if(($diff = $slot->getMaxStackSize() - $slot->getCount()) > 0){ + if(($diff = min($slot->getMaxStackSize(), $item->getMaxStackSize()) - $slot->getCount()) > 0){ $count -= $diff; } }elseif($slot->isNull()){ - $count -= $this->getMaxStackSize(); + $count -= min($this->getMaxStackSize(), $item->getMaxStackSize()); } if($count <= 0){