34 private int $randomAmount = 1;
35 private int $baseAmount = 0;
37 public function setRandomAmount(
int $amount) :
void{
38 $this->randomAmount = $amount;
41 public function setBaseAmount(
int $amount) :
void{
42 $this->baseAmount = $amount;
45 public function populate(
ChunkManager $world,
int $chunkX,
int $chunkZ,
Random $random) :
void{
46 $amount = $random->
nextRange(0, $this->randomAmount) + $this->baseAmount;
48 $block = VanillaBlocks::TALL_GRASS();
49 for($i = 0; $i < $amount; ++$i){
50 $x = $random->
nextRange($chunkX * Chunk::EDGE_LENGTH, $chunkX * Chunk::EDGE_LENGTH + (Chunk::EDGE_LENGTH - 1));
51 $z = $random->
nextRange($chunkZ * Chunk::EDGE_LENGTH, $chunkZ * Chunk::EDGE_LENGTH + (Chunk::EDGE_LENGTH - 1));
52 $y = $this->getHighestWorkableBlock($world, $x, $z);
54 if($y !== -1 && $this->canTallGrassStay($world, $x, $y, $z)){
60 private function canTallGrassStay(
ChunkManager $world,
int $x,
int $y,
int $z) :
bool{
61 $b = $world->
getBlockAt($x, $y, $z)->getTypeId();
62 return ($b === BlockTypeIds::AIR || $b === BlockTypeIds::SNOW_LAYER) && $world->
getBlockAt($x, $y - 1, $z)->getTypeId() === BlockTypeIds::GRASS;
65 private function getHighestWorkableBlock(
ChunkManager $world,
int $x,
int $z) :
int{
66 for($y = 127; $y >= 0; --$y){
68 if($b->getTypeId() !== BlockTypeIds::AIR && !($b instanceof
Leaves) && $b->getTypeId() !== BlockTypeIds::SNOW_LAYER){