From e0522d8b1a09161ccf04f34c5ec34943b594cebe Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 27 Mar 2015 12:42:59 +0100 Subject: [PATCH] Fixed data on generation, biome gradient --- src/pocketmine/Player.php | 6 +-- src/pocketmine/level/Level.php | 7 +--- src/pocketmine/level/SimpleChunkManager.php | 2 +- .../level/generator/normal/Normal.php | 37 +++++++++++++------ 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8f46523b1..cea6bf876 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -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; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index a8a92c777..20126082b 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -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){ diff --git a/src/pocketmine/level/SimpleChunkManager.php b/src/pocketmine/level/SimpleChunkManager.php index d1dab2b34..7375bd7a6 100644 --- a/src/pocketmine/level/SimpleChunkManager.php +++ b/src/pocketmine/level/SimpleChunkManager.php @@ -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); } } diff --git a/src/pocketmine/level/generator/normal/Normal.php b/src/pocketmine/level/generator/normal/Normal.php index 3641a8bcb..c24c61593 100644 --- a/src/pocketmine/level/generator/normal/Normal.php +++ b/src/pocketmine/level/generator/normal/Normal.php @@ -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);