mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Fixed hanging signs placement criteria (#6775)
This commit is contained in:
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\HorizontalFacing;
|
||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||
use pocketmine\block\utils\SupportType;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\Axis;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
@ -50,16 +51,31 @@ final class WallHangingSign extends BaseSign implements HorizontalFacing{
|
||||
}
|
||||
|
||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
if(Facing::axis($face) === Axis::Y){
|
||||
if($player === null){
|
||||
return false;
|
||||
}
|
||||
$attachFace = Facing::axis($face) === Axis::Y ? Facing::rotateY($player->getHorizontalFacing(), clockwise: true) : $face;
|
||||
|
||||
if($this->canBeSupportedAt($blockReplace->getSide($attachFace), $attachFace)){
|
||||
$direction = $attachFace;
|
||||
}elseif($this->canBeSupportedAt($blockReplace->getSide($opposite = Facing::opposite($attachFace)), $opposite)){
|
||||
$direction = $opposite;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->facing = Facing::rotateY($face, clockwise: true);
|
||||
$this->facing = Facing::rotateY(Facing::opposite($direction), clockwise: true);
|
||||
//the front should always face the player if possible
|
||||
if($player !== null && $this->facing === $player->getHorizontalFacing()){
|
||||
if($this->facing === $player->getHorizontalFacing()){
|
||||
$this->facing = Facing::opposite($this->facing);
|
||||
}
|
||||
|
||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||
return
|
||||
($block instanceof WallHangingSign && Facing::axis(Facing::rotateY($block->getFacing(), clockwise: true)) === Facing::axis($face)) ||
|
||||
$block->getSupportType(Facing::opposite($face)) === SupportType::FULL;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user