public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
{
$this->level = $level;
$amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
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);
$tallRand = $random->nextRange(0, 17);
$yMax = $y + 2 + (int) ($tallRand > 10) + (int) ($tallRand > 15);
if ($y !== -1) {
for (; $y < 127 and $y < $yMax; $y++) {
if ($this->canSugarcaneStay($x, $y, $z)) {
$this->level->setBlockIdAt($x, $y, $z, Block::SUGARCANE_BLOCK);
$this->level->setBlockDataAt($x, $y, $z, 1);
}
}
}
}
}