From 978aa2ba0fa019932faff1e1b89cae86becbd53c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 29 Apr 2015 17:04:34 +0200 Subject: [PATCH] Protocol changes --- src/pocketmine/Player.php | 75 ++++++------------- src/pocketmine/level/Level.php | 4 +- src/pocketmine/level/format/anvil/Chunk.php | 8 +- .../level/format/generic/BaseChunk.php | 15 +--- .../level/format/generic/BaseFullChunk.php | 13 +--- src/pocketmine/level/format/leveldb/Chunk.php | 13 ++-- .../level/format/mcregion/Chunk.php | 23 ++---- .../network/protocol/RespawnPacket.php | 2 - 8 files changed, 45 insertions(+), 108 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 06e6eed3d..6588745e2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -651,6 +651,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $Z = null; Level::getXZ($index, $X, $Z); + ++$count; + if(!$this->level->populateChunk($X, $Z)){ if($this->teleportPosition === null){ continue; @@ -660,8 +662,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } - ++$count; - unset($this->loadQueue[$index]); $this->usedChunks[$index] = false; @@ -687,7 +687,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos)); - $this->teleport($ev->getRespawnPosition()); + $pos = $ev->getRespawnPosition(); + + $pk = new RespawnPacket(); + $pk->x = $pos->x; + $pk->y = $pos->y; + $pk->z = $pos->z; + $this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY)); + + $this->teleport($pos); $pk = new PlayStatusPacket(); $pk->status = PlayStatusPacket::PLAYER_SPAWN; @@ -1604,12 +1612,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->eid = $this->getId(); //Always use EntityID as zero for the actual player $this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY)); - $pk = new RespawnPacket(); - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY)); - $pk = new SetTimePacket(); $pk->time = $this->level->getTime(); $pk->started = $this->level->stopTime == false; @@ -1985,6 +1987,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; } + if($this->server->isHardcore()){ + $this->setBanned(true); + break; + } + $this->craftingType = 0; $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn())); @@ -2017,39 +2024,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); break; - case ProtocolInfo::RESPAWN_PACKET: - //TODO: Remove - if($this->spawned === false or $this->dead === false){ - break; - } - - $this->craftingType = 0; - - $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn())); - - $this->teleport($ev->getRespawnPosition()); - - $this->extinguish(); - $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300); - $this->deadTicks = 0; - $this->noDamageTicks = 60; - - $this->setHealth(20); - $this->dead = false; - - $this->removeAllEffects(); - $this->sendData($this); - - $this->sendSettings(); - $this->inventory->sendContents($this); - $this->inventory->sendArmorContents($this); - - $this->blocked = false; - - $this->spawnToAll(); - $this->scheduleUpdate(); - break; - case ProtocolInfo::REMOVE_BLOCK_PACKET: if($this->spawned === false or $this->blocked === true or $this->dead === true){ break; @@ -2866,16 +2840,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS); } - if($this->server->isHardcore()){ - $this->setBanned(true); - }else{ - $pk = new RespawnPacket(); - $pos = $this->getSpawn(); - $pk->x = $pos->x; - $pk->y = $pos->y; - $pk->z = $pos->z; - $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS)); - } + + $pk = new RespawnPacket(); + $pos = $this->getSpawn(); + $pk->x = $pos->x; + $pk->y = $pos->y; + $pk->z = $pos->z; + $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS)); } public function setHealth($amount){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index dd7e2ed7a..19bbd1924 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2408,13 +2408,13 @@ class Level implements ChunkManager, Metadatable{ } Timings::$generationTimer->startTiming(); - if(!$this->isChunkPopulated($x, $z)){ + if(!$this->getChunk($x, $z, true)->isPopulated()){ $populate = true; for($xx = -1; $xx <= 1; ++$xx){ for($zz = -1; $zz <= 1; ++$zz){ if(isset($this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)])){ $populate = false; - }elseif(!$this->isChunkGenerated($x + $xx, $z + $zz)){ + }elseif(!$this->getChunk($x + $xx, $z + $zz, true)->isGenerated()){ $populate = false; $this->generateChunk($x + $xx, $z + $zz, $force); } diff --git a/src/pocketmine/level/format/anvil/Chunk.php b/src/pocketmine/level/format/anvil/Chunk.php index de8ad3af6..68de5afb4 100644 --- a/src/pocketmine/level/format/anvil/Chunk.php +++ b/src/pocketmine/level/format/anvil/Chunk.php @@ -62,10 +62,6 @@ class Chunk extends BaseChunk{ $this->nbt->Sections->setTagType(NBT::TAG_Compound); } - if(!isset($this->nbt->Biomes) or !($this->nbt->Biomes instanceof ByteArray)){ - $this->nbt->Biomes = new ByteArray("Biomes", str_repeat("\x01", 256)); - } - if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArray)){ $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a"))); } @@ -89,7 +85,7 @@ class Chunk extends BaseChunk{ } } - parent::__construct($level, (int) $this->nbt["xPos"], (int) $this->nbt["zPos"], $sections, $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); + parent::__construct($level, (int) $this->nbt["xPos"], (int) $this->nbt["zPos"], $sections, $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); unset($this->nbt->Sections); } @@ -196,7 +192,6 @@ class Chunk extends BaseChunk{ ]); } - $nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray()); $nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray()); $nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray()); @@ -250,7 +245,6 @@ class Chunk extends BaseChunk{ ]); } - $nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray()); $nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray()); $nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray()); diff --git a/src/pocketmine/level/format/generic/BaseChunk.php b/src/pocketmine/level/format/generic/BaseChunk.php index 6ac6f45f8..c2f71de18 100644 --- a/src/pocketmine/level/format/generic/BaseChunk.php +++ b/src/pocketmine/level/format/generic/BaseChunk.php @@ -38,7 +38,6 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ * @param int $x * @param int $z * @param ChunkSection[] $sections - * @param string $biomeIds * @param int[] $biomeColors * @param int[] $heightMap * @param Compound[] $entities @@ -46,7 +45,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ * * @throws ChunkException */ - protected function __construct($provider, $x, $z, array $sections, $biomeIds = null, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = []){ + protected function __construct($provider, $x, $z, array $sections, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = []){ $this->provider = $provider; $this->x = (int) $x; $this->z = (int) $z; @@ -65,17 +64,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ if(count($biomeColors) === 256){ $this->biomeColors = $biomeColors; }else{ - $this->biomeColors = array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a")); - } - - - - if(strlen($biomeIds) !== 256){ - $biomeIds = str_repeat("\x01", 256); - } - - for($i = 0; $i < 256; ++$i){ - $this->biomeColors[$i] = ($this->biomeColors[$i] & 0xFFFFFF) | (ord($biomeIds{$i}) << 24); + $this->biomeColors = array_fill(0, 256, Binary::readInt("\x01\x85\xb2\x4a")); } if(count($heightMap) === 256){ diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index d7de59c0a..1dff0be2f 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -73,13 +73,12 @@ abstract class BaseFullChunk implements FullChunk{ * @param string $data * @param string $skyLight * @param string $blockLight - * @param string $biomeIds * @param int[] $biomeColors * @param int[] $heightMap * @param Compound[] $entities * @param Compound[] $tiles */ - protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, $biomeIds = null, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = []){ + protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = []){ $this->provider = $provider; $this->x = (int) $x; $this->z = (int) $z; @@ -92,15 +91,7 @@ abstract class BaseFullChunk implements FullChunk{ if(count($biomeColors) === 256){ $this->biomeColors = $biomeColors; }else{ - $this->biomeColors = array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a")); - } - - if(strlen($biomeIds) !== 256){ - $biomeIds = str_repeat("\x01", 256); - } - - for($i = 0; $i < 256; ++$i){ - $this->biomeColors[$i] = ($this->biomeColors[$i] & 0xFFFFFF) | (ord($biomeIds{$i}) << 24); + $this->biomeColors = array_fill(0, 256, Binary::readInt("\x01\x85\xb2\x4a")); } if(count($heightMap) === 256){ diff --git a/src/pocketmine/level/format/leveldb/Chunk.php b/src/pocketmine/level/format/leveldb/Chunk.php index be853c73b..dafe439c8 100644 --- a/src/pocketmine/level/format/leveldb/Chunk.php +++ b/src/pocketmine/level/format/leveldb/Chunk.php @@ -33,8 +33,6 @@ class Chunk extends BaseFullChunk{ protected $isGenerated = false; public function __construct($level, $chunkX, $chunkZ, $terrain, array $entityData = null, array $tileData = null){ - $heightMap = array_fill(0, 256, 127); - $offset = 0; $blocks = substr($terrain, $offset, 32768); @@ -45,7 +43,11 @@ class Chunk extends BaseFullChunk{ $offset += 16384; $blockLight = substr($terrain, $offset, 16384); $offset += 16384; - $biomes = substr($terrain, $offset, 256); + + $heightMap = []; + foreach(unpack("C*", substr($terrain, $offset, 256)) as $c){ + $heightMap[] = $c; + } $offset += 256; $biomeColors = []; @@ -54,7 +56,7 @@ class Chunk extends BaseFullChunk{ } $offset += 1024; - parent::__construct($level, $chunkX, $chunkZ, $blocks, $data, $skyLight, $blockLight, $biomes, $biomeColors, $heightMap, $entityData === null ? [] : $entityData, $tileData === null ? [] : $tileData); + parent::__construct($level, $chunkX, $chunkZ, $blocks, $data, $skyLight, $blockLight, $biomeColors, $heightMap, $entityData === null ? [] : $entityData, $tileData === null ? [] : $tileData); } public function getBlockId($x, $y, $z){ @@ -321,6 +323,7 @@ class Chunk extends BaseFullChunk{ } + $heighmap = pack("C*", ...$this->getHeightMapArray()); $biomeColors = pack("N*", ...$this->getBiomeColorArray()); return $chunkIndex . @@ -328,7 +331,7 @@ class Chunk extends BaseFullChunk{ $this->getBlockDataArray() . $this->getBlockSkyLightArray() . $this->getBlockLightArray() . - $this->getBiomeIdArray() . + $heighmap . $biomeColors . chr( ($this->isPopulated() ? 0x02 : 0) | ($this->isGenerated() ? 0x01 : 0) ); diff --git a/src/pocketmine/level/format/mcregion/Chunk.php b/src/pocketmine/level/format/mcregion/Chunk.php index 0c9947140..fce045984 100644 --- a/src/pocketmine/level/format/mcregion/Chunk.php +++ b/src/pocketmine/level/format/mcregion/Chunk.php @@ -67,12 +67,8 @@ class Chunk extends BaseFullChunk{ $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } - if(!isset($this->nbt->Biomes) or !($this->nbt->Biomes instanceof ByteArray)){ - $this->nbt->Biomes = new ByteArray("Biomes", str_repeat("\x01", 256)); - } - if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArray)){ - $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a"))); + $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, Binary::readInt("\x01\x85\xb2\x4a"))); } if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArray)){ @@ -89,7 +85,7 @@ class Chunk extends BaseFullChunk{ $this->nbt->BlockLight = new ByteArray("BlockLight", $half); } - parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt->Blocks->getValue(), $this->nbt->Data->getValue(), $this->nbt->SkyLight->getValue(), $this->nbt->BlockLight->getValue(), $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); + parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt->Blocks->getValue(), $this->nbt->Data->getValue(), $this->nbt->SkyLight->getValue(), $this->nbt->BlockLight->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); unset($this->nbt->Blocks); unset($this->nbt->Data); unset($this->nbt->SkyLight); @@ -314,15 +310,12 @@ class Chunk extends BaseFullChunk{ $chunk->blockLight = substr($data, $offset, 16384); $offset += 16384; - $chunk->biomeIds = substr($data, $offset, 256); - $offset += 256; - - $chunk->biomeColors = []; $chunk->heightMap = []; + $chunk->biomeColors = []; + $hm = unpack("C*", substr($data, $offset, 256)); + $offset += 256; $bc = unpack("N*", substr($data, $offset, 1024)); $offset += 1024; - $hm = unpack("N*", substr($data, $offset, 1024)); - $offset += 1024; for($i = 0; $i < 256; ++$i){ $chunk->biomeColors[$i] = $bc[$i + 1]; @@ -341,8 +334,8 @@ class Chunk extends BaseFullChunk{ } public function toFastBinary(){ + $heightMap = pack("C*", ...$this->getHeightMapArray()); $biomeColors = pack("N*", ...$this->getBiomeColorArray()); - $heightMap = pack("N*", ...$this->getHeightMapArray()); return Binary::writeInt($this->x) . @@ -351,9 +344,8 @@ class Chunk extends BaseFullChunk{ $this->getBlockDataArray() . $this->getBlockSkyLightArray() . $this->getBlockLightArray() . - $this->getBiomeIdArray() . - $biomeColors . $heightMap . + $biomeColors . chr(($this->isPopulated() ? 1 << 1 : 0) + ($this->isGenerated() ? 1 : 0)); } @@ -369,7 +361,6 @@ class Chunk extends BaseFullChunk{ $nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray()); $nbt->BlockLight = new ByteArray("BlockLight", $this->getBlockLightArray()); - $nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray()); $nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray()); $nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray()); diff --git a/src/pocketmine/network/protocol/RespawnPacket.php b/src/pocketmine/network/protocol/RespawnPacket.php index 7d41f72e6..903c7e02f 100644 --- a/src/pocketmine/network/protocol/RespawnPacket.php +++ b/src/pocketmine/network/protocol/RespawnPacket.php @@ -37,7 +37,6 @@ class RespawnPacket extends DataPacket{ } public function decode(){ - $this->getLong(); //TODO: remove $this->x = $this->getFloat(); $this->y = $this->getFloat(); $this->z = $this->getFloat(); @@ -45,7 +44,6 @@ class RespawnPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong(0); //TODO: remove $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z);