BaseInventory::canAddItem(): consider item max stack size (#3881)

this fixes addItem() failing when canAddItem() reported that an item can be added.
This commit is contained in:
Nick 2020-11-01 16:49:13 +03:00 committed by GitHub
parent c0dafe7872
commit deb0cee8a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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){