diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 808a100f8..30489faa3 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -100,7 +100,11 @@ class LevelAPI{ $generator = $this->server->api->getProperty("generator"); $generator = new $generator($options); }else{ - $generator = new SuperflatGenerator($options); + if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){ + $generator = new SuperflatGenerator($options); + }else{ + $generator = new TemporalGenerator($options); + } } $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed); $gen->generate(); diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index d883613bd..e93a22a1d 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -426,11 +426,15 @@ class PlayerAPI{ "lastIP" => "", "lastID" => 0, ); - $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); + if(!file_exists(DATA_PATH."players/".$iname.".yml")){ console("[NOTICE] Player data not found for \"".$iname."\", creating new profile"); + $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); $data->save(); + }else{ + $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); } + if(($this->server->gamemode & 0x01) === 0x01){ $data->set("health", 20); } diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 6bc37fe74..38367bfba 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -81,7 +81,7 @@ class ServerAPI{ "generator-settings" => "", "level-name" => "world", "level-seed" => "", - "level-type" => "FLAT", + "level-type" => "DEFAULT", "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10), diff --git a/src/material/item/generic/Coal.php b/src/material/item/generic/Coal.php index dfbe5c9dc..e8e3d0bf2 100644 --- a/src/material/item/generic/Coal.php +++ b/src/material/item/generic/Coal.php @@ -28,6 +28,9 @@ the Free Software Foundation, either version 3 of the License, or class CoalItem extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(COAL, $meta & 0x01, $count, "Coal"); + if($this->metadata === 1){ + $this->name = "Charcoal"; + } } } \ No newline at end of file diff --git a/src/world/Level.php b/src/world/Level.php index 630e0d9e7..57816829f 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -383,6 +383,10 @@ class Level{ return (int) $this->level->getData("seed"); } + public function setSeed($seed){ + $this->level->setData("seed", (int) $seed); + } + public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){ return $this->server->api->block->scheduleBlockUpdate($pos, $delay, $type); } diff --git a/src/world/generator/TemporalGenerator.php b/src/world/generator/TemporalGenerator.php new file mode 100644 index 000000000..6e0e23cb1 --- /dev/null +++ b/src/world/generator/TemporalGenerator.php @@ -0,0 +1,101 @@ +level = $level; + $this->random = $random; + $this->index = mt_rand(0, count(TemporalGenerator::$levels) - 1); + $this->world = new PocketChunkParser(); + $this->world->loadRaw(gzinflate(gzinflate(base64_decode(TemporalGenerator::$levels[$this->index][4]))), ""); + $this->world->loadMap(); + $this->level->setSeed(TemporalGenerator::$levels[$this->index][0]); + } + + public function generateChunk($chunkX, $chunkY, $chunkZ){ + + } + + public function populateChunk($chunkX, $chunkY, $chunkZ){ + + } + + public function populateLevel(){ + for($Z = 0; $Z < 16; ++$Z){ + for($X = 0; $X < 16; ++$X){ + $chunk = array( + 0 => "", + 1 => "", + 2 => "", + 3 => "", + 4 => "", + 5 => "", + 6 => "", + 7 => "" + ); + for($z = 0; $z < 16; ++$z){ + for($x = 0; $x < 16; ++$x){ + $block = $this->world->getChunkColumn($X, $Z, $x, $z, 0); + $meta = $this->world->getChunkColumn($X, $Z, $x, $z, 1); + for($Y = 0; $Y < 8; ++$Y){ + $chunk[$Y] .= substr($block, $Y << 4, 16); + $chunk[$Y] .= substr($meta, $Y << 3, 8); + $chunk[$Y] .= "\x00\x00\x00\x00\x00\x00\x00\x00"; + } + } + } + foreach($chunk as $Y => $data){ + $this->level->setMiniChunk($X, $Z, $Y, $data); + } + } + console("[NOTICE] Importing level ".ceil(($Z + 1)/0.16)."%"); + } + $this->level->save(true, true); + $this->world->map = null; + $this->world = null; + } + + public function getSpawn(){ + return new Vector3(TemporalGenerator::$levels[$this->index][1], TemporalGenerator::$levels[$this->index][2], TemporalGenerator::$levels[$this->index][3]); + } +} \ No newline at end of file diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index 9cb524d62..fba94a8bf 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -65,7 +65,7 @@ class WorldGenerator{ console("[NOTICE] Populating level"); $this->generator->populateLevel(); $this->level->setSpawn($this->generator->getSpawn()); - $this->level->save(true); + $this->level->save(true, true); } public function close(){