diff --git a/src/pocketmine/inventory/AnvilInventory.php b/src/pocketmine/inventory/AnvilInventory.php index 130220f09..7d74fdc01 100644 --- a/src/pocketmine/inventory/AnvilInventory.php +++ b/src/pocketmine/inventory/AnvilInventory.php @@ -29,11 +29,11 @@ use pocketmine\Player; class AnvilInventory extends ContainerInventory{ - /** @var FakeBlockMenu */ + /** @var Position */ protected $holder; public function __construct(Position $pos){ - parent::__construct(new FakeBlockMenu($this, $pos)); + parent::__construct($pos->asPosition()); } public function getNetworkType() : int{ @@ -50,7 +50,7 @@ class AnvilInventory extends ContainerInventory{ /** * This override is here for documentation and code completion purposes only. - * @return FakeBlockMenu + * @return Position */ public function getHolder(){ return $this->holder; diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index aaa5ebb6a..a465843c2 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -45,18 +45,13 @@ abstract class BaseInventory implements Inventory{ protected $slots = []; /** @var Player[] */ protected $viewers = []; - /** @var InventoryHolder */ - protected $holder; /** - * @param InventoryHolder $holder - * @param Item[] $items - * @param int $size - * @param string $title + * @param Item[] $items + * @param int $size + * @param string $title */ - public function __construct(InventoryHolder $holder, array $items = [], int $size = null, string $title = null){ - $this->holder = $holder; - + public function __construct(array $items = [], int $size = null, string $title = null){ $this->slots = new \SplFixedArray($size ?? $this->getDefaultSize()); $this->title = $title ?? $this->getName(); @@ -379,10 +374,6 @@ abstract class BaseInventory implements Inventory{ } } - public function getHolder(){ - return $this->holder; - } - public function setMaxStackSize(int $size) : void{ $this->maxStackSize = $size; } diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index 03fe3d847..89fef74d6 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -30,6 +30,14 @@ use pocketmine\network\mcpe\protocol\ContainerOpenPacket; use pocketmine\Player; abstract class ContainerInventory extends BaseInventory{ + /** @var Vector3 */ + protected $holder; + + public function __construct(Vector3 $holder, array $items = [], int $size = null, string $title = null){ + $this->holder = $holder; + parent::__construct($items, $size, $title); + } + public function onOpen(Player $who) : void{ parent::onOpen($who); $pk = new ContainerOpenPacket(); @@ -65,4 +73,11 @@ abstract class ContainerInventory extends BaseInventory{ * @return int */ abstract public function getNetworkType() : int; + + /** + * @return Vector3 + */ + public function getHolder(){ + return $this->holder; + } } diff --git a/src/pocketmine/inventory/CraftingGrid.php b/src/pocketmine/inventory/CraftingGrid.php index 18f34af99..3df72fd29 100644 --- a/src/pocketmine/inventory/CraftingGrid.php +++ b/src/pocketmine/inventory/CraftingGrid.php @@ -26,9 +26,12 @@ namespace pocketmine\inventory; use pocketmine\Player; class CraftingGrid extends BaseInventory{ + /** @var Player */ + protected $holder; public function __construct(Player $holder){ - parent::__construct($holder); + $this->holder = $holder; + parent::__construct(); } public function getGridWidth() : int{ @@ -54,4 +57,11 @@ class CraftingGrid extends BaseInventory{ public function sendContents($target) : void{ //no way to do this } + + /** + * @return Player + */ + public function getHolder(){ + return $this->holder; + } } diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index 0ae5e2781..7755b5f2a 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -37,7 +37,7 @@ 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, $items); + BaseInventory::__construct($items); } public function getName() : string{ diff --git a/src/pocketmine/inventory/EnchantInventory.php b/src/pocketmine/inventory/EnchantInventory.php index 50d3a2126..e6f9cf118 100644 --- a/src/pocketmine/inventory/EnchantInventory.php +++ b/src/pocketmine/inventory/EnchantInventory.php @@ -29,11 +29,11 @@ use pocketmine\Player; class EnchantInventory extends ContainerInventory{ - /** @var FakeBlockMenu */ + /** @var Position */ protected $holder; public function __construct(Position $pos){ - parent::__construct(new FakeBlockMenu($this, $pos)); + parent::__construct($pos->asPosition()); } public function getNetworkType() : int{ @@ -50,7 +50,7 @@ class EnchantInventory extends ContainerInventory{ /** * This override is here for documentation and code completion purposes only. - * @return FakeBlockMenu + * @return Position */ public function getHolder(){ return $this->holder; diff --git a/src/pocketmine/inventory/EnderChestInventory.php b/src/pocketmine/inventory/EnderChestInventory.php index 9291fe79e..1efddecec 100644 --- a/src/pocketmine/inventory/EnderChestInventory.php +++ b/src/pocketmine/inventory/EnderChestInventory.php @@ -24,16 +24,17 @@ declare(strict_types=1); namespace pocketmine\inventory; use pocketmine\entity\Human; +use pocketmine\level\Position; use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\tile\EnderChest; class EnderChestInventory extends ChestInventory{ - /** @var FakeBlockMenu */ + /** @var Position */ protected $holder; public function __construct(Human $owner){ - ContainerInventory::__construct(new FakeBlockMenu($this, $owner->getPosition())); + ContainerInventory::__construct(new Position()); } public function getNetworkType() : int{ @@ -60,7 +61,7 @@ class EnderChestInventory extends ChestInventory{ /** * This override is here for documentation and code completion purposes only. - * @return FakeBlockMenu + * @return Position */ public function getHolder(){ return $this->holder; diff --git a/src/pocketmine/inventory/EntityInventory.php b/src/pocketmine/inventory/EntityInventory.php index 18c41696a..28c4e7583 100644 --- a/src/pocketmine/inventory/EntityInventory.php +++ b/src/pocketmine/inventory/EntityInventory.php @@ -32,6 +32,11 @@ abstract class EntityInventory extends BaseInventory{ /** @var Entity */ protected $holder; + public function __construct(Entity $holder, array $items = [], int $size = null, string $title = null){ + $this->holder = $holder; + parent::__construct($items, $size, $title); + } + protected function doSetItemEvents(int $index, Item $newItem) : ?Item{ Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($this->getHolder(), $this->getItem($index), $newItem, $index)); if($ev->isCancelled()){ @@ -42,9 +47,9 @@ abstract class EntityInventory extends BaseInventory{ } /** - * @return Entity|InventoryHolder + * @return Entity */ public function getHolder(){ - return parent::getHolder(); + return $this->holder; } } diff --git a/src/pocketmine/inventory/FakeBlockMenu.php b/src/pocketmine/inventory/FakeBlockMenu.php deleted file mode 100644 index d5db83a0c..000000000 --- a/src/pocketmine/inventory/FakeBlockMenu.php +++ /dev/null @@ -1,40 +0,0 @@ -inventory = $inventory; - parent::__construct($pos->x, $pos->y, $pos->z, $pos->level); - } - - public function getInventory(){ - return $this->inventory; - } -} diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index dfa05aa0c..abe48afa6 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -201,11 +201,6 @@ interface Inventory{ */ public function getViewers() : array; - /** - * @return InventoryHolder - */ - public function getHolder(); - /** * @param Player $who */ diff --git a/src/pocketmine/inventory/PlayerCursorInventory.php b/src/pocketmine/inventory/PlayerCursorInventory.php index c1020f6cf..b967139f5 100644 --- a/src/pocketmine/inventory/PlayerCursorInventory.php +++ b/src/pocketmine/inventory/PlayerCursorInventory.php @@ -30,7 +30,8 @@ class PlayerCursorInventory extends BaseInventory{ protected $holder; public function __construct(Player $holder){ - parent::__construct($holder); + $this->holder = $holder; + parent::__construct(); } public function getName() : string{