meta = $meta; } public function canBeReplaced() : bool{ return $this->meta === 2 or $this->meta === 3; //grass or fern } public function getName() : string{ static $names = [ 0 => "Sunflower", 1 => "Lilac", 2 => "Double Tallgrass", 3 => "Large Fern", 4 => "Rose Bush", 5 => "Peony" ]; return $names[$this->getVariant()] ?? ""; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $id = $blockReplace->getSide(Vector3::SIDE_DOWN)->getId(); if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Vector3::SIDE_UP)->canBeReplaced()){ $this->getLevel()->setBlock($blockReplace, $this, false, false); $this->getLevel()->setBlock($blockReplace->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false); return true; } return false; } /** * Returns whether this double-plant has a corresponding other half. * @return bool */ public function isValidHalfPlant() : bool{ if($this->meta & self::BITFLAG_TOP){ $other = $this->getSide(Vector3::SIDE_DOWN); }else{ $other = $this->getSide(Vector3::SIDE_UP); } return ( $other->getId() === $this->getId() and $other->getVariant() === $this->getVariant() and ($other->getDamage() & self::BITFLAG_TOP) !== ($this->getDamage() & self::BITFLAG_TOP) ); } public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $down = $this->getSide(Vector3::SIDE_DOWN); if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $down->isTransparent())){ $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } } return false; } public function onBreak(Item $item, Player $player = null) : bool{ if(parent::onBreak($item, $player) and $this->isValidHalfPlant()){ $this->getLevel()->useBreakOn($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), $item, $player, $player !== null); } return false; } public function getVariantBitmask() : int{ return 0x07; } public function getToolType() : int{ return ($this->meta === 2 or $this->meta === 3) ? BlockToolType::TYPE_SHEARS : BlockToolType::TYPE_NONE; } public function getToolHarvestLevel() : int{ return ($this->meta === 2 or $this->meta === 3) ? 1 : 0; //only grass or fern require shears } public function getDrops(Item $item) : array{ if($this->meta & self::BITFLAG_TOP){ if($this->isCompatibleWithTool($item)){ return parent::getDrops($item); } if(mt_rand(0, 24) === 0){ return [ ItemFactory::get(Item::SEEDS, 0, 1) ]; } } return []; } }