BaseInventory: stop mutating item for no reason in canAddItem()

This commit is contained in:
Dylan K. Taylor 2020-02-25 20:30:37 +00:00
parent 04581e2700
commit 53067c26d7

View File

@ -246,18 +246,18 @@ abstract class BaseInventory implements Inventory{
}
public function canAddItem(Item $item) : bool{
$item = clone $item;
$count = $item->getCount();
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
$slot = $this->getItem($i);
if($item->equals($slot)){
if(($diff = $slot->getMaxStackSize() - $slot->getCount()) > 0){
$item->setCount($item->getCount() - $diff);
$count -= $diff;
}
}elseif($slot->isNull()){
$item->setCount($item->getCount() - $this->getMaxStackSize());
$count -= $this->getMaxStackSize();
}
if($item->getCount() <= 0){
if($count <= 0){
return true;
}
}