Better vanilla layers support (no meta, MCPE doesn't support it)

This commit is contained in:
Dylan K. Taylor 2017-01-13 12:11:49 +00:00
parent b72218ac5b
commit 0114cb8399
2 changed files with 26 additions and 14 deletions

View File

@ -166,7 +166,7 @@ class LevelDB extends BaseLevelProvider{
"SpawnX" => new IntTag("SpawnX", 0),
"SpawnY" => new IntTag("SpawnY", 32767),
"SpawnZ" => new IntTag("SpawnZ", 0),
"StorageVersion" => new IntTag("StorageVersion", 5), //MCPE 1.0.0, this must be updated if the level format changes in future updates.
"StorageVersion" => new IntTag("StorageVersion", self::CURRENT_STORAGE_VERSION),
"Time" => new LongTag("Time", 0),
"eduLevel" => new ByteTag("eduLevel", 0),
"falldamage" => new ByteTag("falldamage", 1),
@ -201,7 +201,12 @@ class LevelDB extends BaseLevelProvider{
if($generatorType === self::GENERATOR_FLAT and isset($options["preset"])){
$layers = explode(";", $options["preset"])[1] ?? "";
if($layers !== ""){
$db->put(self::ENTRY_FLAT_WORLD_LAYERS, "[" . $layers . "]"); //Add vanilla flatworld layers to allow terrain generation by MCPE to continue seamlessly
$out = "[";
foreach(Flat::parseLayers($layers) as $result){
$out .= $result[0] . ","; //only id, meta will unfortunately not survive :(
}
$out = rtrim($out, ",") . "]"; //remove trailing comma
$db->put(self::ENTRY_FLAT_WORLD_LAYERS, $out); //Add vanilla flatworld layers to allow terrain generation by MCPE to continue seamlessly
}
}

View File

@ -82,6 +82,21 @@ class Flat extends Generator{
}*/
}
public static function parseLayers(string $layers) : array{
$result = [];
preg_match_all('#^(([0-9]*x|)([0-9]{1,3})(|:[0-9]{0,2}))$#m', str_replace(",", "\n", $layers), $matches);
$y = 0;
foreach($matches[3] as $i => $b){
$b = Item::fromString($b . $matches[4][$i]);
$cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
for($cY = $y, $y += $cnt; $cY < $y; ++$cY){
$result[$cY] = [$b->getId(), $b->getDamage()];
}
}
return $result;
}
protected function parsePreset($preset, $chunkX, $chunkZ){
$this->preset = $preset;
$preset = explode(";", $preset);
@ -89,19 +104,11 @@ class Flat extends Generator{
$blocks = $preset[1] ?? "";
$biome = $preset[2] ?? 1;
$options = $preset[3] ?? "";
preg_match_all('#^(([0-9]*x|)([0-9]{1,3})(|:[0-9]{0,2}))$#m', str_replace(",", "\n", $blocks), $matches);
$y = 0;
$this->structure = [];
$this->chunks = [];
foreach($matches[3] as $i => $b){
$b = Item::fromString($b . $matches[4][$i]);
$cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
for($cY = $y, $y += $cnt; $cY < $y; ++$cY){
$this->structure[$cY] = [$b->getId(), $b->getDamage()];
}
}
$this->structure = self::parseLayers($blocks);
$this->floorLevel = $y;
$this->chunks = [];
$this->floorLevel = $y = count($this->structure);
for(; $y < 0xFF; ++$y){
$this->structure[$y] = [0, 0];