mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-07 10:31:51 +00:00
BaseInventory: stop mutating item for no reason in canAddItem()
This commit is contained in:
parent
04581e2700
commit
53067c26d7
@ -246,18 +246,18 @@ abstract class BaseInventory implements Inventory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function canAddItem(Item $item) : bool{
|
public function canAddItem(Item $item) : bool{
|
||||||
$item = clone $item;
|
$count = $item->getCount();
|
||||||
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
||||||
$slot = $this->getItem($i);
|
$slot = $this->getItem($i);
|
||||||
if($item->equals($slot)){
|
if($item->equals($slot)){
|
||||||
if(($diff = $slot->getMaxStackSize() - $slot->getCount()) > 0){
|
if(($diff = $slot->getMaxStackSize() - $slot->getCount()) > 0){
|
||||||
$item->setCount($item->getCount() - $diff);
|
$count -= $diff;
|
||||||
}
|
}
|
||||||
}elseif($slot->isNull()){
|
}elseif($slot->isNull()){
|
||||||
$item->setCount($item->getCount() - $this->getMaxStackSize());
|
$count -= $this->getMaxStackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($item->getCount() <= 0){
|
if($count <= 0){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user