22declare(strict_types=1);
24namespace pocketmine\block\utils;
32use
function array_key_first;
39trait MultiAnySupportTrait{
40 use MultiAnyFacingTrait;
47 abstract protected function getInitialPlaceFaces(Block $blockReplace) : array;
49 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked,
int $face, Vector3 $clickVector, ?Player $player =
null) : bool{
50 $this->faces = $this->getInitialPlaceFaces($blockReplace);
51 $availableFaces = $this->getAvailableFaces();
53 if(count($availableFaces) === 0){
57 $opposite = Facing::opposite($face);
58 $placedFace = isset($availableFaces[$opposite]) ? $opposite : array_key_first($availableFaces);
59 $this->faces[$placedFace] = $placedFace;
61 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
64 public function onNearbyBlockChange() : void{
67 foreach($this->faces as $face){
68 if($this->getAdjacentSupportType($face) !== SupportType::FULL){
69 unset($this->faces[$face]);
75 $world = $this->position->getWorld();
76 if(count($this->faces) === 0){
77 $world->useBreakOn($this->position);
79 $world->setBlock($this->position, $this);
87 private function getAvailableFaces() : array{
89 foreach(Facing::ALL as $face){
90 if(!$this->hasFace($face) && $this->getAdjacentSupportType($face) === SupportType::FULL){
91 $faces[$face] = $face;