From e038c4295d50c31883066e886c03187684247eff Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 27 Sep 2018 18:46:01 +0100 Subject: [PATCH] Clean up abhorrent mess of Slab placement code --- src/pocketmine/block/Slab.php | 51 ++++++++++------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index f138d1c97..d6b8fb63f 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -78,48 +78,25 @@ abstract class Slab extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($face === Facing::DOWN){ - if($blockClicked instanceof Slab and $blockClicked->isSameType($this) and $blockClicked->top){ - $this->getLevel()->setBlock($blockClicked, $this->getDouble()); + /* note these conditions can't be merged, since one targets clicked and the other replace */ - return true; - }elseif($blockReplace->isSameType($this)){ - $this->getLevel()->setBlock($blockReplace, $this->getDouble()); - - return true; - }else{ - $this->top = true; - } - }elseif($face === Facing::UP){ - if($blockClicked instanceof Slab and $blockClicked->isSameType($this) and !$blockClicked->top){ - $this->getLevel()->setBlock($blockClicked, $this->getDouble()); - - return true; - }elseif($blockReplace->isSameType($this)){ - $this->getLevel()->setBlock($blockReplace, $this->getDouble()); - - return true; - } - }else{ //TODO: collision - if($blockReplace->getId() === $this->getId()){ - if($blockReplace->getVariant() === $this->variant){ - $this->getLevel()->setBlock($blockReplace, $this->getDouble()); - - return true; - } - - return false; - }else{ - if($clickVector->y > 0.5){ - $this->top = true; - } - } + if($blockClicked instanceof Slab and $blockClicked->isSameType($this) and ( + ($face === Facing::DOWN and $blockClicked->top) or //Bottom face of top slab + ($face === Facing::UP and !$blockClicked->top) //Top face of bottom slab + )){ + return $this->level->setBlock($blockClicked, $this->getDouble()); } - if($blockReplace->getId() === $this->getId() and $blockClicked->getVariant() !== $this->variant){ - return false; + if($blockReplace instanceof Slab and $blockReplace->isSameType($this) and ( + ($blockReplace->top and $clickVector->y <= 0.5) or + (!$blockReplace->top and $clickVector->y >= 0.5) + )){ + //Clicked in empty half of existing slab + return $this->level->setBlock($blockReplace, $this->getDouble()); } + $this->top = ($face !== Facing::UP && $clickVector->y > 0.5) || $face === Facing::DOWN; + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); }