mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
biomes should be covered in grass now, biome ids are now saved
This commit is contained in:
parent
a5b86aa3ea
commit
3e3bc76ae0
10 changed files with 146 additions and 23 deletions
|
|
@ -245,7 +245,12 @@ class BlockAPI{
|
|||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $id
|
||||
* @param number $meta
|
||||
* @param boolean $v
|
||||
* @return GenericBlock
|
||||
*/
|
||||
public static function get($id, $meta = 0, $v = false){
|
||||
if(isset(Block::$class[$id])){
|
||||
$classname = Block::$class[$id];
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class PMFLevel extends PMF{
|
|||
private $payloadOffset = 0;
|
||||
private $chunks = [];
|
||||
private $chunkChange = [];
|
||||
|
||||
public $chunkInfo = [];
|
||||
public function __construct($file, $blank = false){
|
||||
if(is_array($blank)){
|
||||
$this->create($file, 0);
|
||||
|
|
@ -188,7 +188,32 @@ class PMFLevel extends PMF{
|
|||
unset($chunks, $chunkChange, $locationTable);
|
||||
parent::close();
|
||||
}
|
||||
|
||||
|
||||
public function getBiomeId($x, $z){
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunkInfo[$index])){
|
||||
return 0;
|
||||
}
|
||||
$aX = $x & 15;
|
||||
$aZ = $z & 15;
|
||||
|
||||
return ord($this->chunkInfo[$index][0][$aX + ($aZ << 4)]);
|
||||
}
|
||||
|
||||
public function setBiomeId($x, $z, $id){
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index])){
|
||||
return 0;
|
||||
}
|
||||
$aX = $x & 15;
|
||||
$aZ = $z & 15;
|
||||
$this->chunkInfo[$index][0][$aX + ($aZ << 4)] = chr($id);
|
||||
}
|
||||
|
||||
public function unloadChunk($X, $Z, $save = true){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
|
|
@ -229,6 +254,7 @@ class PMFLevel extends PMF{
|
|||
|
||||
$chunk = @gzopen($this->getChunkPath($X, $Z), "wb" . PMF_LEVEL_DEFLATE_LEVEL);
|
||||
$bitmap = 0;
|
||||
gzwrite($chunk, $this->chunkInfo[$index][0]);
|
||||
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){
|
||||
if($this->chunks[$index][$Y] !== false and ((isset($this->chunkChange[$index][$Y]) and $this->chunkChange[$index][$Y] === 0) or !$this->isMiniChunkEmpty($X, $Z, $Y))){
|
||||
gzwrite($chunk, $this->chunks[$index][$Y]);
|
||||
|
|
@ -296,26 +322,30 @@ class PMFLevel extends PMF{
|
|||
|
||||
$info = $this->locationTable[$index];
|
||||
$this->seek($info[0]);
|
||||
|
||||
$chunk = @gzopen($this->getChunkPath($X, $Z), "rb");
|
||||
$cp = $this->getChunkPath($X, $Z);
|
||||
$chunk = file_get_contents($cp);
|
||||
if($chunk === false){
|
||||
return false;
|
||||
}
|
||||
$chunk = zlib_decode($chunk);
|
||||
$offset = 0;
|
||||
$this->chunks[$index] = [];
|
||||
$this->chunkChange[$index] = [-1 => false];
|
||||
$this->chunkInfo[$index][0] = substr($chunk, $offset, 256); //Biome data
|
||||
$offset += 256;
|
||||
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){
|
||||
$t = 1 << $Y;
|
||||
if(($info[0] & $t) === $t){
|
||||
// 4096 + 2048 + 2048, Block Data, Meta, Light
|
||||
if(strlen($this->chunks[$index][$Y] = gzread($chunk, 16384)) < 16384){
|
||||
// 4096 + 4096 + 4096 + 4096, Id, Meta, BlockLight, Skylight
|
||||
if(strlen($this->chunks[$index][$Y] = substr($chunk, $offset, 16384)) < 16384){
|
||||
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2);
|
||||
$this->fillMiniChunk($X, $Z, $Y);
|
||||
}
|
||||
$offset += 16384;
|
||||
}else{
|
||||
$this->chunks[$index][$Y] = false;
|
||||
}
|
||||
}
|
||||
@gzclose($chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -356,8 +386,7 @@ class PMFLevel extends PMF{
|
|||
7 => 16384,
|
||||
);
|
||||
$this->chunkInfo[$index] = array(
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
0 => str_repeat("\x00", 256)
|
||||
);
|
||||
$this->locationTable[$index] = array(0);
|
||||
}
|
||||
|
|
@ -381,6 +410,13 @@ class PMFLevel extends PMF{
|
|||
var_dump(func_get_args());
|
||||
console("[NOTICE] If you see this message, you should send the log with error to the devs.");
|
||||
}
|
||||
public function getBlockIDsXZ($x, $z){
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$index = $this->getIndex($X, $Z);
|
||||
return nullsafe($this->chunks[$index], 0);
|
||||
}
|
||||
|
||||
public function getBlockID($x, $y, $z){
|
||||
if($y > 127 or $y < 0){
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ class Level{
|
|||
$orderedData = "";
|
||||
$orderedSkyLight = ""; //str_repeat("\xff", 16*16*64);
|
||||
$orderedLight = ""; //str_repeat("\xff", 16*16*64);
|
||||
$orderedBiomeIds = str_repeat("\x0f", 16*16); //all plains, according to PocketMine 1.4 source
|
||||
$orderedBiomeIds = $this->level->chunkInfo[$this->level->getIndex($X, $Z)][0];
|
||||
$orderedBiomeColors = str_repeat("\x00\x85\xb2\x4a", 256); // also PM 1.4
|
||||
$tileEntities = "";
|
||||
if($gen)$this->level->generateChunk($X, $Z, $this->generator);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,14 @@ require_once("NewLevelGenerator.php");
|
|||
* Thank You <3
|
||||
*/
|
||||
class ExperimentalGenerator implements NewLevelGenerator{
|
||||
|
||||
/**
|
||||
* @var Populator[]
|
||||
*/
|
||||
private $populators = array();
|
||||
/**
|
||||
* @var Populator[]
|
||||
*/
|
||||
private $genPopulators = array();
|
||||
private $level;
|
||||
private $random;
|
||||
private $worldHeight = 65;
|
||||
|
|
@ -73,7 +79,7 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
new OreType(new StoneBlock(5), 12, 16, 0, 128),
|
||||
));
|
||||
$this->populators[] = $ores;
|
||||
|
||||
$this->genPopulators[] = new GroundCover();
|
||||
$trees = new TreePopulator();
|
||||
$trees->setBaseAmount(3);
|
||||
$trees->setRandomAmount(0);
|
||||
|
|
@ -116,7 +122,7 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
$weightSum = 0;
|
||||
|
||||
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
|
||||
|
||||
$this->level->level->setBiomeId(($chunkX << 4) + $x, ($chunkZ << 4) + $z, $biome->getID());
|
||||
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];
|
||||
|
|
@ -138,7 +144,6 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
$weightSum += $weight;
|
||||
}
|
||||
}
|
||||
|
||||
$minSum /= $weightSum;
|
||||
$maxSum /= $weightSum;
|
||||
|
||||
|
|
@ -163,13 +168,18 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
//$chunk .= str_repeat("\xff", 16);
|
||||
//$chunk .= str_repeat("\xff", 16);
|
||||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //light
|
||||
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //more light
|
||||
}
|
||||
}
|
||||
$this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk);
|
||||
}
|
||||
|
||||
foreach($this->genPopulators as $pop){
|
||||
$pop->populate($this->level, $chunkX, $chunkZ, $this->random);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
$base = array();
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$this->level->level->setBiomeId($x + ($chunkX << 4), $z + ($chunkZ << 4), BIOME_PLAINS);
|
||||
$i = ($z << 4) + $x;
|
||||
$hills[$i] = $this->noiseHills->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 0.11, 12, true);
|
||||
$patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true);
|
||||
|
|
@ -79,7 +80,6 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
||||
$chunk = "";
|
||||
$startY = $chunkY << 4;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
abstract class Biome{
|
||||
protected $id, $topBlock, $fillerBlock, $name, $minY, $maxY;
|
||||
protected $id, $topBlocks, $fillerBlock, $name, $minY, $maxY;
|
||||
public function __construct($id, $name){
|
||||
$this->name = $name;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function setTopBlock($id){
|
||||
$this->topBlock = $id;
|
||||
public function setTopBlocks($id){
|
||||
$this->topBlocks = $id;
|
||||
}
|
||||
|
||||
public function getID(){
|
||||
|
|
@ -24,6 +24,10 @@ abstract class Biome{
|
|||
return $this->minY;
|
||||
}
|
||||
|
||||
public function getTopBlocks(){
|
||||
return $this->topBlocks;
|
||||
}
|
||||
|
||||
public function getMax(){
|
||||
return $this->maxY;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@ class BiomeSelector
|
|||
ConsoleAPI::debug("Registered $b");
|
||||
self::$biomes[$b->getID()] = $b;
|
||||
}
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Biome | false
|
||||
*/
|
||||
public static function get($id){
|
||||
return nullsafe(self::$biomes[$id], false);
|
||||
}
|
||||
|
||||
public function generateBiomeLookup(){
|
||||
for($t = 0; $t < 64; ++$t){
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class BiomeExtremeHills extends Biome{
|
||||
class BiomeExtremeHills extends BiomeWithGrass{
|
||||
public function __construct($id, $name){
|
||||
parent::__construct($id, $name);
|
||||
$this->setMinMax(63, 127);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,13 @@ class BiomeWithGrass extends Biome
|
|||
{
|
||||
public function __construct($id, $name){
|
||||
parent::__construct($id, $name);
|
||||
$this->setTopBlock(GRASS);
|
||||
$this->setTopBlocks([
|
||||
[GRASS, 0],
|
||||
[DIRT, 0],
|
||||
[DIRT, 0],
|
||||
[DIRT, 0],
|
||||
[DIRT, 0],
|
||||
]);
|
||||
$this->setFillerBlock(STONE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
src/world/generator/populator/GroundCover.php
Normal file
55
src/world/generator/populator/GroundCover.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
class GroundCover extends Populator
|
||||
{
|
||||
public function populate(Level $level, $chunkX, $chunkZ, Random $random)
|
||||
{
|
||||
console("gcpop: $chunkX $chunkZ");
|
||||
$waterHeight = 0; //TODO
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$pcx = ($chunkX << 4) + $x;
|
||||
$pcz = ($chunkZ << 4) + $z;
|
||||
$biome = BiomeSelector::get($level->level->getBiomeId($pcx, $pcz));
|
||||
$cover = $biome->getTopBlocks();
|
||||
if(count($cover) > 0){
|
||||
$diffY = 0;
|
||||
|
||||
if(!BlockAPI::get($cover[0][0], $cover[0][1])->isSolid){
|
||||
$diffY = 1;
|
||||
}
|
||||
|
||||
$column = $level->level->getBlockIDsXZ($pcx, $pcz);
|
||||
for($y = 127; $y > 0; --$y){
|
||||
$chunkY = $y >> 4;
|
||||
$b = $column[$chunkY][(($y & 0xf) + ($x << 6) + ($z << 10))];
|
||||
if($b !== "\x00" and !BlockAPI::get(ord($b))->isTransparent){
|
||||
break;
|
||||
}
|
||||
}
|
||||
$startY = min(127, $y + $diffY);
|
||||
$endY = $startY - count($cover);
|
||||
for($y = $startY; $y > $endY and $y >= 0; --$y){
|
||||
$chunkY = $y >> 4;
|
||||
$pair = $cover[$startY - $y];
|
||||
$b = BlockAPI::get($pair[0], $pair[1]);
|
||||
if($column[$chunkY][(($y & 0xf) + ($x << 6) + ($z << 10))] === "\x00" and $b->isSolid){
|
||||
break;
|
||||
}
|
||||
if($y <= $waterHeight and $b->getID() == GRASS and $level->level->getBlockID($pcx, $y + 1, $pcz) == STILL_WATER){
|
||||
$b = BlockAPI::get(DIRT);
|
||||
}
|
||||
if($b->getMetadata() === 0){
|
||||
$level->level->setBlockId($pcx, $y, $pcz, $b->getID());
|
||||
}else{
|
||||
$level->level->setBlock($pcx, $y, $pcz, $b->getID(), $b->getMetadata());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue