From 716c1f29b4dd65cdb60348bad932d11de3267a5e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 24 Oct 2017 10:23:07 +0100 Subject: [PATCH] Fixed slabs again --- src/pocketmine/block/Block.php | 2 +- src/pocketmine/block/Slab.php | 24 ++++++++++++++---------- src/pocketmine/level/Level.php | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 64eda69b8..ff99e072f 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -164,7 +164,7 @@ class Block extends Position implements BlockIds, Metadatable{ return false; } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ return $blockReplace->canBeReplaced(); } diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 8af41753a..08d97ab19 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -36,16 +36,20 @@ abstract class Slab extends Transparent{ abstract public function getDoubleSlabId() : int; - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector) : bool{ - return parent::canBePlacedAt($blockReplace, $clickVector) or - ( - $blockReplace->getId() === $this->getId() and - $blockReplace->getVariant() === $this->getVariant() and - ( - (($blockReplace->getDamage() & 0x08) !== 0 and ($clickVector->y <= 0.5 or $clickVector->y === 1.0)) or //top slab, fill bottom half - (($blockReplace->getDamage() & 0x08) === 0 and ($clickVector->y >= 0.5 or $clickVector->y === 0.0)) //bottom slab, fill top half - ) - ); + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + if(parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock)){ + return true; + } + + if($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->getVariant()){ + if(($blockReplace->getDamage() & 0x08) !== 0){ //Trying to combine with top slab + return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Vector3::SIDE_UP); + }else{ + return $clickVector->y >= 0.5 or (!$isClickedBlock and $face === Vector3::SIDE_DOWN); + } + } + + return false; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 3321d7a8d..36cdac716 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1793,10 +1793,10 @@ class Level implements ChunkManager, Metadatable{ return false; } - if($hand->canBePlacedAt($blockClicked, $facePos)){ + if($hand->canBePlacedAt($blockClicked, $facePos, $face, true)){ $blockReplace = $blockClicked; $hand->position($blockReplace); - }elseif(!$hand->canBePlacedAt($blockReplace, $facePos)){ + }elseif(!$hand->canBePlacedAt($blockReplace, $facePos, $face, false)){ return false; }