Remove biome colours and fix biome id arrays

This commit is contained in:
Dylan K. Taylor
2016-12-04 14:04:36 +00:00
parent 4d121f7d84
commit aafe0c4f69
9 changed files with 58 additions and 140 deletions

View File

@ -111,15 +111,10 @@ class Flat extends Generator{
$this->chunk = clone $this->level->getChunk($chunkX, $chunkZ);
$this->chunk->setGenerated();
$c = Biome::getBiome($biome)->getColor();
$R = $c >> 16;
$G = ($c >> 8) & 0xff;
$B = $c & 0xff;
for($Z = 0; $Z < 16; ++$Z){
for($X = 0; $X < 16; ++$X){
$this->chunk->setBiomeId($X, $Z, $biome);
$this->chunk->setBiomeColor($X, $Z, $R, $G, $B);
for($y = 0; $y < 128; ++$y){
$this->chunk->setBlock($X, $y, $Z, ...$this->structure[$y]);
}

View File

@ -75,12 +75,10 @@ abstract class Biome{
protected $rainfall = 0.5;
protected $temperature = 0.5;
protected $grassColor = 0;
protected static function register($id, Biome $biome){
self::$biomes[(int) $id] = $biome;
$biome->setId((int) $id);
$biome->grassColor = self::generateBiomeColor($biome->getTemperature(), $biome->getRainfall());
}
public static function init(){
@ -175,30 +173,4 @@ abstract class Biome{
public function getRainfall(){
return $this->rainfall;
}
private static function generateBiomeColor($temperature, $rainfall){
$x = (1 - $temperature) * 255;
$z = (1 - $rainfall * $temperature) * 255;
$c = self::interpolateColor(256, $x, $z, [0x47, 0xd0, 0x33], [0x6c, 0xb4, 0x93], [0xbf, 0xb6, 0x55], [0x80, 0xb4, 0x97]);
return ((int) ($c[0] << 16)) | (int) (($c[1] << 8)) | (int) ($c[2]);
}
private static function interpolateColor($size, $x, $z, $c1, $c2, $c3, $c4){
$l1 = self::lerpColor($c1, $c2, $x / $size);
$l2 = self::lerpColor($c3, $c4, $x / $size);
return self::lerpColor($l1, $l2, $z / $size);
}
private static function lerpColor($a, $b, $s){
$invs = 1 - $s;
return [$a[0] * $invs + $b[0] * $s, $a[1] * $invs + $b[1] * $s, $a[2] * $invs + $b[2] * $s];
}
/**
* @return int (Red|Green|Blue)
*/
abstract public function getColor();
}

View File

@ -120,13 +120,6 @@ class Nether extends Generator{
$biome = Biome::getBiome(Biome::HELL);
$chunk->setBiomeId($x, $z, $biome->getId());
$color = [0, 0, 0];
$bColor = $biome->getColor();
$color[0] += (($bColor >> 16) ** 2);
$color[1] += ((($bColor >> 8) & 0xff) ** 2);
$color[2] += (($bColor & 0xff) ** 2);
$chunk->setBiomeColor($x, $z, $color[0], $color[1], $color[2]);
for($y = 0; $y < 128; ++$y){
if($y === 0 or $y === 127){

View File

@ -201,7 +201,6 @@ class Normal extends Generator{
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
$chunk->setBiomeId($x, $z, $biome->getId());
$color = [0, 0, 0];
for($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx){
for($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz){
@ -221,10 +220,6 @@ class Normal extends Generator{
$minSum += ($adjacent->getMinElevation() - 1) * $weight;
$maxSum += $adjacent->getMaxElevation() * $weight;
$bColor = $adjacent->getColor();
$color[0] += (($bColor >> 16) ** 2) * $weight;
$color[1] += ((($bColor >> 8) & 0xff) ** 2) * $weight;
$color[2] += (($bColor & 0xff) ** 2) * $weight;
$weightSum += $weight;
}
@ -233,8 +228,6 @@ class Normal extends Generator{
$minSum /= $weightSum;
$maxSum /= $weightSum;
$chunk->setBiomeColor($x, $z, sqrt($color[0] / $weightSum), sqrt($color[1] / $weightSum), sqrt($color[2] / $weightSum));
$smoothHeight = ($maxSum - $minSum) / 2;
for($y = 0; $y < 128; ++$y){