mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
biomez
This commit is contained in:
parent
b6da664236
commit
eaa5390879
6 changed files with 134 additions and 83 deletions
|
|
@ -138,7 +138,6 @@ class Level{
|
|||
}
|
||||
}
|
||||
$chunkTiles = [];
|
||||
console(strlen($orderedLight));
|
||||
$tiles = $this->server->query("SELECT ID FROM tiles WHERE spawnable = 1 AND level = '".$this->getName()."' AND x >= ".($X * 16 - 1)." AND x < ".($X * 16 + 17)." AND z >= ".($Z * 16 - 1)." AND z < ".($Z * 16 + 17).";");
|
||||
if($tiles !== false and $tiles !== true){
|
||||
while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
$this->noisePatches = new NoiseGeneratorSimplex($this->random, 2);
|
||||
$this->noisePatchesSmall = new NoiseGeneratorSimplex($this->random, 2);
|
||||
$this->noiseBase = new NoiseGeneratorPerlin($this->random, 4);
|
||||
|
||||
$this->selector = new BiomeSelector($this->random, BiomeSelector::$biomes[BIOME_PLAINS]);
|
||||
$ores = new OrePopulator();
|
||||
$ores->setOreTypes(array(
|
||||
new OreType(new CoalOreBlock(), 20, 16, 0, 128),
|
||||
|
|
@ -85,10 +85,25 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
//$this->populators[] = $tallGrass;
|
||||
}
|
||||
|
||||
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 generateChunk($chunkX, $chunkZ){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
$noiseArray = ExperimentalGenerator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
|
||||
|
||||
$biomeCache = [];
|
||||
|
||||
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
||||
$chunk = "";
|
||||
|
|
@ -99,23 +114,26 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
$minSum = 0;
|
||||
$maxSum = 0;
|
||||
$weightSum = 0;
|
||||
|
||||
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
|
||||
|
||||
for($sx = -ExperimentalGenerator::$SMOOTH_SIZE; $sx <= ExperimentalGenerator::$SMOOTH_SIZE; ++$sx){
|
||||
for($sz = -ExperimentalGenerator::$SMOOTH_SIZE; $sz <= ExperimentalGenerator::$SMOOTH_SIZE; ++$sz){
|
||||
$weight = ExperimentalGenerator::$GAUSSIAN_KERNEL[$sx + ExperimentalGenerator::$SMOOTH_SIZE][$sz + ExperimentalGenerator::$SMOOTH_SIZE];
|
||||
|
||||
/*if($sx === 0 and $sz === 0){
|
||||
$adjacent = $biome;
|
||||
}else{
|
||||
$index = Level::chunkHash($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
|
||||
if(isset($biomeCache[$index])){
|
||||
$adjacent = $biomeCache[$index];
|
||||
}else{
|
||||
$biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
|
||||
}
|
||||
}*/
|
||||
if($sx === 0 and $sz === 0){
|
||||
$adjacent = $biome;
|
||||
}else{
|
||||
$index = ($chunkX * 16 + $x + $sx).":".($chunkZ * 16 + $z + $sz);
|
||||
if(isset($biomeCache[$index])){
|
||||
$adjacent = $biomeCache[$index];
|
||||
}else{
|
||||
$biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
|
||||
}
|
||||
}
|
||||
|
||||
$minSum += (63 - 1) * $weight; //TODO biomes
|
||||
$maxSum += 127 * $weight;
|
||||
$minSum += ($adjacent->getMin() - 1) * $weight; //TODO biomes
|
||||
$maxSum += $adjacent->getMax() * $weight;
|
||||
|
||||
$weightSum += $weight;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,51 @@
|
|||
<?php
|
||||
|
||||
abstract class Biome{
|
||||
protected $topBlock, $fillerBlock;
|
||||
protected $id, $topBlock, $fillerBlock, $name, $minY, $maxY;
|
||||
public function __construct($id, $name){
|
||||
$this->name = $name;
|
||||
self::$biomes[$id] = $this;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function setTopBlock($id){
|
||||
$this->topBlock = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getID(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setMinMax($min, $max){
|
||||
$this->minY = $min;
|
||||
$this->maxY = $max;
|
||||
}
|
||||
|
||||
public function getMin(){
|
||||
return $this->minY;
|
||||
}
|
||||
|
||||
public function getMax(){
|
||||
return $this->maxY;
|
||||
}
|
||||
|
||||
public function setFillerBlock($id){
|
||||
$this->fillerBlock = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBiomeAt($x, $z){
|
||||
self::$biomeLookup[$x + $z * 64];
|
||||
}
|
||||
|
||||
|
||||
public static function init(){
|
||||
//register biomes
|
||||
}
|
||||
|
||||
public static $temperature, $rainfall;
|
||||
private static $biomeLookup = [];
|
||||
public static $biomes = [];
|
||||
}
|
||||
public function __toString(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public static function init(){
|
||||
BiomeSelector::registerBiome(new BiomeExtremeHills(BIOME_EXTREME_HILLS, "Extreme Hills"));
|
||||
BiomeSelector::registerBiome(new BiomePlains(BIOME_PLAINS, "Plains"));
|
||||
}
|
||||
|
||||
private static $initialized = false;
|
||||
public static $temperature, $rainfall;
|
||||
public static $biomes = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,41 +11,56 @@ class BiomeSelector
|
|||
private $rainfall;
|
||||
|
||||
/** @var Biome[] */
|
||||
private $biomes = [];
|
||||
public static $biomes = [];
|
||||
|
||||
private $map;
|
||||
private $map = [];
|
||||
|
||||
private $lookup;
|
||||
|
||||
public function __construct(Random $random, callable $lookup, Biome $fallback){
|
||||
public function __construct(Random $random, Biome $fallback){
|
||||
$this->fallback = $fallback;
|
||||
$this->lookup = $lookup;
|
||||
$this->temperature = new NoiseGeneratorSimplex($random, 2);
|
||||
$this->rainfall = new NoiseGeneratorSimplex($random, 2);
|
||||
$this->generateBiomeLookup();
|
||||
}
|
||||
|
||||
public static function registerBiome(Biome $b){
|
||||
ConsoleAPI::debug("Registered $b");
|
||||
self::$biomes[$b->getID()] = $b;
|
||||
}
|
||||
|
||||
public function generateBiomeLookup(){
|
||||
$this->map = new SplFixedArray(64 * 64);
|
||||
for($t = 0; $t < 64; ++$t){
|
||||
for($r = 0; $r < 64; ++$r){
|
||||
$this->map[$t + $r << 6] = call_user_func($this->lookup, $t / 63, $r / 63);
|
||||
$this->map[$t + ($r << 6)] = $this->getBiomeTR($t / 63, $r / 63);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getBiomeTR($t, $r){
|
||||
if($r < 0.60){
|
||||
return BIOME_PLAINS;
|
||||
}else{
|
||||
if($t < 0.70){
|
||||
return BIOME_EXTREME_HILLS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTemperature($x, $z){ //TODO cache
|
||||
return ($this->temperature->noise2D($x, $z, 1 / 16, 1 / 512, true) + 1) / 2;
|
||||
return ($this->temperature->noise2D($x * (1/512), $z * (1/512), 2, 1 / 16, true) + 1) / 2;
|
||||
}
|
||||
|
||||
public function getRainfall($x, $z){
|
||||
return ($this->rainfall->noise2D($x, $z, 1 / 16, 1 / 512, true) + 1) / 2;
|
||||
return ($this->rainfall->noise2D($x * (1/512), $z * (1/512), 2, 1 / 16, true) + 1) / 2;
|
||||
}
|
||||
|
||||
public function getBiome($x, $z){
|
||||
public function pickBiome($x, $z){
|
||||
$temperature = (int) ($this->getTemperature($x, $z) * 63);
|
||||
$rainfall = (int) ($this->getRainfall($x, $z) * 63);
|
||||
|
||||
$biomeId = $this->map[$temperature + ($rainfall << 6)];
|
||||
return isset($this->biomes[$biomeId]) ? $this->biomes[$biomeId] : $this->fallback;
|
||||
|
||||
$biomeId = nullsafe($this->map[$temperature + ($rainfall << 6)], -1);
|
||||
return nullsafe(self::$biomes[$biomeId], $this->fallback);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue