top ? self::BITFLAG_TOP : 0); } public function readStateFromData(int $id, int $stateMeta) : void{ $this->top = ($stateMeta & self::BITFLAG_TOP) !== 0; } public function getStateBitmask() : int{ return 0b1000; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $id = $blockReplace->getSide(Facing::DOWN)->getId(); if(($id === BlockIds::GRASS or $id === BlockIds::DIRT) and $blockReplace->getSide(Facing::UP)->canBeReplaced()){ $top = clone $this; $top->top = true; $transaction = new BlockTransaction($this->level); $transaction->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top); return $transaction->apply(); } return false; } /** * Returns whether this double-plant has a corresponding other half. * @return bool */ public function isValidHalfPlant() : bool{ $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); return ( $other instanceof DoublePlant and $other->isSameType($this) and $other->top !== $this->top ); } public function onNearbyBlockChange() : void{ if(!$this->isValidHalfPlant() or (!$this->top and $this->getSide(Facing::DOWN)->isTransparent())){ $this->getLevel()->useBreakOn($this); } } public function getDrops(Item $item) : array{ return $this->top ? parent::getDrops($item) : []; } public function getAffectedBlocks() : array{ if($this->isValidHalfPlant()){ return [$this, $this->getSide($this->top ? Facing::DOWN : Facing::UP)]; } return parent::getAffectedBlocks(); } }