From 1f4f8ab3f0cfc748f07beea7d7126a1e85ec5d5d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 27 Mar 2018 11:20:23 +0100 Subject: [PATCH] Inventory: Removed BigCraftingGrid, allow arbitrary size parameter This is more flexible and requires less classes. --- src/pocketmine/Player.php | 7 ++--- src/pocketmine/block/CraftingTable.php | 4 +-- src/pocketmine/inventory/BigCraftingGrid.php | 31 -------------------- src/pocketmine/inventory/CraftingGrid.php | 10 +++++-- 4 files changed, 13 insertions(+), 39 deletions(-) delete mode 100644 src/pocketmine/inventory/BigCraftingGrid.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b6d6f0be7..6365dd959 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -68,7 +68,6 @@ use pocketmine\event\player\PlayerToggleSneakEvent; use pocketmine\event\player\PlayerToggleSprintEvent; use pocketmine\event\player\PlayerTransferEvent; use pocketmine\event\server\DataPacketSendEvent; -use pocketmine\inventory\BigCraftingGrid; use pocketmine\inventory\CraftingGrid; use pocketmine\inventory\Inventory; use pocketmine\inventory\PlayerCursorInventory; @@ -3764,7 +3763,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->cursorInventory = new PlayerCursorInventory($this); $this->addWindow($this->cursorInventory, ContainerIds::CURSOR, true); - $this->craftingGrid = new CraftingGrid($this); + $this->craftingGrid = new CraftingGrid($this, CraftingGrid::SIZE_SMALL); //TODO: more windows } @@ -3795,8 +3794,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->craftingGrid->clearAll(); } - if($this->craftingGrid instanceof BigCraftingGrid){ - $this->craftingGrid = new CraftingGrid($this); + if($this->craftingGrid->getGridWidth() > CraftingGrid::SIZE_SMALL){ + $this->craftingGrid = new CraftingGrid($this, CraftingGrid::SIZE_SMALL); } } diff --git a/src/pocketmine/block/CraftingTable.php b/src/pocketmine/block/CraftingTable.php index da41090af..05b52fd6a 100644 --- a/src/pocketmine/block/CraftingTable.php +++ b/src/pocketmine/block/CraftingTable.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\inventory\BigCraftingGrid; +use pocketmine\inventory\CraftingGrid; use pocketmine\item\Item; use pocketmine\Player; @@ -49,7 +49,7 @@ class CraftingTable extends Solid{ public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ - $player->setCraftingGrid(new BigCraftingGrid($player)); + $player->setCraftingGrid(new CraftingGrid($player, CraftingGrid::SIZE_BIG)); } return true; diff --git a/src/pocketmine/inventory/BigCraftingGrid.php b/src/pocketmine/inventory/BigCraftingGrid.php deleted file mode 100644 index 85ecc3405..000000000 --- a/src/pocketmine/inventory/BigCraftingGrid.php +++ /dev/null @@ -1,31 +0,0 @@ -holder = $holder; + $this->gridWidth = $gridWidth; parent::__construct(); } public function getGridWidth() : int{ - return 2; + return $this->gridWidth; } public function getDefaultSize() : int{