From 8e6a5813eaa88ba24b5b8176943259c5f755203d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 28 Sep 2018 20:12:41 +0100 Subject: [PATCH] Don't auto-create tiles on activate this complicates the code unnecessarily and doesn't produce the desired effect in most cases anyway. --- src/pocketmine/block/Chest.php | 25 ++++++++++--------------- src/pocketmine/block/EnderChest.php | 18 ++++-------------- src/pocketmine/block/Furnace.php | 10 ++-------- src/pocketmine/block/ItemFrame.php | 14 ++++++-------- 4 files changed, 22 insertions(+), 45 deletions(-) diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 323f9f544..c5f22ebed 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -109,23 +109,18 @@ class Chest extends Transparent{ public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ - $t = $this->getLevel()->getTile($this); - $chest = null; - if($t instanceof TileChest){ - $chest = $t; - }else{ - $chest = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this)); - } + $chest = $this->getLevel()->getTile($this); + if($chest instanceof TileChest){ + if( + !$this->getSide(Facing::UP)->isTransparent() or + ($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Facing::UP)->isTransparent()) or + !$chest->canOpenWith($item->getCustomName()) + ){ + return true; + } - if( - !$this->getSide(Facing::UP)->isTransparent() or - ($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Facing::UP)->isTransparent()) or - !$chest->canOpenWith($item->getCustomName()) - ){ - return true; + $player->addWindow($chest->getInventory()); } - - $player->addWindow($chest->getInventory()); } return true; diff --git a/src/pocketmine/block/EnderChest.php b/src/pocketmine/block/EnderChest.php index 8bf91e201..e2d273d4a 100644 --- a/src/pocketmine/block/EnderChest.php +++ b/src/pocketmine/block/EnderChest.php @@ -76,21 +76,11 @@ class EnderChest extends Chest{ public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ - - $t = $this->getLevel()->getTile($this); - $enderChest = null; - if($t instanceof TileEnderChest){ - $enderChest = $t; - }else{ - $enderChest = Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this)); + $enderChest = $this->getLevel()->getTile($this); + if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){ + $player->getEnderChestInventory()->setHolderPosition($enderChest); + $player->addWindow($player->getEnderChestInventory()); } - - if(!$this->getSide(Facing::UP)->isTransparent()){ - return true; - } - - $player->getEnderChestInventory()->setHolderPosition($enderChest); - $player->addWindow($player->getEnderChestInventory()); } return true; diff --git a/src/pocketmine/block/Furnace.php b/src/pocketmine/block/Furnace.php index a31135579..820195d6e 100644 --- a/src/pocketmine/block/Furnace.php +++ b/src/pocketmine/block/Furnace.php @@ -104,15 +104,9 @@ class Furnace extends Solid{ public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ $furnace = $this->getLevel()->getTile($this); - if(!($furnace instanceof TileFurnace)){ - $furnace = Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this)); + if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){ + $player->addWindow($furnace->getInventory()); } - - if(!$furnace->canOpenWith($item->getCustomName())){ - return true; - } - - $player->addWindow($furnace->getInventory()); } return true; diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index 8e3315390..ca9dab19f 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -60,14 +60,12 @@ class ItemFrame extends Flowable{ public function onActivate(Item $item, Player $player = null) : bool{ $tile = $this->level->getTile($this); - if(!($tile instanceof TileItemFrame)){ - $tile = Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this)); - } - - if($tile->hasItem()){ - $tile->setItemRotation(($tile->getItemRotation() + 1) % 8); - }elseif(!$item->isNull()){ - $tile->setItem($item->pop()); + if($tile instanceof TileItemFrame){ + if($tile->hasItem()){ + $tile->setItemRotation(($tile->getItemRotation() + 1) % 8); + }elseif(!$item->isNull()){ + $tile->setItem($item->pop()); + } } return true;