fromId($stateMeta); if($coralType === null){ throw new InvalidBlockStateException("No such coral type"); } $this->coralType = $coralType; } public function writeStateToMeta() : int{ return CoralTypeIdMap::getInstance()->toId($this->coralType); } protected function writeStateToItemMeta() : int{ return $this->writeStateToMeta(); } public function getStateBitmask() : int{ return 0b0111; } public function readStateFromWorld() : void{ //TODO: this hack ensures correct state of coral plants, because they don't retain their dead flag in metadata $world = $this->position->getWorld(); $this->dead = true; foreach($this->position->sides() as $vector3){ if($world->getBlock($vector3) instanceof Water){ $this->dead = false; break; } } } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->canBeSupportedBy($tx->fetchBlock($blockReplace->getPosition()->down()))){ return false; } 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->down()))){ $world->useBreakOn($this->position); }else{ parent::onNearbyBlockChange(); } } private function canBeSupportedBy(Block $block) : bool{ return $block->getSupportType(Facing::UP)->hasCenterSupport(); } }