Merge branch 'stable'

This commit is contained in:
Dylan K. Taylor 2020-02-25 20:45:39 +00:00
commit 78394a336c
3 changed files with 4 additions and 22 deletions

View File

@ -199,18 +199,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;
}
}

View File

@ -385,10 +385,6 @@ class Item implements \JsonSerializable{
* @return $this
*/
public function setCount(int $count) : Item{
if($count < 0 or $count > 255){
throw new \InvalidArgumentException("Count must be in the range 0-255");
}
$this->count = $count;
return $this;

View File

@ -143,18 +143,4 @@ class ItemTest extends TestCase{
$this->item->removeEnchantment(Enchantment::FIRE_ASPECT(), 2);
self::assertFalse($this->item->hasEnchantment(Enchantment::FIRE_ASPECT()));
}
public function testSetCountTooBig() : void{
$this->expectException(\InvalidArgumentException::class);
$item = ItemFactory::get(ItemIds::STONE);
$item->setCount(256);
}
public function testSetCountTooSmall() : void{
$this->expectException(\InvalidArgumentException::class);
$item = ItemFactory::get(ItemIds::STONE);
$item->setCount(-1);
}
}