From afaa2cf722ec351ef9f2655ff8ad4d5c20864bb3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Oct 2014 12:57:26 +0100 Subject: [PATCH] Fixed Double Chest behavior --- src/pocketmine/block/Chest.php | 6 ++-- .../inventory/ContainerInventory.php | 9 ++--- .../inventory/DoubleChestInventory.php | 35 +++++++++++++++++++ src/pocketmine/tile/Chest.php | 5 +-- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 2b670f3159..6b5b38d3b6 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -62,7 +62,7 @@ class Chest extends Transparent{ 3 => 3, ]; - $chest = false; + $chest = null; $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; for($side = 2; $side <= 5; ++$side){ @@ -130,11 +130,11 @@ class Chest extends Transparent{ new Int("z", $this->z) ]); $nbt->Items->setTagType(NBT::TAG_Compound); - $chest = new TileChest($this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); + $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } - if(($player->gamemode & 0x01) === 0x01){ + if($player->isCreative()){ return true; } $player->addWindow($chest->getInventory()); diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index ea16b0574d..d0666cc541 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -33,10 +33,11 @@ abstract class ContainerInventory extends BaseInventory{ $pk->windowid = $who->getWindowId($this); $pk->type = $this->getType()->getNetworkType(); $pk->slots = $this->getSize(); - if($this->holder instanceof Vector3){ - $pk->x = $this->holder->getX(); - $pk->y = $this->holder->getY(); - $pk->z = $this->holder->getZ(); + $holder = $this->getHolder(); + if($holder instanceof Vector3){ + $pk->x = $holder->getX(); + $pk->y = $holder->getY(); + $pk->z = $holder->getZ(); }else{ $pk->x = $pk->y = $pk->z = 0; } diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index f819795c8a..706d273daa 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -22,6 +22,10 @@ namespace pocketmine\inventory; use pocketmine\item\Item; +use pocketmine\level\Level; +use pocketmine\network\protocol\TileEventPacket; +use pocketmine\Player; +use pocketmine\Server; use pocketmine\tile\Chest; class DoubleChestInventory extends ChestInventory implements InventoryHolder{ @@ -83,6 +87,37 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ } } + public function onOpen(Player $who){ + parent::onOpen($who); + + if(count($this->getViewers()) === 1){ + $pk = TileEventPacket::getFromPool(); + $pk->x = $this->right->getHolder()->getX(); + $pk->y = $this->right->getHolder()->getY(); + $pk->z = $this->right->getHolder()->getZ(); + $pk->case1 = 1; + $pk->case2 = 2; + if(($level = $this->right->getHolder()->getLevel()) instanceof Level){ + Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk); + } + } + } + + public function onClose(Player $who){ + if(count($this->getViewers()) === 1){ + $pk = TileEventPacket::getFromPool(); + $pk->x = $this->right->getHolder()->getX(); + $pk->y = $this->right->getHolder()->getY(); + $pk->z = $this->right->getHolder()->getZ(); + $pk->case1 = 1; + $pk->case2 = 0; + if(($level = $this->right->getHolder()->getLevel()) instanceof Level){ + Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk); + } + } + parent::onClose($who); + } + /** * @return ChestInventory */ diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 86b2b9a0fc..89e7826b6d 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -55,8 +55,6 @@ class Chest extends Spawnable implements InventoryHolder, Container{ for($i = 0; $i < $this->getSize(); ++$i){ $this->inventory->setItem($i, $this->getItem($i)); } - - $this->checkPairing(); } public function close(){ @@ -158,6 +156,9 @@ class Chest extends Spawnable implements InventoryHolder, Container{ * @return ChestInventory|DoubleChestInventory */ public function getInventory(){ + if($this->isPaired() and $this->doubleInventory === null){ + $this->checkPairing(); + } return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory; }