age; } public function readStateFromData(int $id, int $stateMeta) : void{ $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15); } public function getStateBitmask() : int{ return 0b1111; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($item instanceof Fertilizer){ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){ for($y = 1; $y < 3; ++$y){ $b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === BlockLegacyIds::AIR){ $ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK)); $ev->call(); if($ev->isCancelled()){ break; } $this->getWorld()->setBlock($b, $ev->getNewState()); }else{ break; } } $this->age = 0; $this->getWorld()->setBlock($this, $this); } $item->pop(); return true; } return false; } public function onNearbyBlockChange() : void{ $down = $this->getSide(Facing::DOWN); if($down->isTransparent() and $down->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){ $this->getWorld()->useBreakOn($this); } } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){ if($this->age === 15){ for($y = 1; $y < 3; ++$y){ $b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === BlockLegacyIds::AIR){ $this->getWorld()->setBlock($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK)); break; } } $this->age = 0; $this->getWorld()->setBlock($this, $this); }else{ ++$this->age; $this->getWorld()->setBlock($this, $this); } } } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() === BlockLegacyIds::SUGARCANE_BLOCK){ return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); }elseif($down->getId() === BlockLegacyIds::GRASS or $down->getId() === BlockLegacyIds::DIRT or $down->getId() === BlockLegacyIds::SAND){ foreach(Facing::HORIZONTAL as $side){ if($down->getSide($side) instanceof Water){ return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } } } return false; } }