From 53067c26d78d629f9980ac3269edb72f7bc4878a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 25 Feb 2020 20:30:37 +0000 Subject: [PATCH] BaseInventory: stop mutating item for no reason in canAddItem() --- src/pocketmine/inventory/BaseInventory.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 71d6f258c..434495cfc 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -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; } }