diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index df447767d..a0cd73e6b 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -65,6 +65,10 @@ class NormalGenerator implements LevelGenerator{ new OreType(new GravelBlock(), 10, 16, 0, 128), )); $this->populators[] = $ores; + $tallGrass = new TallGrassPopulator(); + $tallGrass->setBaseAmount(5); + $tallGrass->setRandomAmount(1); + $this->populators[] = $tallGrass; } public function generateChunk($chunkX, $chunkZ){ @@ -79,6 +83,10 @@ class NormalGenerator implements LevelGenerator{ $patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true); $patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true); $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 16, true); + + if($base[$i] < 0){ + $base[$i] *= 0.5; + } } } diff --git a/src/world/generator/populator/OrePopulator.php b/src/world/generator/populator/OrePopulator.php index 390cbcba7..5ae016ad9 100644 --- a/src/world/generator/populator/OrePopulator.php +++ b/src/world/generator/populator/OrePopulator.php @@ -25,9 +25,9 @@ class OrePopulator extends Populator{ foreach($this->oreTypes as $type){ $ore = new OreObject($random, $type); for($i = 0; $i < $ore->type->clusterCount; ++$i){ - $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16); + $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight); - $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16); + $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); if($ore->canPlaceObject($level, $x, $y, $z)){ $ore->placeObject($level, new Vector3($x, $y, $z)); } diff --git a/src/world/generator/populator/TallGrassPopulator.php b/src/world/generator/populator/TallGrassPopulator.php new file mode 100644 index 000000000..ba37bf59d --- /dev/null +++ b/src/world/generator/populator/TallGrassPopulator.php @@ -0,0 +1,70 @@ +randomAmount = $amount; + } + + public function setBaseAmount($amount){ + $this->baseAmount = $amount; + } + + public function populate(Level $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 << 4, ($chunkX << 4) + 15); + $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); + for($size = 30; $size > 0; --$size){ + $xx = $x - 7 + $random->nextRange(0, 15); + $zz = $z - 7 + $random->nextRange(0, 15); + $yy = $this->getHighestWorkableBlock($xx, $zz); + $vector = new Vector3($xx, $yy, $zz); + if($yy !== -1 and $this->canTallGrassStay($this->level->getBlockRaw($vector))){ + $this->level->setBlockRaw($vector, new TallGrassBlock(1)); + } + } + } + } + + private function canTallGrassStay(Block $block){ + return $block->getID() === AIR and $block->getSide(0)->getID() === GRASS; + } + + private function getHighestWorkableBlock($x, $z){ + for($y = 128; $y > 0; --$y){ + $b = $this->level->getBlockRaw(new Vector3($x, $y, $z)); + if($b->getID() === AIR or $b->getID() === LEAVES){ + if(--$y <= 0){ + return -1; + } + }else{ + break; + } + } + return ++$y; + } +} \ No newline at end of file