From 1fd7e0431b0b867dde7e18cdaf6fc7fc7137a967 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 24 May 2014 01:30:58 +0200 Subject: [PATCH] Added CustomInventory, StoneCutter inventory type, network IDs, fixed viewer list bugs --- src/pocketmine/inventory/BaseInventory.php | 4 +-- .../inventory/ContainerInventory.php | 24 ++++++-------- src/pocketmine/inventory/CustomInventory.php | 29 +++++++++++++++++ src/pocketmine/inventory/InventoryType.php | 31 ++++++++++++++----- src/pocketmine/inventory/PlayerInventory.php | 15 +++------ 5 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 src/pocketmine/inventory/CustomInventory.php diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index b043bc238..fe698c2d6 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -319,11 +319,11 @@ abstract class BaseInventory implements Inventory{ } public function onOpen(Player $who){ - + $this->viewers->attach($who); } public function onClose(Player $who){ - + $this->viewers->detach($who); } public function onSlotChange($index, $before){ diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index 907db93fb..848749805 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -24,26 +24,22 @@ namespace pocketmine\inventory; use pocketmine\network\protocol\ContainerClosePacket; use pocketmine\network\protocol\ContainerOpenPacket; use pocketmine\Player; -use pocketmine\tile\Chest; -use pocketmine\tile\Furnace; +use pocketmine\math\Vector3; abstract class ContainerInventory extends BaseInventory{ - - /** - * @return Chest|Furnace - */ - public function getHolder(){ - return $this->holder; - } - public function onOpen(Player $who){ $pk = new ContainerOpenPacket; $pk->windowid = $who->getWindowId($this); - $pk->type = 0; + $pk->type = $this->getType()->getNetworkType(); $pk->slots = $this->getSize(); - $pk->x = $this->getHolder()->getX(); - $pk->y = $this->getHolder()->getY(); - $pk->z = $this->getHolder()->getZ(); + if($this->holder instanceof Vector3){ + $pk->x = $this->holder->getX(); + $pk->y = $this->holder->getY(); + $pk->z = $this->holder->getZ(); + }else{ + $pk->x = $pk->y = $pk->z = 0; + } + $who->dataPacket($pk); } diff --git a/src/pocketmine/inventory/CustomInventory.php b/src/pocketmine/inventory/CustomInventory.php new file mode 100644 index 000000000..6f94fc746 --- /dev/null +++ b/src/pocketmine/inventory/CustomInventory.php @@ -0,0 +1,29 @@ +size = $defaultSize; $this->title = $defaultTitle; + $this->typeId = $typeId; } /** @@ -76,4 +86,11 @@ class InventoryType{ public function getDefaultTitle(){ return $this->title; } + + /** + * @return int + */ + public function getNetworkType(){ + return $this->typeId; + } } \ No newline at end of file diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 56df20047..9c27505c2 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -141,7 +141,7 @@ class PlayerInventory extends BaseInventory{ if($player === $this->getHolder()){ //TODO: Check if Mojang enabled sending a single slot this //$this->sendSlot($this->getHeldItemSlot()); - $this->sendContents($this->getHolder()); + $this->sendContents($player); }else{ $player->dataPacket(clone $pk); } @@ -153,11 +153,6 @@ class PlayerInventory extends BaseInventory{ if($index >= $this->getSize()){ $this->sendArmorContents($this->getHolder()->getViewers()); - if($this->getHolder() instanceof Player){ - $this->sendArmorContents($this->getHolder()); - } - }elseif($this->getHolder() instanceof Player){ - $this->sendSlot($index, $this->getHolder()); } } @@ -213,8 +208,8 @@ class PlayerInventory extends BaseInventory{ if($index >= $this->getSize()){ //Armor change Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $item, $index)); if($ev->isCancelled() and $this->getHolder() instanceof Player){ - $this->sendArmorContents($this->getHolder()); - $this->sendContents($this->getHolder()); + $this->sendArmorContents($this->getViewers()); + $this->sendContents($this->getViewers()); return false; } @@ -235,8 +230,8 @@ class PlayerInventory extends BaseInventory{ if($index >= $this->getSize() and $index < $this->size){ //Armor change Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $old, $item, $index)); if($ev->isCancelled()){ - $this->sendArmorContents($this); - $this->sendContents($this); + $this->sendArmorContents($this->getViewers()); + $this->sendContents($this->getViewers()); return; }