From 6ed63edd89d1c20f9f5b39a878402545f6fe9e70 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 19 Apr 2015 16:45:45 +0200 Subject: [PATCH] Removed some remaining references, removed duplicated code on Anvil --- src/pocketmine/Player.php | 2 +- src/pocketmine/level/Level.php | 4 +- .../level/format/anvil/RegionLoader.php | 61 +------------------ .../level/format/mcregion/Chunk.php | 3 +- .../level/format/mcregion/RegionLoader.php | 7 ++- src/pocketmine/nbt/tag/IntArray.php | 3 +- src/pocketmine/nbt/tag/String.php | 9 +-- 7 files changed, 13 insertions(+), 76 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index f31bd56fc..d96e6a0e7 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -581,7 +581,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } - public function sendChunk($x, $z, &$payload){ + public function sendChunk($x, $z, $payload){ if($this->connected === false){ return; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 6c3339b05..329f3c857 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1993,11 +1993,11 @@ class Level implements ChunkManager, Metadatable{ } } - public function chunkRequestCallback($x, $z, &$payload){ + public function chunkRequestCallback($x, $z, $payload){ $index = Level::chunkHash($x, $z); if(!isset($this->chunkCache[$index]) and $this->cacheChunks and $this->server->getMemoryManager()->canUseChunkCache()){ - $this->chunkCache[$index] =& $payload; + $this->chunkCache[$index] = $payload; } if(isset($this->chunkSendTasks[$index])){ diff --git a/src/pocketmine/level/format/anvil/RegionLoader.php b/src/pocketmine/level/format/anvil/RegionLoader.php index 207a8f155..934e85dc4 100644 --- a/src/pocketmine/level/format/anvil/RegionLoader.php +++ b/src/pocketmine/level/format/anvil/RegionLoader.php @@ -54,65 +54,8 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{ $this->lastUsed = time(); } - public function readChunk($x, $z, $generate = true, $forward = false){ - $index = self::getChunkOffset($x, $z); - if($index < 0 or $index >= 4096){ - return null; - } - - $this->lastUsed = time(); - - if(!$this->isChunkGenerated($index)){ - if($generate === true){ - //Allocate space - $this->locationTable[$index][0] = ++$this->lastSector; - $this->locationTable[$index][1] = 1; - fseek($this->filePointer, $this->locationTable[$index][0] << 12); - fwrite($this->filePointer, str_pad(Binary::writeInt(-1) . chr(self::COMPRESSION_ZLIB), 4096, "\x00", STR_PAD_RIGHT)); - $this->writeLocationIndex($index); - }else{ - return null; - } - } - - fseek($this->filePointer, $this->locationTable[$index][0] << 12); - $length = Binary::readInt(fread($this->filePointer, 4)); - $compression = ord(fgetc($this->filePointer)); - - if($length <= 0 or $length >= self::MAX_SECTOR_LENGTH){ //Not yet generated / corrupted - if($length >= self::MAX_SECTOR_LENGTH){ - $this->locationTable[$index][0] = ++$this->lastSector; - $this->locationTable[$index][1] = 1; - MainLogger::getLogger()->error("Corrupted chunk header detected"); - } - $this->generateChunk($x, $z); - fseek($this->filePointer, $this->locationTable[$index][0] << 12); - $length = Binary::readInt(fread($this->filePointer, 4)); - $compression = ord(fgetc($this->filePointer)); - } - - if($length > ($this->locationTable[$index][1] << 12)){ //Invalid chunk, bigger than defined number of sectors - MainLogger::getLogger()->error("Corrupted bigger chunk detected"); - $this->locationTable[$index][1] = $length >> 12; - $this->writeLocationIndex($index); - }elseif($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){ - MainLogger::getLogger()->error("Invalid compression type"); - - return null; - } - - $data = fread($this->filePointer, $length - 1); - $chunk = Chunk::fromBinary($data, $this->levelProvider); - if($chunk instanceof Chunk){ - return $chunk; - }elseif($forward === false){ - MainLogger::getLogger()->error("Corrupted chunk detected"); - $this->generateChunk($x, $z); - - return $this->readChunk($x, $z, $generate, true); - }else{ - return null; - } + protected function unserializeChunk($data){ + return Chunk::fromBinary($data, $this->levelProvider); } public function generateChunk($x, $z){ diff --git a/src/pocketmine/level/format/mcregion/Chunk.php b/src/pocketmine/level/format/mcregion/Chunk.php index db454464c..0c9947140 100644 --- a/src/pocketmine/level/format/mcregion/Chunk.php +++ b/src/pocketmine/level/format/mcregion/Chunk.php @@ -344,7 +344,7 @@ class Chunk extends BaseFullChunk{ $biomeColors = pack("N*", ...$this->getBiomeColorArray()); $heightMap = pack("N*", ...$this->getHeightMapArray()); - $data = + return Binary::writeInt($this->x) . Binary::writeInt($this->z) . $this->getBlockIdArray() . @@ -355,7 +355,6 @@ class Chunk extends BaseFullChunk{ $biomeColors . $heightMap . chr(($this->isPopulated() ? 1 << 1 : 0) + ($this->isGenerated() ? 1 : 0)); - return $data; } public function toBinary(){ diff --git a/src/pocketmine/level/format/mcregion/RegionLoader.php b/src/pocketmine/level/format/mcregion/RegionLoader.php index 5fbe1c575..e13ce8067 100644 --- a/src/pocketmine/level/format/mcregion/RegionLoader.php +++ b/src/pocketmine/level/format/mcregion/RegionLoader.php @@ -130,8 +130,7 @@ class RegionLoader{ return null; } - $data = fread($this->filePointer, $length - 1); - $chunk = Chunk::fromBinary($data, $this->levelProvider); + $chunk = $this->unserializeChunk(fread($this->filePointer, $length - 1)); if($chunk instanceof Chunk){ return $chunk; }elseif($forward === false){ @@ -144,6 +143,10 @@ class RegionLoader{ } } + protected function unserializeChunk($data){ + return Chunk::fromBinary($data, $this->levelProvider); + } + public function chunkExists($x, $z){ return $this->isChunkGenerated(self::getChunkOffset($x, $z)); } diff --git a/src/pocketmine/nbt/tag/IntArray.php b/src/pocketmine/nbt/tag/IntArray.php index 3bcdabbe9..c1500fa23 100644 --- a/src/pocketmine/nbt/tag/IntArray.php +++ b/src/pocketmine/nbt/tag/IntArray.php @@ -42,7 +42,6 @@ class IntArray extends NamedTag{ public function write(NBT $nbt){ $nbt->putInt(count($this->value)); - $data = pack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", ...$this->value); - $nbt->put($data); + $nbt->put(pack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", ...$this->value)); } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/String.php b/src/pocketmine/nbt/tag/String.php index a23594b74..40aae2cd6 100644 --- a/src/pocketmine/nbt/tag/String.php +++ b/src/pocketmine/nbt/tag/String.php @@ -26,14 +26,7 @@ use pocketmine\nbt\NBT; #include class String extends NamedTag{ - - public function __construct($name = "", $value = null){ - $this->name = $name; - if($value !== null){ - $this->value = $value; - } - } - + public function getType(){ return NBT::TAG_String; }