pocketmine\inventory\BaseInventory::canAddItem PHP Method

canAddItem() public method

public canAddItem ( Item $item )
$item pocketmine\item\Item
    public function canAddItem(Item $item)
    {
        $item = clone $item;
        $checkDamage = $item->getDamage() === null ? false : true;
        $checkTags = $item->getCompoundTag() === null ? false : true;
        for ($i = 0; $i < $this->getSize(); ++$i) {
            $slot = $this->getItem($i);
            if ($item->equals($slot, $checkDamage, $checkTags)) {
                if (($diff = $slot->getMaxStackSize() - $slot->getCount()) > 0) {
                    $item->setCount($item->getCount() - $diff);
                }
            } elseif ($slot->getId() === Item::AIR) {
                $item->setCount($item->getCount() - $this->getMaxStackSize());
            }
            if ($item->getCount() <= 0) {
                return true;
            }
        }
        return false;
    }