mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Improved biome generation, get grass color from gradient interpolation, improved performance of generation, try to recreate grass colors from imported chunks, closes #2845, closes #1792
This commit is contained in:
@ -73,10 +73,12 @@ 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(){
|
||||
@ -173,9 +175,29 @@ abstract class Biome{
|
||||
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 (randomness|Red|Green|Blue)
|
||||
* @return int (Red|Green|Blue)
|
||||
*/
|
||||
abstract public function getColor();
|
||||
}
|
@ -44,8 +44,8 @@ class BiomeSelector{
|
||||
public function __construct(Random $random, callable $lookup, Biome $fallback){
|
||||
$this->fallback = $fallback;
|
||||
$this->lookup = $lookup;
|
||||
$this->temperature = new Simplex($random, 1, 0.001, 1, 1);
|
||||
$this->rainfall = new Simplex($random, 1, 0.001, 1, 1);
|
||||
$this->temperature = new Simplex($random, 2, 1 / 16, 1 / 512);
|
||||
$this->rainfall = new Simplex($random, 2, 1 / 16, 1 / 512);
|
||||
}
|
||||
|
||||
public function recalculate(){
|
||||
|
Reference in New Issue
Block a user