toId($this->coralType); } protected function decodeState(BlockDataReader $r) : void{ parent::decodeState($r); $this->facing = $r->readHorizontalFacing(); } protected function encodeState(BlockDataWriter $w) : void{ parent::encodeState($w); $w->writeHorizontalFacing($this->facing); } public function asItem() : Item{ return ItemFactory::getInstance()->get( $this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN, $this->writeStateToItemMeta() ); } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $axis = Facing::axis($face); if(($axis !== Axis::X && $axis !== Axis::Z) || !$this->canBeSupportedBy($blockClicked, $face)){ return false; } $this->facing = $face; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ $world = $this->position->getWorld(); if(!$this->canBeSupportedBy($world->getBlock($this->position->getSide(Facing::opposite($this->facing))), $this->facing)){ $world->useBreakOn($this->position); }else{ parent::onNearbyBlockChange(); } } private function canBeSupportedBy(Block $block, int $face) : bool{ return $block->getSupportType($face)->hasCenterSupport(); } }