diff --git a/src/pocketmine/inventory/AnvilInventory.php b/src/pocketmine/inventory/AnvilInventory.php index 37490a105..f22b56674 100644 --- a/src/pocketmine/inventory/AnvilInventory.php +++ b/src/pocketmine/inventory/AnvilInventory.php @@ -33,17 +33,13 @@ class AnvilInventory extends ContainerInventory{ protected $holder; public function __construct(Position $pos){ - parent::__construct($pos->asPosition()); + parent::__construct($pos->asPosition(), 2); } public function getNetworkType() : int{ return WindowTypes::ANVIL; } - public function getDefaultSize() : int{ - return 2; //1 input, 1 material - } - /** * This override is here for documentation and code completion purposes only. * @return Position diff --git a/src/pocketmine/inventory/ArmorInventory.php b/src/pocketmine/inventory/ArmorInventory.php index ac5154129..39700c51d 100644 --- a/src/pocketmine/inventory/ArmorInventory.php +++ b/src/pocketmine/inventory/ArmorInventory.php @@ -43,17 +43,13 @@ class ArmorInventory extends BaseInventory{ public function __construct(Living $holder){ $this->holder = $holder; - parent::__construct(); + parent::__construct(4); } public function getHolder() : Living{ return $this->holder; } - public function getDefaultSize() : int{ - return 4; - } - public function getHelmet() : Item{ return $this->getItem(self::SLOT_HEAD); } diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 5a96002da..73e079875 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -49,11 +49,11 @@ abstract class BaseInventory implements Inventory{ protected $slotChangeListener; /** - * @param Item[] $items * @param int $size + * @param Item[] $items */ - public function __construct(array $items = [], ?int $size = null){ - $this->slots = new \SplFixedArray($size ?? $this->getDefaultSize()); + public function __construct(int $size, array $items = []){ + $this->slots = new \SplFixedArray($size); $this->setContents($items, false); } @@ -76,8 +76,6 @@ abstract class BaseInventory implements Inventory{ $this->slots->setSize($size); } - abstract public function getDefaultSize() : int; - public function getMaxStackSize() : int{ return $this->maxStackSize; } diff --git a/src/pocketmine/inventory/ChestInventory.php b/src/pocketmine/inventory/ChestInventory.php index cbf63df12..dc4fa69f4 100644 --- a/src/pocketmine/inventory/ChestInventory.php +++ b/src/pocketmine/inventory/ChestInventory.php @@ -39,17 +39,13 @@ class ChestInventory extends ContainerInventory{ * @param Chest $tile */ public function __construct(Chest $tile){ - parent::__construct($tile); + parent::__construct($tile, 27); } public function getNetworkType() : int{ return WindowTypes::CONTAINER; } - public function getDefaultSize() : int{ - return 27; - } - /** * This override is here for documentation and code completion purposes only. * @return Chest diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index 4a808ca57..8a41a73a4 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -33,9 +33,9 @@ abstract class ContainerInventory extends BaseInventory{ /** @var Vector3 */ protected $holder; - public function __construct(Vector3 $holder, array $items = [], ?int $size = null){ + public function __construct(Vector3 $holder, int $size, array $items = []){ $this->holder = $holder; - parent::__construct($items, $size); + parent::__construct($size, $items); } protected function onOpen(Player $who) : void{ diff --git a/src/pocketmine/inventory/CraftingGrid.php b/src/pocketmine/inventory/CraftingGrid.php index 3da867cd5..b15ac65b0 100644 --- a/src/pocketmine/inventory/CraftingGrid.php +++ b/src/pocketmine/inventory/CraftingGrid.php @@ -50,17 +50,13 @@ class CraftingGrid extends BaseInventory{ public function __construct(Player $holder, int $gridWidth){ $this->holder = $holder; $this->gridWidth = $gridWidth; - parent::__construct(); + parent::__construct($this->getGridWidth() ** 2); } public function getGridWidth() : int{ return $this->gridWidth; } - public function getDefaultSize() : int{ - return $this->getGridWidth() ** 2; - } - public function setSize(int $size) : void{ throw new \BadMethodCallException("Cannot change the size of a crafting grid"); } diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index 06b439551..51a46e8c4 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -40,11 +40,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ $this->left = $left->getRealInventory(); $this->right = $right->getRealInventory(); $items = array_merge($this->left->getContents(true), $this->right->getContents(true)); - BaseInventory::__construct($items); - } - - public function getDefaultSize() : int{ - return $this->left->getDefaultSize() + $this->right->getDefaultSize(); + BaseInventory::__construct($this->left->getSize() + $this->right->getSize(), $items); } public function getInventory(){ diff --git a/src/pocketmine/inventory/EnchantInventory.php b/src/pocketmine/inventory/EnchantInventory.php index 80709f5c9..4d3a6b97f 100644 --- a/src/pocketmine/inventory/EnchantInventory.php +++ b/src/pocketmine/inventory/EnchantInventory.php @@ -33,17 +33,13 @@ class EnchantInventory extends ContainerInventory{ protected $holder; public function __construct(Position $pos){ - parent::__construct($pos->asPosition()); + parent::__construct($pos->asPosition(), 2); } public function getNetworkType() : int{ return WindowTypes::ENCHANTMENT; } - public function getDefaultSize() : int{ - return 2; //1 input, 1 lapis - } - /** * This override is here for documentation and code completion purposes only. * @return Position diff --git a/src/pocketmine/inventory/EnderChestInventory.php b/src/pocketmine/inventory/EnderChestInventory.php index d7605d837..a0fdfe24c 100644 --- a/src/pocketmine/inventory/EnderChestInventory.php +++ b/src/pocketmine/inventory/EnderChestInventory.php @@ -34,17 +34,13 @@ class EnderChestInventory extends ChestInventory{ protected $holder; public function __construct(){ - ContainerInventory::__construct(new Position()); + ContainerInventory::__construct(new Position(), 27); } public function getNetworkType() : int{ return WindowTypes::CONTAINER; } - public function getDefaultSize() : int{ - return 27; - } - /** * Set the holder's position to that of a tile * diff --git a/src/pocketmine/inventory/FurnaceInventory.php b/src/pocketmine/inventory/FurnaceInventory.php index 1418adb47..79a400c06 100644 --- a/src/pocketmine/inventory/FurnaceInventory.php +++ b/src/pocketmine/inventory/FurnaceInventory.php @@ -32,17 +32,13 @@ class FurnaceInventory extends ContainerInventory{ protected $holder; public function __construct(Furnace $tile){ - parent::__construct($tile); + parent::__construct($tile, 3); } public function getNetworkType() : int{ return WindowTypes::FURNACE; } - public function getDefaultSize() : int{ - return 3; //1 input, 1 fuel, 1 output - } - /** * This override is here for documentation and code completion purposes only. * @return Furnace diff --git a/src/pocketmine/inventory/PlayerCursorInventory.php b/src/pocketmine/inventory/PlayerCursorInventory.php index 4ad1a4050..e760493f2 100644 --- a/src/pocketmine/inventory/PlayerCursorInventory.php +++ b/src/pocketmine/inventory/PlayerCursorInventory.php @@ -31,11 +31,7 @@ class PlayerCursorInventory extends BaseInventory{ public function __construct(Player $holder){ $this->holder = $holder; - parent::__construct(); - } - - public function getDefaultSize() : int{ - return 1; + parent::__construct(1); } public function setSize(int $size) : void{ diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index ff355fad3..df0fedcc2 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -45,11 +45,7 @@ class PlayerInventory extends BaseInventory{ */ public function __construct(Human $player){ $this->holder = $player; - parent::__construct(); - } - - public function getDefaultSize() : int{ - return 36; + parent::__construct(36); } public function isHotbarSlot(int $slot) : bool{ diff --git a/tests/phpunit/inventory/BaseInventoryTest.php b/tests/phpunit/inventory/BaseInventoryTest.php index ade55f317..a00bbc1b1 100644 --- a/tests/phpunit/inventory/BaseInventoryTest.php +++ b/tests/phpunit/inventory/BaseInventoryTest.php @@ -34,13 +34,8 @@ class BaseInventoryTest extends TestCase{ } public function testAddItemDifferentUserData() : void{ - $inv = new class extends BaseInventory{ - public function getDefaultSize() : int{ - return 1; - } - public function getName() : string{ - return ""; - } + $inv = new class(1) extends BaseInventory{ + }; $item1 = ItemFactory::get(Item::ARROW, 0, 1); $item2 = ItemFactory::get(Item::ARROW, 0, 1)->setCustomName("TEST");