Skip to content

Commit 716c1f2

Browse files
committed
Fixed slabs again
1 parent 0df3b00 commit 716c1f2

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/pocketmine/block/Block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function canBeReplaced() : bool{
164164
return false;
165165
}
166166

167-
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector) : bool{
167+
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
168168
return $blockReplace->canBeReplaced();
169169
}
170170

src/pocketmine/block/Slab.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,20 @@ public function __construct(int $meta = 0){
3636

3737
abstract public function getDoubleSlabId() : int;
3838

39-
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector) : bool{
40-
return parent::canBePlacedAt($blockReplace, $clickVector) or
41-
(
42-
$blockReplace->getId() === $this->getId() and
43-
$blockReplace->getVariant() === $this->getVariant() and
44-
(
45-
(($blockReplace->getDamage() & 0x08) !== 0 and ($clickVector->y <= 0.5 or $clickVector->y === 1.0)) or //top slab, fill bottom half
46-
(($blockReplace->getDamage() & 0x08) === 0 and ($clickVector->y >= 0.5 or $clickVector->y === 0.0)) //bottom slab, fill top half
47-
)
48-
);
39+
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
40+
if(parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock)){
41+
return true;
42+
}
43+
44+
if($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->getVariant()){
45+
if(($blockReplace->getDamage() & 0x08) !== 0){ //Trying to combine with top slab
46+
return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Vector3::SIDE_UP);
47+
}else{
48+
return $clickVector->y >= 0.5 or (!$isClickedBlock and $face === Vector3::SIDE_DOWN);
49+
}
50+
}
51+
52+
return false;
4953
}
5054

5155
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{

src/pocketmine/level/Level.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,10 +1793,10 @@ public function useItemOn(Vector3 $vector, Item &$item, int $face, Vector3 $face
17931793
return false;
17941794
}
17951795

1796-
if($hand->canBePlacedAt($blockClicked, $facePos)){
1796+
if($hand->canBePlacedAt($blockClicked, $facePos, $face, true)){
17971797
$blockReplace = $blockClicked;
17981798
$hand->position($blockReplace);
1799-
}elseif(!$hand->canBePlacedAt($blockReplace, $facePos)){
1799+
}elseif(!$hand->canBePlacedAt($blockReplace, $facePos, $face, false)){
18001800
return false;
18011801
}
18021802

0 commit comments

Comments
 (0)