randomAmount = $amount; } public function setBaseAmount(int $amount) : void{ $this->baseAmount = $amount; } public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random) : void{ $this->level = $level; $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; $block = BlockFactory::get(Block::TALL_GRASS, 1); for($i = 0; $i < $amount; ++$i){ $x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15); $z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15); $y = $this->getHighestWorkableBlock($x, $z); if($y !== -1 and $this->canTallGrassStay($x, $y, $z)){ $this->level->setBlockAt($x, $y, $z, $block); } } } private function canTallGrassStay(int $x, int $y, int $z) : bool{ $b = $this->level->getBlockAt($x, $y, $z)->getId(); return ($b === Block::AIR or $b === Block::SNOW_LAYER) and $this->level->getBlockAt($x, $y - 1, $z)->getId() === Block::GRASS; } private function getHighestWorkableBlock(int $x, int $z) : int{ for($y = 127; $y >= 0; --$y){ $b = $this->level->getBlockAt($x, $y, $z)->getId(); if($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2 and $b !== Block::SNOW_LAYER){ break; } } return $y === 0 ? -1 : ++$y; } }