mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Merge branch 'stable'
This commit is contained in:
commit
78394a336c
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user