mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
Fixed PMFLevel bugs, crashes and weird methods
This commit is contained in:
parent
c1251a25bd
commit
63f4f87d37
@ -151,6 +151,10 @@ class LevelAPI{
|
||||
$path = DATA_PATH."worlds/".$name."/";
|
||||
console("[INFO] Preparing level \"".$name."\"");
|
||||
$level = new PMFLevel($path."level.pmf");
|
||||
if(!$level->isLoaded){
|
||||
console("[ERROR] Could not load level \"".$name."\"");
|
||||
return false;
|
||||
}
|
||||
$entities = new Config($path."entities.yml", CONFIG_YAML);
|
||||
if(file_exists($path."tileEntities.yml")){
|
||||
@rename($path."tileEntities.yml", $path."tiles.yml");
|
||||
@ -223,20 +227,6 @@ class LevelAPI{
|
||||
return $this->server->spawn;
|
||||
}
|
||||
|
||||
public function loadMap(){
|
||||
if($this->mapName !== false and trim($this->mapName) !== ""){
|
||||
if(!file_exists($this->mapDir."level.pmf")){
|
||||
$level = new LevelImport($this->mapDir);
|
||||
$level->import();
|
||||
}
|
||||
$this->level = new PMFLevel($this->mapDir."level.pmf");
|
||||
console("[INFO] Preparing level \"".$this->level->getData("name")."\"");
|
||||
$this->time = (int) $this->level->getData("time");
|
||||
$this->seed = (int) $this->level->getData("seed");
|
||||
$this->spawn = $this->level->getSpawn();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAll(){
|
||||
return $this->levels;
|
||||
}
|
||||
|
@ -46,13 +46,16 @@ class PMFLevel extends PMF{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function close(){
|
||||
public function closeLevel(){
|
||||
$this->chunks = null;
|
||||
unset($this->chunks, $this->chunkChange, $this->chunkInfo, $this->level);
|
||||
parent::close();
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function __construct($file, $blank = false){
|
||||
$this->chunks = array();
|
||||
$this->chunkChange = array();
|
||||
$this->chunkInfo = array();
|
||||
if(is_array($blank)){
|
||||
$this->create($file, 0);
|
||||
$this->levelData = $blank;
|
||||
@ -166,7 +169,7 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
|
||||
public static function getIndex($X, $Z){
|
||||
return ($Z << 16) + $X;
|
||||
return ($Z << 16) | ($X < 0 ? (~--$X & 0x7fff) | 0x1000 : $X & 0xFFFF);
|
||||
}
|
||||
|
||||
public static function getXZ($index, &$X = null, &$Z = null){
|
||||
@ -223,10 +226,11 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
$path = $this->getChunkPath($X, $Z);
|
||||
if(!file_exists($path)){
|
||||
if($this->isGenerating > 0){
|
||||
$this->level->generateChunk($X, $Z);
|
||||
}elseif($this->generateChunk($X, $Z) === false){
|
||||
if($this->generateChunk($X, $Z) === false){
|
||||
return false;
|
||||
}else{
|
||||
$this->populateChunk($X, $Z);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,7 +311,7 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
|
||||
public function getMiniChunk($X, $Z, $Y){
|
||||
if($this->loadChunk($X, $Z) === false){
|
||||
if($this->isChunkLoaded($X, $Z) === false and $this->loadChunk($X, $Z) === false){
|
||||
return str_repeat("\x00", 8192);
|
||||
}
|
||||
$index = self::getIndex($X, $Z);
|
||||
@ -475,11 +479,9 @@ class PMFLevel extends PMF{
|
||||
return array(AIR, 0);
|
||||
}
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index])){
|
||||
if($this->loadChunk($X, $Z) === false){
|
||||
return array(AIR, 0);
|
||||
}
|
||||
}elseif($this->chunks[$index][$Y] === false){
|
||||
if(!isset($this->chunks[$index]) and $this->loadChunk($X, $Z) === false){
|
||||
return array(AIR, 0);
|
||||
}elseif($this->chunks[$index][$Y] === false){
|
||||
return array(AIR, 0);
|
||||
}
|
||||
$aX = $x - ($X << 4);
|
||||
@ -505,10 +507,8 @@ class PMFLevel extends PMF{
|
||||
$block &= 0xFF;
|
||||
$meta &= 0x0F;
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index])){
|
||||
if($this->loadChunk($X, $Z) === false){
|
||||
return false;
|
||||
}
|
||||
if(!isset($this->chunks[$index]) and $this->loadChunk($X, $Z) === false){
|
||||
return false;
|
||||
}elseif($this->chunks[$index][$Y] === false){
|
||||
$this->fillMiniChunk($X, $Z, $Y);
|
||||
}
|
||||
@ -543,11 +543,7 @@ class PMFLevel extends PMF{
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
if(!$this->isChunkLoaded($X, $Z)){
|
||||
if($this->isGenerating > 0){
|
||||
$this->initCleanChunk($X, $Z);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
$index = self::getIndex($X, $Z);
|
||||
if(!isset($this->chunkChange[$index]) or $this->chunkChange[$index][-1] === false){//No changes in chunk
|
||||
|
@ -26,7 +26,6 @@ class Level{
|
||||
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->level = $level;
|
||||
$level->level = $this;
|
||||
$this->level->level = $this;
|
||||
$this->entities = $entities;
|
||||
$this->tiles = $tiles;
|
||||
@ -151,17 +150,19 @@ class Level{
|
||||
++$this->level->isGenerating;
|
||||
$this->generator->generateChunk($X, $Z);
|
||||
--$this->level->isGenerating;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function populateChunk($X, $Z){
|
||||
$this->generator->populateChunk($X, $Z);
|
||||
$this->level->setPopulated($X, $Z);
|
||||
$this->generator->populateChunk($X, $Z);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
if(isset($this->level)){
|
||||
$this->save(false, false);
|
||||
$this->level->close();
|
||||
$this->level->closeLevel();
|
||||
unset($this->level);
|
||||
}
|
||||
}
|
||||
|
@ -51,12 +51,11 @@ class WorldGenerator{
|
||||
//Generate 4 chunks for spawning players
|
||||
for($Z = 7; $Z <= 8; ++$Z){
|
||||
for($X = 7; $X <= 8; ++$X){
|
||||
$this->level->level->generateChunk($X, $Z);
|
||||
$this->level->level->loadChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
|
||||
$this->level->setSpawn($this->generator->getSpawn());
|
||||
$this->level->save(true, true);
|
||||
}
|
||||
|
||||
public function close(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user