age; } public function readStateFromMeta(int $meta) : void{ $this->age = $meta; } public function getStateBitmask() : int{ return 0b1111; } public function getHardness() : float{ return 0.4; } public function hasEntityCollision() : bool{ return true; } public function getName() : string{ return "Cactus"; } protected function recalculateBoundingBox() : ?AxisAlignedBB{ static $shrinkSize = 0.0625; return new AxisAlignedBB($shrinkSize, $shrinkSize, $shrinkSize, 1 - $shrinkSize, 1 - $shrinkSize, 1 - $shrinkSize); } public function onEntityCollide(Entity $entity) : void{ $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); $entity->attack($ev); } public function onNearbyBlockChange() : void{ $down = $this->getSide(Facing::DOWN); if($down->getId() !== self::SAND and $down->getId() !== self::CACTUS){ $this->getLevel()->useBreakOn($this); }else{ foreach(Facing::HORIZONTAL as $side){ $b = $this->getSide($side); if($b->isSolid()){ $this->getLevel()->useBreakOn($this); break; } } } } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ if($this->getSide(Facing::DOWN)->getId() !== self::CACTUS){ if($this->age === 15){ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === self::AIR){ $ev = new BlockGrowEvent($b, BlockFactory::get(Block::CACTUS)); $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($b, $ev->getNewState()); } } } $this->age = 0; $this->getLevel()->setBlock($this, $this); }else{ ++$this->age; $this->getLevel()->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() === self::SAND or $down->getId() === self::CACTUS){ foreach(Facing::HORIZONTAL as $side){ if($this->getSide($side)->isSolid()){ return false; } } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; } }