From a944641509f6f6f9c9172f9a452d53614d712bec Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 12 Oct 2018 12:26:44 +0100 Subject: [PATCH] Torch: Fix placement issues when clicking the bottom of a block, closes #2453 (#2474) --- src/pocketmine/block/Torch.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 8e889bfe5..1238fe110 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -73,16 +73,28 @@ class Torch extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $below = $this->getSide(Facing::DOWN); - - if(!$blockClicked->isTransparent() and $face !== Facing::DOWN){ - $this->facing = $face; - return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); - }elseif(!$below->isTransparent() or $below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL){ + if($blockClicked->canBeReplaced() and !$blockClicked->getSide(Facing::DOWN)->isTransparent()){ $this->facing = Facing::UP; return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); + }elseif($face !== Facing::DOWN and (!$blockClicked->isTransparent() or ($face === Facing::UP and ($blockClicked->getId() === self::FENCE or $blockClicked->getId() === self::COBBLESTONE_WALL)))){ + $this->facing = $face; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); + }else{ + static $faces = [ + Facing::SOUTH, + Facing::WEST, + Facing::NORTH, + Facing::EAST, + Facing::DOWN, + ]; + foreach($faces as $side){ + $block = $this->getSide($side); + if(!$block->isTransparent()){ + $this->facing = Facing::opposite($side); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); + } + } } - return false; } }