diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index c95190130..0ae14b5e2 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -47,7 +47,6 @@ use pocketmine\event\Timings; use pocketmine\event\TimingsHandler; use pocketmine\event\TranslationContainer; use pocketmine\inventory\CraftingManager; -use pocketmine\inventory\InventoryType; use pocketmine\inventory\Recipe; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; @@ -1582,7 +1581,6 @@ class Server{ Entity::init(); Tile::init(); - InventoryType::init(); Block::init(); Enchantment::init(); Item::init(); diff --git a/src/pocketmine/inventory/AnvilInventory.php b/src/pocketmine/inventory/AnvilInventory.php index c679144ae..e27e3e540 100644 --- a/src/pocketmine/inventory/AnvilInventory.php +++ b/src/pocketmine/inventory/AnvilInventory.php @@ -24,11 +24,28 @@ declare(strict_types=1); namespace pocketmine\inventory; use pocketmine\level\Position; +use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\Player; class AnvilInventory extends ContainerInventory{ + + /** @var FakeBlockMenu */ + protected $holder; + public function __construct(Position $pos){ - parent::__construct(new FakeBlockMenu($this, $pos), InventoryType::get(InventoryType::ANVIL)); + parent::__construct(new FakeBlockMenu($this, $pos)); + } + + public function getNetworkType() : int{ + return WindowTypes::ANVIL; + } + + public function getName() : string{ + return "Anvil"; + } + + public function getDefaultSize() : int{ + return 3; //1 input, 1 material, 1 result } /** diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 0f8d8d84e..f3cca50d1 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -34,8 +34,6 @@ use pocketmine\Server; abstract class BaseInventory implements Inventory{ - /** @var InventoryType */ - protected $type; /** @var int */ protected $maxStackSize = Inventory::MAX_STACK; /** @var int */ @@ -53,37 +51,31 @@ abstract class BaseInventory implements Inventory{ /** * @param InventoryHolder $holder - * @param InventoryType $type * @param Item[] $items - * @param int $overrideSize - * @param string $overrideTitle + * @param int $size + * @param string $title */ - public function __construct(InventoryHolder $holder, InventoryType $type, array $items = [], $overrideSize = null, $overrideTitle = null){ + public function __construct(InventoryHolder $holder, array $items = [], int $size = null, string $title = null){ $this->holder = $holder; - $this->type = $type; - if($overrideSize !== null){ - $this->size = (int) $overrideSize; - }else{ - $this->size = $this->type->getDefaultSize(); - } - - if($overrideTitle !== null){ - $this->title = $overrideTitle; - }else{ - $this->title = $this->type->getDefaultTitle(); - } - - $this->name = $this->type->getDefaultTitle(); + $this->size = $size ?? $this->getDefaultSize(); + $this->title = $title ?? $this->getName(); $this->setContents($items); } - public function __destruct(){ - $this->holder = null; - $this->slots = []; + abstract public function getName() : string; + + public function getTitle() : string{ + return $this->title; } + /** + * Returns the Minecraft PE inventory type used to show the inventory window to clients. + * @return int + */ + abstract public function getNetworkType() : int; + public function getSize() : int{ return $this->size; } @@ -92,18 +84,12 @@ abstract class BaseInventory implements Inventory{ $this->size = $size; } + abstract public function getDefaultSize() : int; + public function getMaxStackSize() : int{ return $this->maxStackSize; } - public function getName() : string{ - return $this->name; - } - - public function getTitle() : string{ - return $this->title; - } - public function getItem(int $index) : Item{ assert($index >= 0, "Inventory slot should not be negative"); return isset($this->slots[$index]) ? clone $this->slots[$index] : Item::get(Item::AIR, 0, 0); @@ -456,9 +442,4 @@ abstract class BaseInventory implements Inventory{ $player->dataPacket($pk); } } - - public function getType() : InventoryType{ - return $this->type; - } - } diff --git a/src/pocketmine/inventory/ChestInventory.php b/src/pocketmine/inventory/ChestInventory.php index 6f967a94e..283423b1c 100644 --- a/src/pocketmine/inventory/ChestInventory.php +++ b/src/pocketmine/inventory/ChestInventory.php @@ -26,12 +26,32 @@ namespace pocketmine\inventory; use pocketmine\level\Level; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; +use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\Player; use pocketmine\tile\Chest; class ChestInventory extends ContainerInventory{ + + /** @var Chest */ + protected $holder; + + /** + * @param Chest $tile + */ public function __construct(Chest $tile){ - parent::__construct($tile, InventoryType::get(InventoryType::CHEST)); + parent::__construct($tile); + } + + public function getNetworkType() : int{ + return WindowTypes::CONTAINER; + } + + public function getName() : string{ + return "Chest"; + } + + public function getDefaultSize() : int{ + return 27; } /** diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index e56e9f43e..d49a7d822 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -33,7 +33,7 @@ abstract class ContainerInventory extends BaseInventory{ parent::onOpen($who); $pk = new ContainerOpenPacket(); $pk->windowid = $who->getWindowId($this); - $pk->type = $this->getType()->getNetworkType(); + $pk->type = $this->getNetworkType(); $holder = $this->getHolder(); if($holder instanceof Vector3){ $pk->x = $holder->getX(); diff --git a/src/pocketmine/inventory/CraftingInventory.php b/src/pocketmine/inventory/CraftingInventory.php deleted file mode 100644 index bab44132d..000000000 --- a/src/pocketmine/inventory/CraftingInventory.php +++ /dev/null @@ -1,62 +0,0 @@ -getDefaultTitle() !== "Crafting"){ - throw new \InvalidStateException("Invalid Inventory type, expected CRAFTING or WORKBENCH"); - } - $this->resultInventory = $resultInventory; - parent::__construct($holder, $inventoryType); - } - - /** - * @return Inventory - */ - public function getResultInventory(){ - return $this->resultInventory; - } - - public function getSize() : int{ - return $this->getResultInventory()->getSize() + parent::getSize(); - } -} \ No newline at end of file diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index 3b68ef889..142d6e3d0 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -39,7 +39,15 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ $this->left = $left->getRealInventory(); $this->right = $right->getRealInventory(); $items = array_merge($this->left->getContents(), $this->right->getContents()); - BaseInventory::__construct($this, InventoryType::get(InventoryType::DOUBLE_CHEST), $items); + BaseInventory::__construct($this, $items); + } + + public function getName() : string{ + return "Double Chest"; + } + + public function getDefaultSize() : int{ + return $this->left->getDefaultSize() + $this->right->getDefaultSize(); } public function getInventory(){ diff --git a/src/pocketmine/inventory/EnchantInventory.php b/src/pocketmine/inventory/EnchantInventory.php index 11d3fd154..38f6290b7 100644 --- a/src/pocketmine/inventory/EnchantInventory.php +++ b/src/pocketmine/inventory/EnchantInventory.php @@ -24,11 +24,28 @@ declare(strict_types=1); namespace pocketmine\inventory; use pocketmine\level\Position; +use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\Player; class EnchantInventory extends ContainerInventory{ + + /** @var FakeBlockMenu */ + protected $holder; + public function __construct(Position $pos){ - parent::__construct(new FakeBlockMenu($this, $pos), InventoryType::get(InventoryType::ENCHANT_TABLE)); + parent::__construct(new FakeBlockMenu($this, $pos)); + } + + public function getNetworkType() : int{ + return WindowTypes::ENCHANTMENT; + } + + public function getName() : string{ + return "Enchantment Table"; + } + + public function getDefaultSize() : int{ + return 2; //1 input, 1 lapis } /** diff --git a/src/pocketmine/inventory/FurnaceInventory.php b/src/pocketmine/inventory/FurnaceInventory.php index efce4cea0..7d2a8bec3 100644 --- a/src/pocketmine/inventory/FurnaceInventory.php +++ b/src/pocketmine/inventory/FurnaceInventory.php @@ -24,11 +24,27 @@ declare(strict_types=1); namespace pocketmine\inventory; use pocketmine\item\Item; +use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\tile\Furnace; class FurnaceInventory extends ContainerInventory{ + /** @var Furnace */ + protected $holder; + public function __construct(Furnace $tile){ - parent::__construct($tile, InventoryType::get(InventoryType::FURNACE)); + parent::__construct($tile); + } + + public function getNetworkType() : int{ + return WindowTypes::FURNACE; + } + + public function getName() : string{ + return "Furnace"; + } + + public function getDefaultSize() : int{ + return 3; //1 input, 1 fuel, 1 output } /** diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index 2c81c4486..1dfcbb784 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -193,11 +193,6 @@ interface Inventory{ */ public function getViewers() : array; - /** - * @return InventoryType - */ - public function getType() : InventoryType; - /** * @return InventoryHolder */ diff --git a/src/pocketmine/inventory/InventoryType.php b/src/pocketmine/inventory/InventoryType.php deleted file mode 100644 index 7df5e0c14..000000000 --- a/src/pocketmine/inventory/InventoryType.php +++ /dev/null @@ -1,111 +0,0 @@ - 0){ - return; - } - - //TODO: move network stuff out of here - //TODO: move inventory data to json - static::$default = [ - static::CHEST => new InventoryType(27, "Chest", WindowTypes::CONTAINER), - static::DOUBLE_CHEST => new InventoryType(27 + 27, "Double Chest", WindowTypes::CONTAINER), - static::PLAYER => new InventoryType(36 + 4, "Player", WindowTypes::INVENTORY), //36 CONTAINER, 4 ARMOR - static::CRAFTING => new InventoryType(5, "Crafting", WindowTypes::INVENTORY), //yes, the use of INVENTORY is intended! 4 CRAFTING slots, 1 RESULT - static::WORKBENCH => new InventoryType(10, "Crafting", WindowTypes::WORKBENCH), //9 CRAFTING slots, 1 RESULT - static::FURNACE => new InventoryType(3, "Furnace", WindowTypes::FURNACE), //2 INPUT, 1 OUTPUT - static::ENCHANT_TABLE => new InventoryType(2, "Enchant", WindowTypes::ENCHANTMENT), //1 INPUT/OUTPUT, 1 LAPIS - static::BREWING_STAND => new InventoryType(4, "Brewing", WindowTypes::BREWING_STAND), //1 INPUT, 3 POTION - static::ANVIL => new InventoryType(3, "Anvil", WindowTypes::ANVIL) //2 INPUT, 1 OUTP - ]; - } - - /** - * @param int $defaultSize - * @param string $defaultTitle - * @param int $typeId - */ - private function __construct($defaultSize, $defaultTitle, $typeId = 0){ - $this->size = $defaultSize; - $this->title = $defaultTitle; - $this->typeId = $typeId; - } - - /** - * @return int - */ - public function getDefaultSize() : int{ - return $this->size; - } - - /** - * @return string - */ - public function getDefaultTitle() : string{ - return $this->title; - } - - /** - * @return int - */ - public function getNetworkType() : int{ - return $this->typeId; - } -} \ No newline at end of file diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index f637b60e7..b02567ea7 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -34,6 +34,7 @@ use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; use pocketmine\network\mcpe\protocol\MobEquipmentPacket; use pocketmine\network\mcpe\protocol\PlayerHotbarPacket; use pocketmine\network\mcpe\protocol\types\ContainerIds; +use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\Player; use pocketmine\Server; @@ -45,7 +46,19 @@ class PlayerInventory extends BaseInventory{ public function __construct(Human $player){ $this->resetHotbar(false); - parent::__construct($player, InventoryType::get(InventoryType::PLAYER)); + parent::__construct($player); + } + + public function getNetworkType() : int{ + return WindowTypes::INVENTORY; + } + + public function getName() : string{ + return "Player"; + } + + public function getDefaultSize() : int{ + return 40; //36 inventory, 4 armor } public function getSize() : int{ diff --git a/src/pocketmine/inventory/SlotType.php b/src/pocketmine/inventory/SlotType.php deleted file mode 100644 index 65ab00732..000000000 --- a/src/pocketmine/inventory/SlotType.php +++ /dev/null @@ -1,41 +0,0 @@ -