level = $level; $amount = $this->getAmount($random); 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 && $level->getBlockIdAt($x, $y - 1, $z ) == Block::SAND) { $level->setBlockIdAt($x, $y + 1, $z, Block::DEAD_BUSH); $level->setBlockDataAt($x, $y + 1, $z, 1); } } } /* * Gets the top block (y) on an x and z axes * @param $x int * @param $z int */ protected function getHighestWorkableBlock($x, $z) { for($y = Level::Y_MAX; $y >= 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) { break; } } return $y === 0 ? - 1 : ++$y; } }