From 28f332233750f2fce12a60a6987224fb9c653e12 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 27 May 2019 17:30:57 +0100 Subject: [PATCH] Block: add onPostPlace() hook --- src/pocketmine/block/Block.php | 4 ++++ src/pocketmine/block/Chest.php | 36 ++++++++++++++++------------------ src/pocketmine/world/World.php | 1 + 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 16b242839..c1b16ce08 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -253,6 +253,10 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ return $this->getWorld()->setBlock($blockReplace, $this); } + public function onPostPlace() : void{ + + } + /** * Returns an object containing information about the destruction requirements of this block. * diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 6c72e6134..3e08722ee 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -62,29 +62,27 @@ class Chest extends Transparent{ $this->facing = Facing::opposite($player->getHorizontalFacing()); } - if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ - $tile = $this->world->getTile($this); - if($tile instanceof TileChest){ - foreach([ - Facing::rotateY($this->facing, true), - Facing::rotateY($this->facing, false) - ] as $side){ - $c = $this->getSide($side); - if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){ - $pair = $this->world->getTile($c); - if($pair instanceof TileChest and !$pair->isPaired()){ - $pair->pairWith($tile); - $tile->pairWith($pair); - break; - } + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); + } + + public function onPostPlace() : void{ + $tile = $this->world->getTile($this); + if($tile instanceof TileChest){ + foreach([ + Facing::rotateY($this->facing, true), + Facing::rotateY($this->facing, false) + ] as $side){ + $c = $this->getSide($side); + if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){ + $pair = $this->world->getTile($c); + if($pair instanceof TileChest and !$pair->isPaired()){ + $pair->pairWith($tile); + $tile->pairWith($pair); + break; } } } - - return true; } - - return false; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/pocketmine/world/World.php b/src/pocketmine/world/World.php index 7f65df8f1..44fecc67b 100644 --- a/src/pocketmine/world/World.php +++ b/src/pocketmine/world/World.php @@ -1863,6 +1863,7 @@ class World implements ChunkManager, Metadatable{ //TODO: seal this up inside block placement $tile->copyDataFromItem($item); } + $hand->onPostPlace(); if($playSound){ $this->addSound($hand, new BlockPlaceSound($hand));