Protocol changes

This commit is contained in:
Shoghi Cervantes 2015-04-29 17:04:34 +02:00
parent c2b3f7cd7f
commit 978aa2ba0f
8 changed files with 45 additions and 108 deletions

View File

@ -651,6 +651,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$Z = null; $Z = null;
Level::getXZ($index, $X, $Z); Level::getXZ($index, $X, $Z);
++$count;
if(!$this->level->populateChunk($X, $Z)){ if(!$this->level->populateChunk($X, $Z)){
if($this->teleportPosition === null){ if($this->teleportPosition === null){
continue; continue;
@ -660,8 +662,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
++$count;
unset($this->loadQueue[$index]); unset($this->loadQueue[$index]);
$this->usedChunks[$index] = false; $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->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 = new PlayStatusPacket();
$pk->status = PlayStatusPacket::PLAYER_SPAWN; $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 $pk->eid = $this->getId(); //Always use EntityID as zero for the actual player
$this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY)); $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 = new SetTimePacket();
$pk->time = $this->level->getTime(); $pk->time = $this->level->getTime();
$pk->started = $this->level->stopTime == false; $pk->started = $this->level->stopTime == false;
@ -1985,6 +1987,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
break; break;
} }
if($this->server->isHardcore()){
$this->setBanned(true);
break;
}
$this->craftingType = 0; $this->craftingType = 0;
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn())); $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); $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
break; 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: case ProtocolInfo::REMOVE_BLOCK_PACKET:
if($this->spawned === false or $this->blocked === true or $this->dead === true){ if($this->spawned === false or $this->blocked === true or $this->dead === true){
break; break;
@ -2866,16 +2840,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS); $this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS);
} }
if($this->server->isHardcore()){
$this->setBanned(true); $pk = new RespawnPacket();
}else{ $pos = $this->getSpawn();
$pk = new RespawnPacket(); $pk->x = $pos->x;
$pos = $this->getSpawn(); $pk->y = $pos->y;
$pk->x = $pos->x; $pk->z = $pos->z;
$pk->y = $pos->y; $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
$pk->z = $pos->z;
$this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
}
} }
public function setHealth($amount){ public function setHealth($amount){

View File

@ -2408,13 +2408,13 @@ class Level implements ChunkManager, Metadatable{
} }
Timings::$generationTimer->startTiming(); Timings::$generationTimer->startTiming();
if(!$this->isChunkPopulated($x, $z)){ if(!$this->getChunk($x, $z, true)->isPopulated()){
$populate = true; $populate = true;
for($xx = -1; $xx <= 1; ++$xx){ for($xx = -1; $xx <= 1; ++$xx){
for($zz = -1; $zz <= 1; ++$zz){ for($zz = -1; $zz <= 1; ++$zz){
if(isset($this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)])){ if(isset($this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)])){
$populate = false; $populate = false;
}elseif(!$this->isChunkGenerated($x + $xx, $z + $zz)){ }elseif(!$this->getChunk($x + $xx, $z + $zz, true)->isGenerated()){
$populate = false; $populate = false;
$this->generateChunk($x + $xx, $z + $zz, $force); $this->generateChunk($x + $xx, $z + $zz, $force);
} }

View File

@ -62,10 +62,6 @@ class Chunk extends BaseChunk{
$this->nbt->Sections->setTagType(NBT::TAG_Compound); $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)){ 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("\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); 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->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray()); $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->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray()); $nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());

View File

@ -38,7 +38,6 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
* @param int $x * @param int $x
* @param int $z * @param int $z
* @param ChunkSection[] $sections * @param ChunkSection[] $sections
* @param string $biomeIds
* @param int[] $biomeColors * @param int[] $biomeColors
* @param int[] $heightMap * @param int[] $heightMap
* @param Compound[] $entities * @param Compound[] $entities
@ -46,7 +45,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
* *
* @throws ChunkException * @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->provider = $provider;
$this->x = (int) $x; $this->x = (int) $x;
$this->z = (int) $z; $this->z = (int) $z;
@ -65,17 +64,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
if(count($biomeColors) === 256){ if(count($biomeColors) === 256){
$this->biomeColors = $biomeColors; $this->biomeColors = $biomeColors;
}else{ }else{
$this->biomeColors = array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a")); $this->biomeColors = array_fill(0, 256, Binary::readInt("\x01\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);
} }
if(count($heightMap) === 256){ if(count($heightMap) === 256){

View File

@ -73,13 +73,12 @@ abstract class BaseFullChunk implements FullChunk{
* @param string $data * @param string $data
* @param string $skyLight * @param string $skyLight
* @param string $blockLight * @param string $blockLight
* @param string $biomeIds
* @param int[] $biomeColors * @param int[] $biomeColors
* @param int[] $heightMap * @param int[] $heightMap
* @param Compound[] $entities * @param Compound[] $entities
* @param Compound[] $tiles * @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->provider = $provider;
$this->x = (int) $x; $this->x = (int) $x;
$this->z = (int) $z; $this->z = (int) $z;
@ -92,15 +91,7 @@ abstract class BaseFullChunk implements FullChunk{
if(count($biomeColors) === 256){ if(count($biomeColors) === 256){
$this->biomeColors = $biomeColors; $this->biomeColors = $biomeColors;
}else{ }else{
$this->biomeColors = array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a")); $this->biomeColors = array_fill(0, 256, Binary::readInt("\x01\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);
} }
if(count($heightMap) === 256){ if(count($heightMap) === 256){

View File

@ -33,8 +33,6 @@ class Chunk extends BaseFullChunk{
protected $isGenerated = false; protected $isGenerated = false;
public function __construct($level, $chunkX, $chunkZ, $terrain, array $entityData = null, array $tileData = null){ public function __construct($level, $chunkX, $chunkZ, $terrain, array $entityData = null, array $tileData = null){
$heightMap = array_fill(0, 256, 127);
$offset = 0; $offset = 0;
$blocks = substr($terrain, $offset, 32768); $blocks = substr($terrain, $offset, 32768);
@ -45,7 +43,11 @@ class Chunk extends BaseFullChunk{
$offset += 16384; $offset += 16384;
$blockLight = substr($terrain, $offset, 16384); $blockLight = substr($terrain, $offset, 16384);
$offset += 16384; $offset += 16384;
$biomes = substr($terrain, $offset, 256);
$heightMap = [];
foreach(unpack("C*", substr($terrain, $offset, 256)) as $c){
$heightMap[] = $c;
}
$offset += 256; $offset += 256;
$biomeColors = []; $biomeColors = [];
@ -54,7 +56,7 @@ class Chunk extends BaseFullChunk{
} }
$offset += 1024; $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){ public function getBlockId($x, $y, $z){
@ -321,6 +323,7 @@ class Chunk extends BaseFullChunk{
} }
$heighmap = pack("C*", ...$this->getHeightMapArray());
$biomeColors = pack("N*", ...$this->getBiomeColorArray()); $biomeColors = pack("N*", ...$this->getBiomeColorArray());
return $chunkIndex . return $chunkIndex .
@ -328,7 +331,7 @@ class Chunk extends BaseFullChunk{
$this->getBlockDataArray() . $this->getBlockDataArray() .
$this->getBlockSkyLightArray() . $this->getBlockSkyLightArray() .
$this->getBlockLightArray() . $this->getBlockLightArray() .
$this->getBiomeIdArray() . $heighmap .
$biomeColors . chr( $biomeColors . chr(
($this->isPopulated() ? 0x02 : 0) | ($this->isGenerated() ? 0x01 : 0) ($this->isPopulated() ? 0x02 : 0) | ($this->isGenerated() ? 0x01 : 0)
); );

View File

@ -67,12 +67,8 @@ class Chunk extends BaseFullChunk{
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound); $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)){ 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)){ 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); $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->Blocks);
unset($this->nbt->Data); unset($this->nbt->Data);
unset($this->nbt->SkyLight); unset($this->nbt->SkyLight);
@ -314,15 +310,12 @@ class Chunk extends BaseFullChunk{
$chunk->blockLight = substr($data, $offset, 16384); $chunk->blockLight = substr($data, $offset, 16384);
$offset += 16384; $offset += 16384;
$chunk->biomeIds = substr($data, $offset, 256);
$offset += 256;
$chunk->biomeColors = [];
$chunk->heightMap = []; $chunk->heightMap = [];
$chunk->biomeColors = [];
$hm = unpack("C*", substr($data, $offset, 256));
$offset += 256;
$bc = unpack("N*", substr($data, $offset, 1024)); $bc = unpack("N*", substr($data, $offset, 1024));
$offset += 1024; $offset += 1024;
$hm = unpack("N*", substr($data, $offset, 1024));
$offset += 1024;
for($i = 0; $i < 256; ++$i){ for($i = 0; $i < 256; ++$i){
$chunk->biomeColors[$i] = $bc[$i + 1]; $chunk->biomeColors[$i] = $bc[$i + 1];
@ -341,8 +334,8 @@ class Chunk extends BaseFullChunk{
} }
public function toFastBinary(){ public function toFastBinary(){
$heightMap = pack("C*", ...$this->getHeightMapArray());
$biomeColors = pack("N*", ...$this->getBiomeColorArray()); $biomeColors = pack("N*", ...$this->getBiomeColorArray());
$heightMap = pack("N*", ...$this->getHeightMapArray());
return return
Binary::writeInt($this->x) . Binary::writeInt($this->x) .
@ -351,9 +344,8 @@ class Chunk extends BaseFullChunk{
$this->getBlockDataArray() . $this->getBlockDataArray() .
$this->getBlockSkyLightArray() . $this->getBlockSkyLightArray() .
$this->getBlockLightArray() . $this->getBlockLightArray() .
$this->getBiomeIdArray() .
$biomeColors .
$heightMap . $heightMap .
$biomeColors .
chr(($this->isPopulated() ? 1 << 1 : 0) + ($this->isGenerated() ? 1 : 0)); 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->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray());
$nbt->BlockLight = new ByteArray("BlockLight", $this->getBlockLightArray()); $nbt->BlockLight = new ByteArray("BlockLight", $this->getBlockLightArray());
$nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray());
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray()); $nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray()); $nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());

View File

@ -37,7 +37,6 @@ class RespawnPacket extends DataPacket{
} }
public function decode(){ public function decode(){
$this->getLong(); //TODO: remove
$this->x = $this->getFloat(); $this->x = $this->getFloat();
$this->y = $this->getFloat(); $this->y = $this->getFloat();
$this->z = $this->getFloat(); $this->z = $this->getFloat();
@ -45,7 +44,6 @@ class RespawnPacket extends DataPacket{
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putLong(0); //TODO: remove
$this->putFloat($this->x); $this->putFloat($this->x);
$this->putFloat($this->y); $this->putFloat($this->y);
$this->putFloat($this->z); $this->putFloat($this->z);