age; } public function readStateFromData(int $id, int $stateMeta) : void{ $this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta, 0, 15); } public function getStateBitmask() : int{ return 0b1111; } public function hasEntityCollision() : bool{ return true; } /** * @return AxisAlignedBB[] */ protected function recalculateCollisionBoxes() : array{ static $shrinkSize = 1 / 16; return [AxisAlignedBB::one()->contract($shrinkSize, 0, $shrinkSize)->trim(Facing::UP, $shrinkSize)]; } public function onEntityInside(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() !== BlockLegacyIds::SAND and !$down->isSameType($this)){ $this->pos->getWorldNonNull()->useBreakOn($this->pos); }else{ foreach(Facing::HORIZONTAL as $side){ $b = $this->getSide($side); if($b->isSolid()){ $this->pos->getWorldNonNull()->useBreakOn($this->pos); break; } } } } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ if(!$this->getSide(Facing::DOWN)->isSameType($this)){ if($this->age === 15){ for($y = 1; $y < 3; ++$y){ $b = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); if($b->getId() === BlockLegacyIds::AIR){ $ev = new BlockGrowEvent($b, VanillaBlocks::CACTUS()); $ev->call(); if($ev->isCancelled()){ break; } $this->pos->getWorldNonNull()->setBlock($b->pos, $ev->getNewState()); }else{ break; } } $this->age = 0; $this->pos->getWorldNonNull()->setBlock($this->pos, $this); }else{ ++$this->age; $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); if($down->getId() === BlockLegacyIds::SAND or $down->isSameType($this)){ foreach(Facing::HORIZONTAL as $side){ if($this->getSide($side)->isSolid()){ return false; } } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; } }