From 8ae9cd4eafc0de20ee335c2641c205e2b5a37dfd Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 19 Mar 2015 15:41:26 +0100 Subject: [PATCH 1/3] Clone initial chunk in Flat.php The Flat generator destroys Chunk at 0,0. What happens is that it request the level to read Chunk at 0,0. It then uses that chunk to create the template chunk. However this obliterates whatever was in Chunk at 0,0. Added a line to "clone" this chunk, so when parsePreset generates the template chunk, all this goes to a copy rather than the original file chunk 0,0. --- src/pocketmine/level/generator/Flat.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index 0aa1902045..a4e15f7b91 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -106,7 +106,7 @@ class Flat extends Generator{ } - $this->chunk = $this->level->getChunk(0, 0); + $this->chunk = clone $this->level->getChunk(0, 0); $this->chunk->setGenerated(); for($Z = 0; $Z < 16; ++$Z){ @@ -165,4 +165,4 @@ class Flat extends Generator{ public function getSpawn(){ return new Vector3(128, $this->floorLevel, 128); } -} \ No newline at end of file +} From 1d1a8a316e7fd7ba6a206ffc9df9cb411a79ad16 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Fri, 20 Mar 2015 08:13:55 +0100 Subject: [PATCH 2/3] Take-2: Delay "parsePreset" until we have to really generate a block --- src/pocketmine/level/generator/Flat.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index a4e15f7b91..2264c1ea86 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -59,6 +59,7 @@ class Flat extends Generator{ $this->preset = "2;7,2x3,2;1;"; //$this->preset = "2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)"; $this->options = $options; + $this->chunk = null; if(isset($this->options["decoration"])){ $ores = new Ore(); @@ -80,7 +81,7 @@ class Flat extends Generator{ }*/ } - protected function parsePreset($preset){ + protected function parsePreset($preset, $chunkX, $chunkZ){ $this->preset = $preset; $preset = explode(";", $preset); $version = (int) $preset[0]; @@ -106,7 +107,7 @@ class Flat extends Generator{ } - $this->chunk = clone $this->level->getChunk(0, 0); + $this->chunk = $this->level->getChunk($chunkX, $chunkZ); $this->chunk->setGenerated(); for($Z = 0; $Z < 16; ++$Z){ @@ -139,15 +140,24 @@ class Flat extends Generator{ $this->level = $level; $this->random = $random; + /* + // Commented out : We want to delay this if(isset($this->options["preset"]) and $this->options["preset"] != ""){ $this->parsePreset($this->options["preset"]); }else{ $this->parsePreset($this->preset); } - + */ } public function generateChunk($chunkX, $chunkZ){ + if($this->chunk === null) { + if(isset($this->options["preset"]) and $this->options["preset"] != ""){ + $this->parsePreset($this->options["preset"], $chunkX, $chunkZ); + }else{ + $this->parsePreset($this->preset, $chunkX, $chunkZ); + } + } $chunk = clone $this->chunk; $chunk->setX($chunkX); $chunk->setZ($chunkZ); From c68cd2c49623e94f1f02219d2fa8dfaf44cea8e6 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Mon, 23 Mar 2015 10:28:29 +0100 Subject: [PATCH 3/3] Cloned the initial empty chunk --- src/pocketmine/level/generator/Flat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index 2264c1ea86..edaf7cb197 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -107,7 +107,7 @@ class Flat extends Generator{ } - $this->chunk = $this->level->getChunk($chunkX, $chunkZ); + $this->chunk = clone $this->level->getChunk($chunkX, $chunkZ); $this->chunk->setGenerated(); for($Z = 0; $Z < 16; ++$Z){