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;
}