This commit is contained in:
GameHerobrine 2023-03-07 14:35:31 +03:00
parent b6da664236
commit eaa5390879
6 changed files with 134 additions and 83 deletions

View file

@ -134,7 +134,7 @@ class ServerAPI{
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
"auto-save" => true,
]);
Biome::init();
$this->parseProperties();
MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50);
//Load advanced properties

View file

@ -1,50 +1,50 @@
<?php
//0.9.5 adds 2 new biomes, ExtremeHills+ and JungleM(Modified Jungle)
define("OCEAN", 0);
define("PLAINS", 1);
define("DESERT", 2);
define("EXTREME_HILLS", 3); //extreme_hills
define("FOREST", 4);
define("TAIGA", 5);
define("SWAMP", 6);
define("RIVER", 7);
define("HELL", 8); //yes it is a biome in 0.9
define("BIOME_OCEAN", 0);
define("BIOME_PLAINS", 1);
define("BIOME_DESERT", 2);
define("BIOME_EXTREME_HILLS", 3); //extreme_hills
define("BIOME_FOREST", 4);
define("BIOME_TAIGA", 5);
define("BIOME_SWAMP", 6);
define("BIOME_RIVER", 7);
define("BIOME_HELL", 8); //yes it is a biome in 0.9
//id 9 found, not sure about name, maybe sky
define("FROZEN_OCEAN", 10);
define("FROZEN_RIVER", 11);
define("ICE_PLAINS", 12);
define("ICE_MOUNTAINS", 13); //snow covered, temp&fall->0.0, 0.5
define("MUSHROOM_ISLAND", 14);
define("MUSHROOM_ISLAND_SHORE", 15);
define("BEACH", 16);
define("DESERT_HILLS", 17);
define("FOREST_HILLS", 18);
define("TAIGA_HILLS", 19);
define("EXTREME_HILLS_EDGE", 20);
define("JUNGLE", 21);
define("JUNGLE_HILLS", 22);
define("JUNGLE_EDGE", 23);
define("DEEP_OCEAN", 24);
define("STONE_BEACH", 25);
define("COLD_BEACH", 26);
define("BIRCH_FOREST", 27);
define("BIRCH_FOREST_HILLS", 28);
define("ROOFED_FOREST", 29);
define("COLD_TAIGA", 30);
define("COLD_TAIGA_HILLS", 31);
define("MEGA_TAIGA", 32);
define("MEGA_TAIGA_HILLS", 33);
define("EXTREME_HILLS_PLUS", 34);
define("SAVANNA", 35);
define("SAVANNA_PLATEAU", 36);
define("MESA", 37);
define("MESA_PLATEAU_F", 38);
define("MESA_PLATEAU", 39);
//define("SUNFLOWER_PLAINS", 129); metioning not found
define("BIOME_FROZEN_OCEAN", 10);
define("BIOME_FROZEN_RIVER", 11);
define("BIOME_ICE_PLAINS", 12);
define("BIOME_ICE_MOUNTAINS", 13); //snow covered, temp&fall->0.0, 0.5
define("BIOME_MUSHROOM_ISLAND", 14);
define("BIOME_MUSHROOM_ISLAND_SHORE", 15);
define("BIOME_BEACH", 16);
define("BIOME_DESERT_HILLS", 17);
define("BIOME_FOREST_HILLS", 18);
define("BIOME_TAIGA_HILLS", 19);
define("BIOME_EXTREME_HILLS_EDGE", 20);
define("BIOME_JUNGLE", 21);
define("BIOME_JUNGLE_HILLS", 22);
define("BIOME_JUNGLE_EDGE", 23);
define("BIOME_DEEP_OCEAN", 24);
define("BIOME_STONE_BEACH", 25);
define("BIOME_COLD_BEACH", 26);
define("BIOME_BIRCH_FOREST", 27);
define("BIOME_BIRCH_FOREST_HILLS", 28);
define("BIOME_ROOFED_FOREST", 29);
define("BIOME_COLD_TAIGA", 30);
define("BIOME_COLD_TAIGA_HILLS", 31);
define("BIOME_MEGA_TAIGA", 32);
define("BIOME_MEGA_TAIGA_HILLS", 33);
define("BIOME_EXTREME_HILLS_PLUS", 34);
define("BIOME_SAVANNA", 35);
define("BIOME_SAVANNA_PLATEAU", 36);
define("BIOME_MESA", 37);
define("BIOME_MESA_PLATEAU_F", 38);
define("BIOME_MESA_PLATEAU", 39);
//define("BIOME_SUNFLOWER_PLAINS", 129); metioning not found
//define("ICE_PLAINS_SPIKES", 140); metioning not found
//define("BIOME_ICE_PLAINS_SPIKES", 140); metioning not found
define("REDWOOD_TAIGA_MUTATED", 160); //mentioned, but cannot check id
define("BIOME_REDWOOD_TAIGA_MUTATED", 160); //mentioned, but cannot check id
define("MAX_BIOMES", 256);
define("BIOME_MAX_BIOMES", 256);

View file

@ -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){

View file

@ -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;
}

View file

@ -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 = [];
}

View file

@ -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);
}
}