40 private \SplFixedArray $map;
42 public function __construct(
Random $random){
43 $this->temperature =
new Simplex($random, 2, 1 / 16, 1 / 512);
44 $this->rainfall =
new Simplex($random, 2, 1 / 16, 1 / 512);
52 abstract protected function lookup(
float $temperature,
float $rainfall) : int;
54 public function recalculate() : void{
55 $this->map = new \SplFixedArray(64 * 64);
57 $biomeRegistry = BiomeRegistry::getInstance();
58 for($i = 0; $i < 64; ++$i){
59 for($j = 0; $j < 64; ++$j){
60 $biome = $biomeRegistry->getBiome($this->
lookup($i / 63, $j / 63));
62 throw new \RuntimeException(
"Unknown biome returned by selector with ID " . $biome->getId());
64 $this->map[$i + ($j << 6)] = $biome;
69 public function getTemperature(
float $x,
float $z) : float{
70 return ($this->temperature->noise2D($x, $z, true) + 1) / 2;
73 public function getRainfall(
float $x,
float $z) : float{
74 return ($this->rainfall->noise2D($x, $z, true) + 1) / 2;
77 public function pickBiome(
float $x,
float $z) : Biome{
78 $temperature = (int) ($this->getTemperature($x, $z) * 63);
79 $rainfall = (int) ($this->getRainfall($x, $z) * 63);
81 return $this->map[$temperature + ($rainfall << 6)];