PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
CeilingEdgesHangingSign.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
27use pocketmine\block\utils\HorizontalFacingOption;
28use pocketmine\block\utils\HorizontalFacingTrait;
29use pocketmine\block\utils\SupportType;
35
36final class CeilingEdgesHangingSign extends BaseSign implements HorizontalFacing{
37 use HorizontalFacingTrait;
38
39 protected function getSupportingFace() : Facing{
40 return Facing::UP;
41 }
42
43 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{
44 if($face !== Facing::DOWN){
45 return false;
46 }
47 if($player !== null){
48 $this->facing = HorizontalFacingOption::fromFacing(Facing::opposite($player->getHorizontalFacing()));
49 }
50 if(!$this->canBeSupportedAt($blockReplace)){
51 return false;
52 }
53
54 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
55 }
56
57 public function onNearbyBlockChange() : void{
58 if(!$this->canBeSupportedAt($this)){
59 $this->position->getWorld()->useBreakOn($this->position);
60 }
61 }
62
63 private function canBeSupportedAt(Block $block) : bool{
64 $supportBlock = $block->getSide(Facing::UP);
65 return
66 $supportBlock->getSupportType(Facing::DOWN) === SupportType::FULL ||
67 (($supportBlock instanceof WallHangingSign || $supportBlock instanceof CeilingEdgesHangingSign) && Facing::axis($supportBlock->getFacing()->toFacing()) === Facing::axis($this->facing->toFacing()));
68 }
69
70 protected function getFacingDegrees() : float{
71 return match($this->facing){
72 HorizontalFacingOption::SOUTH => 0,
73 HorizontalFacingOption::WEST => 90,
74 HorizontalFacingOption::NORTH => 180,
75 HorizontalFacingOption::EAST => 270,
76 };
77 }
78}
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)