mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
biomes should be covered in grass now, biome ids are now saved
This commit is contained in:
parent
a5b86aa3ea
commit
3e3bc76ae0
10 changed files with 146 additions and 23 deletions
|
|
@ -112,7 +112,7 @@ class Level{
|
|||
$orderedData = "";
|
||||
$orderedSkyLight = ""; //str_repeat("\xff", 16*16*64);
|
||||
$orderedLight = ""; //str_repeat("\xff", 16*16*64);
|
||||
$orderedBiomeIds = str_repeat("\x0f", 16*16); //all plains, according to PocketMine 1.4 source
|
||||
$orderedBiomeIds = $this->level->chunkInfo[$this->level->getIndex($X, $Z)][0];
|
||||
$orderedBiomeColors = str_repeat("\x00\x85\xb2\x4a", 256); // also PM 1.4
|
||||
$tileEntities = "";
|
||||
if($gen)$this->level->generateChunk($X, $Z, $this->generator);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,14 @@ require_once("NewLevelGenerator.php");
|
|||
* Thank You <3
|
||||
*/
|
||||
class ExperimentalGenerator implements NewLevelGenerator{
|
||||
|
||||
/**
|
||||
* @var Populator[]
|
||||
*/
|
||||
private $populators = array();
|
||||
/**
|
||||
* @var Populator[]
|
||||
*/
|
||||
private $genPopulators = array();
|
||||
private $level;
|
||||
private $random;
|
||||
private $worldHeight = 65;
|
||||
|
|
@ -73,7 +79,7 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
new OreType(new StoneBlock(5), 12, 16, 0, 128),
|
||||
));
|
||||
$this->populators[] = $ores;
|
||||
|
||||
$this->genPopulators[] = new GroundCover();
|
||||
$trees = new TreePopulator();
|
||||
$trees->setBaseAmount(3);
|
||||
$trees->setRandomAmount(0);
|
||||
|
|
@ -116,7 +122,7 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
$weightSum = 0;
|
||||
|
||||
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
|
||||
|
||||
$this->level->level->setBiomeId(($chunkX << 4) + $x, ($chunkZ << 4) + $z, $biome->getID());
|
||||
for($sx = -ExperimentalGenerator::$SMOOTH_SIZE; $sx <= ExperimentalGenerator::$SMOOTH_SIZE; ++$sx){
|
||||
for($sz = -ExperimentalGenerator::$SMOOTH_SIZE; $sz <= ExperimentalGenerator::$SMOOTH_SIZE; ++$sz){
|
||||
$weight = ExperimentalGenerator::$GAUSSIAN_KERNEL[$sx + ExperimentalGenerator::$SMOOTH_SIZE][$sz + ExperimentalGenerator::$SMOOTH_SIZE];
|
||||
|
|
@ -138,7 +144,6 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
$weightSum += $weight;
|
||||
}
|
||||
}
|
||||
|
||||
$minSum /= $weightSum;
|
||||
$maxSum /= $weightSum;
|
||||
|
||||
|
|
@ -163,13 +168,18 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
//$chunk .= str_repeat("\xff", 16);
|
||||
//$chunk .= str_repeat("\xff", 16);
|
||||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //light
|
||||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //more light
|
||||
}
|
||||
}
|
||||
$this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk);
|
||||
}
|
||||
|
||||
foreach($this->genPopulators as $pop){
|
||||
$pop->populate($this->level, $chunkX, $chunkZ, $this->random);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
$base = array();
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$this->level->level->setBiomeId($x + ($chunkX << 4), $z + ($chunkZ << 4), BIOME_PLAINS);
|
||||
$i = ($z << 4) + $x;
|
||||
$hills[$i] = $this->noiseHills->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 0.11, 12, true);
|
||||
$patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true);
|
||||
|
|
@ -79,7 +80,6 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
||||
$chunk = "";
|
||||
$startY = $chunkY << 4;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
abstract class Biome{
|
||||
protected $id, $topBlock, $fillerBlock, $name, $minY, $maxY;
|
||||
protected $id, $topBlocks, $fillerBlock, $name, $minY, $maxY;
|
||||
public function __construct($id, $name){
|
||||
$this->name = $name;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function setTopBlock($id){
|
||||
$this->topBlock = $id;
|
||||
public function setTopBlocks($id){
|
||||
$this->topBlocks = $id;
|
||||
}
|
||||
|
||||
public function getID(){
|
||||
|
|
@ -24,6 +24,10 @@ abstract class Biome{
|
|||
return $this->minY;
|
||||
}
|
||||
|
||||
public function getTopBlocks(){
|
||||
return $this->topBlocks;
|
||||
}
|
||||
|
||||
public function getMax(){
|
||||
return $this->maxY;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@ class BiomeSelector
|
|||
ConsoleAPI::debug("Registered $b");
|
||||
self::$biomes[$b->getID()] = $b;
|
||||
}
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Biome | false
|
||||
*/
|
||||
public static function get($id){
|
||||
return nullsafe(self::$biomes[$id], false);
|
||||
}
|
||||
|
||||
public function generateBiomeLookup(){
|
||||
for($t = 0; $t < 64; ++$t){
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class BiomeExtremeHills extends Biome{
|
||||
class BiomeExtremeHills extends BiomeWithGrass{
|
||||
public function __construct($id, $name){
|
||||
parent::__construct($id, $name);
|
||||
$this->setMinMax(63, 127);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,13 @@ class BiomeWithGrass extends Biome
|
|||
{
|
||||
public function __construct($id, $name){
|
||||
parent::__construct($id, $name);
|
||||
$this->setTopBlock(GRASS);
|
||||
$this->setTopBlocks([
|
||||
[GRASS, 0],
|
||||
[DIRT, 0],
|
||||
[DIRT, 0],
|
||||
[DIRT, 0],
|
||||
[DIRT, 0],
|
||||
]);
|
||||
$this->setFillerBlock(STONE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
src/world/generator/populator/GroundCover.php
Normal file
55
src/world/generator/populator/GroundCover.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
class GroundCover extends Populator
|
||||
{
|
||||
public function populate(Level $level, $chunkX, $chunkZ, Random $random)
|
||||
{
|
||||
console("gcpop: $chunkX $chunkZ");
|
||||
$waterHeight = 0; //TODO
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$pcx = ($chunkX << 4) + $x;
|
||||
$pcz = ($chunkZ << 4) + $z;
|
||||
$biome = BiomeSelector::get($level->level->getBiomeId($pcx, $pcz));
|
||||
$cover = $biome->getTopBlocks();
|
||||
if(count($cover) > 0){
|
||||
$diffY = 0;
|
||||
|
||||
if(!BlockAPI::get($cover[0][0], $cover[0][1])->isSolid){
|
||||
$diffY = 1;
|
||||
}
|
||||
|
||||
$column = $level->level->getBlockIDsXZ($pcx, $pcz);
|
||||
for($y = 127; $y > 0; --$y){
|
||||
$chunkY = $y >> 4;
|
||||
$b = $column[$chunkY][(($y & 0xf) + ($x << 6) + ($z << 10))];
|
||||
if($b !== "\x00" and !BlockAPI::get(ord($b))->isTransparent){
|
||||
break;
|
||||
}
|
||||
}
|
||||
$startY = min(127, $y + $diffY);
|
||||
$endY = $startY - count($cover);
|
||||
for($y = $startY; $y > $endY and $y >= 0; --$y){
|
||||
$chunkY = $y >> 4;
|
||||
$pair = $cover[$startY - $y];
|
||||
$b = BlockAPI::get($pair[0], $pair[1]);
|
||||
if($column[$chunkY][(($y & 0xf) + ($x << 6) + ($z << 10))] === "\x00" and $b->isSolid){
|
||||
break;
|
||||
}
|
||||
if($y <= $waterHeight and $b->getID() == GRASS and $level->level->getBlockID($pcx, $y + 1, $pcz) == STILL_WATER){
|
||||
$b = BlockAPI::get(DIRT);
|
||||
}
|
||||
if($b->getMetadata() === 0){
|
||||
$level->level->setBlockId($pcx, $y, $pcz, $b->getID());
|
||||
}else{
|
||||
$level->level->setBlock($pcx, $y, $pcz, $b->getID(), $b->getMetadata());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue