Fixed data on generation, biome gradient

This commit is contained in:
Shoghi Cervantes 2015-03-27 12:42:59 +01:00
parent 08f2b7f291
commit e0522d8b1a
4 changed files with 29 additions and 23 deletions

View File

@ -595,11 +595,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
Level::getXZ($index, $X, $Z);
if(!$this->level->populateChunk($X, $Z)){
if($this->spawned){
continue;
}else{
break;
}
continue;
}

View File

@ -2295,7 +2295,7 @@ class Level implements ChunkManager, Metadatable{
public function populateChunk($x, $z, $force = false){
if(isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)])){
if(isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)]) or (count($this->chunkPopulationQueue) >= $this->chunkPopulationQueueSize and !$force)){
return false;
}
@ -2314,11 +2314,6 @@ class Level implements ChunkManager, Metadatable{
}
if($populate){
if(count($this->chunkPopulationQueue) >= $this->chunkPopulationQueueSize and !$force){
Timings::$generationTimer->stopTiming();
return false;
}
if(!isset($this->chunkPopulationQueue[$index])){
$this->chunkPopulationQueue[$index] = true;
for($xx = -1; $xx <= 1; ++$xx){

View File

@ -90,7 +90,7 @@ class SimpleChunkManager implements ChunkManager{
*/
public function setBlockDataAt($x, $y, $z, $data){
if($chunk = $this->getChunk($x >> 4, $z >> 4)){
$chunk->getBlockData($x & 0xf, $y & 0x7f, $z & 0xf, $data);
$chunk->setBlockData($x & 0xf, $y & 0x7f, $z & 0xf, $data);
}
}

View File

@ -80,6 +80,7 @@ class Normal extends Generator{
private static function generateKernel(){
self::$GAUSSIAN_KERNEL = [];
for($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx){
self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE] = [];
for($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz){
self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE] = 10 / sqrt($sx ** 2 + $sz ** 2 + 0.2);
}
@ -94,11 +95,26 @@ class Normal extends Generator{
return [];
}
public function pickBiome($x, $z){
$hash = $x * 2345803 ^ $z * 9236449 ^ $this->level->getSeed();
$hash *= $hash + 223;
$xNoise = $hash >> 20 & 3;
$zNoise = $hash >> 22 & 3;
if ($xNoise == 3) {
$xNoise = 1;
}
if($zNoise == 3) {
$zNoise = 1;
}
return $this->selector->pickBiome($x + $xNoise - 1, $z + $zNoise - 1);
}
public function init(ChunkManager $level, Random $random){
$this->level = $level;
$this->random = $random;
$this->random->setSeed($this->level->getSeed());
$this->noiseBase = new Simplex($this->random, 16, 0.015, 0.5, 2);
$this->noiseBase = new Simplex($this->random, 16, 0.01, 0.5, 2);
$this->random->setSeed($this->level->getSeed());
$this->selector = new BiomeSelector($this->random, function($temperature, $rainfall){
$rainfall *= $temperature;
@ -185,19 +201,16 @@ class Normal extends Generator{
$maxSum = 0;
$weightSum = 0;
$biome = $this->selector->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
$chunk->setBiomeId($x, $z, $biome->getId());
$color = $biome->getColor();
$chunk->setBiomeColor($x, $z, $color >> 16, ($color >> 8) & 0xff, $color & 0xff);
for($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx){
for($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz){
if($sx === 0 and $sz === 0){
continue;
}else{
$adjacent = $this->selector->pickBiome(($chunkX + $sx) * 16 + $x, ($chunkZ + $sz) * 16 + $z);
}
$weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE] / ($biome->getMaxElevation() / 128 + 2);
$adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
$weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE] / (($biome->getMaxElevation() - $this->waterHeight) / $this->waterHeight + 2);
if($adjacent->getMaxElevation() > $biome->getMaxElevation()){
$weight /= 2;
}
@ -207,15 +220,17 @@ class Normal extends Generator{
}
}
$minElevation = $minSum / $weightSum;
$smoothHeight = ($maxSum / $weightSum - $minElevation) / 2;
$minSum /= $weightSum;
$maxSum /= $weightSum;
$smoothHeight = ($maxSum - $minSum) / 2;
for($y = 0; $y < 128; ++$y){
if($y === 0){
$chunk->setBlockId($x, $y, $z, Block::BEDROCK);
continue;
}
$noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minElevation);
$noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum);
if($noiseValue >= 0){
$chunk->setBlockId($x, $y, $z, Block::STONE);