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

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