mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
World generation with biomes!
This commit is contained in:
@ -23,14 +23,16 @@ namespace pocketmine\level\generator\biome;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\level\generator\normal\biome\BeachBiome;
|
||||
use pocketmine\level\generator\normal\biome\SwampBiome;
|
||||
use pocketmine\level\generator\normal\biome\DesertBiome;
|
||||
use pocketmine\level\generator\normal\biome\ForestBiome;
|
||||
use pocketmine\level\generator\normal\biome\IcePlainsBiome;
|
||||
use pocketmine\level\generator\normal\biome\MountainsBiome;
|
||||
use pocketmine\level\generator\normal\biome\OceanBiome;
|
||||
use pocketmine\level\generator\normal\biome\PlainBiome;
|
||||
use pocketmine\level\generator\normal\biome\RiverBiome;
|
||||
use pocketmine\level\generator\normal\biome\SmallMountainsBiome;
|
||||
use pocketmine\level\generator\normal\biome\TaigaBiome;
|
||||
use pocketmine\level\generator\populator\Populator;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
@ -41,14 +43,19 @@ abstract class Biome{
|
||||
const DESERT = 2;
|
||||
const MOUNTAINS = 3;
|
||||
const FOREST = 4;
|
||||
|
||||
const TAIGA = 5;
|
||||
const SWAMP = 6;
|
||||
const RIVER = 7;
|
||||
|
||||
const BEACH = 16;
|
||||
const ICE_PLAINS = 12;
|
||||
|
||||
|
||||
const SMALL_MOUNTAINS = 20;
|
||||
|
||||
|
||||
const BIRCH_FOREST = 27;
|
||||
|
||||
|
||||
const MAX_BIOMES = 256;
|
||||
|
||||
/** @var Biome[] */
|
||||
@ -64,6 +71,9 @@ abstract class Biome{
|
||||
|
||||
private $groundCover = [];
|
||||
|
||||
protected $rainfall = 0.5;
|
||||
protected $temperature = 0.5;
|
||||
|
||||
protected static function register($id, Biome $biome){
|
||||
self::$biomes[(int) $id] = $biome;
|
||||
$biome->setId((int) $id);
|
||||
@ -75,12 +85,17 @@ abstract class Biome{
|
||||
self::register(self::DESERT, new DesertBiome());
|
||||
self::register(self::MOUNTAINS, new MountainsBiome());
|
||||
self::register(self::FOREST, new ForestBiome());
|
||||
self::register(self::TAIGA, new TaigaBiome());
|
||||
|
||||
self::register(self::RIVER, new RiverBiome());
|
||||
|
||||
self::register(self::BEACH, new BeachBiome());
|
||||
self::register(self::ICE_PLAINS, new IcePlainsBiome());
|
||||
|
||||
self::register(self::SWAMP, new SwampBiome());
|
||||
|
||||
self::register(self::SMALL_MOUNTAINS, new SmallMountainsBiome());
|
||||
|
||||
self::register(self::BIRCH_FOREST, new ForestBiome(ForestBiome::TYPE_BIRCH));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +104,7 @@ abstract class Biome{
|
||||
* @return Biome
|
||||
*/
|
||||
public static function getBiome($id){
|
||||
return isset(self::$biomes[$id]) ? self::$biomes[$id] : null;
|
||||
return isset(self::$biomes[$id]) ? self::$biomes[$id] : self::$biomes[self::OCEAN];
|
||||
}
|
||||
|
||||
public function clearPopulators(){
|
||||
@ -149,4 +164,18 @@ abstract class Biome{
|
||||
public function setGroundCover(array $covers){
|
||||
$this->groundCover = $covers;
|
||||
}
|
||||
|
||||
public function getTemperature(){
|
||||
return $this->temperature;
|
||||
}
|
||||
|
||||
public function getRainfall(){
|
||||
return $this->rainfall;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int (randomness|Red|Green|Blue)
|
||||
*/
|
||||
abstract public function getColor();
|
||||
}
|
@ -37,17 +37,37 @@ class BiomeSelector{
|
||||
/** @var Biome[] */
|
||||
private $biomes = [];
|
||||
|
||||
private $select = [];
|
||||
private $map = [];
|
||||
|
||||
public function __construct(Random $random, Biome $fallback){
|
||||
private $lookup;
|
||||
|
||||
public function __construct(Random $random, callable $lookup, Biome $fallback){
|
||||
$this->fallback = $fallback;
|
||||
$this->temperature = new Simplex($random, 1, 0.004, 0.5, 2);
|
||||
$this->rainfall = new Simplex($random, 2, 0.004, 0.5, 2);
|
||||
$this->lookup = $lookup;
|
||||
$this->temperature = new Simplex($random, 1, 0.001, 1, 1);
|
||||
$this->rainfall = new Simplex($random, 1, 0.001, 1, 1);
|
||||
}
|
||||
|
||||
public function addBiome(Biome $biome, $start, $end){
|
||||
public function recalculate(){
|
||||
$this->map = new \SplFixedArray(64 * 64);
|
||||
|
||||
for($i = 0; $i < 64; ++$i){
|
||||
for($j = 0; $j < 64; ++$j){
|
||||
$this->map[$i + ($j << 6)] = call_user_func($this->lookup, $i / 63, $j / 63);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function addBiome(Biome $biome){
|
||||
$this->biomes[$biome->getId()] = $biome;
|
||||
$this->select[$biome->getId()] = [$biome->getId(), $start, $end];
|
||||
}
|
||||
|
||||
public function getTemperature($x, $z){
|
||||
return ($this->temperature->noise2D($x, $z, true) + 1) / 2;
|
||||
}
|
||||
|
||||
public function getRainfall($x, $z){
|
||||
return ($this->rainfall->noise2D($x, $z, true) + 1) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,27 +77,10 @@ class BiomeSelector{
|
||||
* @return Biome
|
||||
*/
|
||||
public function pickBiome($x, $z){
|
||||
$temperature = (int) ($this->getTemperature($x, $z) * 63);
|
||||
$rainfall = (int) ($this->getRainfall($x, $z) * 63);
|
||||
|
||||
//$temperature = $this->temperature->noise2D($x, $z);
|
||||
$rainfall = $this->rainfall->noise2D($x, $z);
|
||||
|
||||
if($rainfall > 0.9){
|
||||
return Biome::getBiome(Biome::OCEAN);
|
||||
}elseif($rainfall > 0.7){
|
||||
return Biome::getBiome(Biome::RIVER);
|
||||
}elseif($rainfall > 0.6){
|
||||
return Biome::getBiome(Biome::BEACH);
|
||||
}elseif($rainfall > 0.2){
|
||||
return Biome::getBiome(Biome::FOREST);
|
||||
}elseif($rainfall > -0.3){
|
||||
return Biome::getBiome(Biome::PLAINS);
|
||||
}elseif($rainfall > -0.6){
|
||||
return Biome::getBiome(Biome::DESERT);
|
||||
}elseif($rainfall > -0.7){
|
||||
return Biome::getBiome(Biome::BEACH);
|
||||
}else{
|
||||
return Biome::getBiome(Biome::OCEAN);
|
||||
}
|
||||
|
||||
$biomeId = $this->map[$temperature + ($rainfall << 6)];
|
||||
return isset($this->biomes[$biomeId]) ? $this->biomes[$biomeId] : $this->fallback;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user