asItem() ]; } public function isAffectedBySilkTouch() : bool{ return true; } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ $world = $this->position->getWorld(); $lightAbove = $world->getFullLightAt($this->position->x, $this->position->y + 1, $this->position->z); if($lightAbove < 4 && $world->getBlockAt($this->position->x, $this->position->y + 1, $this->position->z)->getLightFilter() >= 2){ //grass dies $ev = new BlockSpreadEvent($this, $this, VanillaBlocks::DIRT()); $ev->call(); if(!$ev->isCancelled()){ $world->setBlock($this->position, $ev->getNewState(), false); } }elseif($lightAbove >= 9){ //try grass spread for($i = 0; $i < 4; ++$i){ $x = mt_rand($this->position->x - 1, $this->position->x + 1); $y = mt_rand($this->position->y - 3, $this->position->y + 1); $z = mt_rand($this->position->z - 1, $this->position->z + 1); $b = $world->getBlockAt($x, $y, $z); if( !($b instanceof Dirt) || !$b->getDirtType()->equals(DirtType::NORMAL()) || $world->getFullLightAt($x, $y + 1, $z) < 4 || $world->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 ){ continue; } $ev = new BlockSpreadEvent($b, $this, VanillaBlocks::GRASS()); $ev->call(); if(!$ev->isCancelled()){ $world->setBlock($b->position, $ev->getNewState(), false); } } } } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($face !== Facing::UP){ return false; } $world = $this->position->getWorld(); if($item instanceof Fertilizer){ $item->pop(); TallGrassObject::growGrass($world, $this->position, new Random(mt_rand()), 8, 2); return true; }elseif($item instanceof Hoe){ $item->applyDamage(1); $newBlock = VanillaBlocks::FARMLAND(); $world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); $world->setBlock($this->position, $newBlock); return true; }elseif($item instanceof Shovel && $this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::AIR){ $item->applyDamage(1); $newBlock = VanillaBlocks::GRASS_PATH(); $world->addSound($this->position->add(0.5, 0.5, 0.5), new ItemUseOnBlockSound($newBlock)); $world->setBlock($this->position, $newBlock); return true; } return false; } }