diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d18da0889..4e010ca7f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -520,7 +520,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return $this->spawnPosition; }else{ $level = $this->server->getDefaultLevel(); - return $level->getSpawn(); + return $level->getSafeSpawn(); } } @@ -1740,7 +1740,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->craftingType = 0; - $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->spawnPosition)); + $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn())); $this->teleport($ev->getRespawnPosition()); //$this->entity->fire = 0; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 75e90532b..818550167 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1635,9 +1635,10 @@ class Level implements ChunkManager, Metadatable{ * Sets the spawnpoint * * @param Vector3 $pos + * @deprecated */ public function setSpawn(Vector3 $pos){ - $this->provider->setSpawn($pos); + $this->setSpawnLocation($pos); } /** diff --git a/src/pocketmine/level/format/anvil/Anvil.php b/src/pocketmine/level/format/anvil/Anvil.php index 9781feb9d..a8af132dc 100644 --- a/src/pocketmine/level/format/anvil/Anvil.php +++ b/src/pocketmine/level/format/anvil/Anvil.php @@ -67,24 +67,16 @@ class Anvil extends McRegion{ return new ChunkRequestTask($this, $this->getLevel()->getID(), $x, $z); } - public function loadChunk($chunkX, $chunkZ, $create = false){ - $index = Level::chunkHash($chunkX, $chunkZ); - if(isset($this->chunks[$index])){ - return true; - } - $regionX = $regionZ = null; - self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ); - $this->loadRegion($regionX, $regionZ); + /** + * @param $x + * @param $z + * + * @return RegionLoader + */ + protected function getRegion($x, $z){ + $index = $x . ":" . $z; - $this->level->timings->syncChunkLoadDataTimer->startTiming(); - $chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded - $this->level->timings->syncChunkLoadDataTimer->stopTiming(); - - if($chunk instanceof Chunk){ - $this->chunks[$index] = $chunk; - }else{ - return false; - } + return isset($this->regions[$index]) ? $this->regions[$index] : null; } /** @@ -112,10 +104,9 @@ class Anvil extends McRegion{ $region->removeChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32); $this->loadChunk($chunkX, $chunkZ); }else{ - $newChunk = clone $chunk; - $newChunk->setX($chunkX); - $newChunk->setZ($chunkZ); - $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $newChunk; + $chunk->setX($chunkX); + $chunk->setZ($chunkZ); + $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk; //$this->saveChunk($chunkX, $chunkZ); } } diff --git a/src/pocketmine/level/format/anvil/Chunk.php b/src/pocketmine/level/format/anvil/Chunk.php index 77125e97f..d3491c0c0 100644 --- a/src/pocketmine/level/format/anvil/Chunk.php +++ b/src/pocketmine/level/format/anvil/Chunk.php @@ -29,6 +29,7 @@ use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\ByteArray; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Enum; +use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\IntArray; use pocketmine\Player; use pocketmine\utils\Binary; @@ -93,6 +94,8 @@ class Chunk extends BaseChunk{ } parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $sections, $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); + + unset($this->nbt->Sections); } /** @@ -151,6 +154,9 @@ class Chunk extends BaseChunk{ public function toBinary(){ $nbt = $this->getNBT(); + $nbt->xPos = new Int("xPos", $this->x); + $nbt->zPos = new Int("zPos", $this->z); + $nbt->Sections = new Enum("Sections", []); $nbt->Sections->setTagType(NBT::TAG_Compound); foreach($this->getSections() as $section){ diff --git a/src/pocketmine/level/format/anvil/RegionLoader.php b/src/pocketmine/level/format/anvil/RegionLoader.php index c8a2885c2..f1c93fc84 100644 --- a/src/pocketmine/level/format/anvil/RegionLoader.php +++ b/src/pocketmine/level/format/anvil/RegionLoader.php @@ -22,7 +22,6 @@ namespace pocketmine\level\format\anvil; use pocketmine\level\format\LevelProvider; -use pocketmine\level\format\mcregion\Chunk; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\ByteArray; @@ -31,7 +30,6 @@ use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\IntArray; use pocketmine\nbt\tag\Long; -use pocketmine\Player; use pocketmine\utils\Binary; class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{ @@ -130,8 +128,4 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{ $this->saveChunk($x, $z, $chunkData); } - public function writeChunk(Chunk $chunk){ - $this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunk->toBinary()); - } - } \ No newline at end of file diff --git a/src/pocketmine/level/format/mcregion/Chunk.php b/src/pocketmine/level/format/mcregion/Chunk.php index d5ba9054d..3fd119c61 100644 --- a/src/pocketmine/level/format/mcregion/Chunk.php +++ b/src/pocketmine/level/format/mcregion/Chunk.php @@ -28,6 +28,7 @@ use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\ByteArray; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Enum; +use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\IntArray; use pocketmine\Player; use pocketmine\utils\Binary; @@ -70,6 +71,10 @@ class Chunk extends BaseFullChunk{ } parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt["Blocks"], $this->nbt["Data"], $this->nbt["SkyLight"], $this->nbt["BlockLight"], $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); + unset($this->nbt->Blocks); + unset($this->nbt->Data); + unset($this->nbt->SkyLight); + unset($this->nbt->BlockLight); } public function getBlockId($x, $y, $z){ @@ -245,6 +250,9 @@ class Chunk extends BaseFullChunk{ public function toBinary(){ $nbt = $this->getNBT(); + $nbt->xPos = new Int("xPos", $this->x); + $nbt->zPos = new Int("zPos", $this->z); + $nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray()); $nbt->Data = new ByteArray("Data", $this->getBlockDataArray()); $nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray()); diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index 1c4b0c13d..7fca5c3b0 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -142,12 +142,11 @@ class McRegion extends BaseLevelProvider{ $regionX = $regionZ = null; self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ); $this->loadRegion($regionX, $regionZ); - $this->level->timings->syncChunkLoadDataTimer->startTiming(); $chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded $this->level->timings->syncChunkLoadDataTimer->stopTiming(); - if($chunk instanceof Chunk){ + if($chunk instanceof FullChunk){ $this->chunks[$index] = $chunk; }else{ return false; @@ -156,7 +155,7 @@ class McRegion extends BaseLevelProvider{ public function unloadChunk($x, $z, $safe = true){ $chunk = $this->getChunk($x, $z, false); - if($chunk instanceof Chunk){ + if($chunk instanceof FullChunk){ if($safe === true and $this->isChunkLoaded($x, $z)){ foreach($chunk->getEntities() as $entity){ if($entity instanceof Player){ @@ -233,10 +232,9 @@ class McRegion extends BaseLevelProvider{ $region->removeChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32); $this->loadChunk($chunkX, $chunkZ); }else{ - $newChunk = clone $chunk; - $newChunk->setX($chunkX); - $newChunk->setZ($chunkZ); - $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $newChunk; + $chunk->setX($chunkX); + $chunk->setZ($chunkZ); + $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk; //$this->saveChunk($chunkX, $chunkZ); } } @@ -255,7 +253,7 @@ class McRegion extends BaseLevelProvider{ public function isChunkPopulated($chunkX, $chunkZ){ $chunk = $this->getChunk($chunkX, $chunkZ); - if($chunk instanceof Chunk){ + if($chunk instanceof FullChunk){ return $chunk->isPopulated(); }else{ return false; diff --git a/src/pocketmine/level/format/mcregion/RegionLoader.php b/src/pocketmine/level/format/mcregion/RegionLoader.php index a15299abb..0dcb92e86 100644 --- a/src/pocketmine/level/format/mcregion/RegionLoader.php +++ b/src/pocketmine/level/format/mcregion/RegionLoader.php @@ -21,6 +21,7 @@ namespace pocketmine\level\format\mcregion; +use pocketmine\level\format\FullChunk; use pocketmine\level\format\LevelProvider; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Byte; @@ -180,7 +181,7 @@ class RegionLoader{ $this->locationTable[$index][1] = 0; } - public function writeChunk(Chunk $chunk){ + public function writeChunk(FullChunk $chunk){ $this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunk->toBinary()); } diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index 9c03a9dda..9480622be 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -122,6 +122,7 @@ class Flat extends Generator{ } } + preg_match_all('#(([0-9a-z_]{1,})\(?([0-9a-z_ =:]{0,})\)?),?#', $options, $matches); foreach($matches[2] as $i => $option){ $params = true; diff --git a/src/pocketmine/level/generator/GenerationChunkManager.php b/src/pocketmine/level/generator/GenerationChunkManager.php index eba2e89cf..195ca5588 100644 --- a/src/pocketmine/level/generator/GenerationChunkManager.php +++ b/src/pocketmine/level/generator/GenerationChunkManager.php @@ -85,6 +85,7 @@ class GenerationChunkManager implements ChunkManager{ $index = Level::chunkHash($chunkX, $chunkZ); $chunk = !isset($this->chunks[$index]) ? $this->requestChunk($chunkX, $chunkZ) : $this->chunks[$index]; $this->unloadQueue->detach($chunk); + $this->changes[$index] = $chunk; return $chunk; } @@ -112,6 +113,9 @@ class GenerationChunkManager implements ChunkManager{ } foreach($this->chunks as $chunk){ + if(isset($this->changes[$index = Level::chunkHash($chunk->getX(), $chunk->getZ())])){ + continue; + } $this->unloadQueue->attach($chunk); } } @@ -150,13 +154,11 @@ class GenerationChunkManager implements ChunkManager{ public function setChunkGenerated($chunkX, $chunkZ){ $chunk = $this->getChunk($chunkX, $chunkZ); $chunk->setGenerated(true); - $this->changes[Level::chunkHash($chunkX, $chunkZ)] = $chunk; } public function setChunkPopulated($chunkX, $chunkZ){ $chunk = $this->getChunk($chunkX, $chunkZ); $chunk->setPopulated(true); - $this->changes[Level::chunkHash($chunkX, $chunkZ)] = $chunk; } protected function requestChunk($chunkX, $chunkZ){