UpdateBlockPacket fixed and changed skinName to skinId

This commit is contained in:
Intyre 2016-06-22 01:07:09 +02:00
parent df8e1e8702
commit 6fb41c5c7f
No known key found for this signature in database
GPG Key ID: B06D41D26935005A
6 changed files with 57 additions and 36 deletions

View File

@ -567,14 +567,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
public function setDisplayName($name){ public function setDisplayName($name){
$this->displayName = $name; $this->displayName = $name;
if($this->spawned){ if($this->spawned){
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->getSkinName(), $this->getSkinData()); $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->getSkinId(), $this->getSkinData());
} }
} }
public function setSkin($str, $skinName){ public function setSkin($str, $skinId){
parent::setSkin($str, $skinName); parent::setSkin($str, $skinId);
if($this->spawned){ if($this->spawned){
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $skinName, $str); $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $skinId, $str);
} }
} }
@ -1850,7 +1850,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
break; break;
} }
$this->setSkin($packet->skin, $packet->skinID); $this->setSkin($packet->skin, $packet->skinId);
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason")); $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if($ev->isCancelled()){ if($ev->isCancelled()){

View File

@ -2180,7 +2180,7 @@ class Server{
public function addOnlinePlayer(Player $player){ public function addOnlinePlayer(Player $player){
$this->playerList[$player->getRawUniqueId()] = $player; $this->playerList[$player->getRawUniqueId()] = $player;
$this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinName(), $player->getSkinData()); $this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinId(), $player->getSkinData());
} }
public function removeOnlinePlayer(Player $player){ public function removeOnlinePlayer(Player $player){
@ -2194,10 +2194,10 @@ class Server{
} }
} }
public function updatePlayerListData(UUID $uuid, $entityId, $name, $skinName, $skinData, array $players = null){ public function updatePlayerListData(UUID $uuid, $entityId, $name, $skinId, $skinData, array $players = null){
$pk = new PlayerListPacket(); $pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_ADD; $pk->type = PlayerListPacket::TYPE_ADD;
$pk->entries[] = [$uuid, $entityId, $name, $skinName, $skinData]; $pk->entries[] = [$uuid, $entityId, $name, $skinId, $skinData];
Server::broadcastPacket($players === null ? $this->playerList : $players, $pk); Server::broadcastPacket($players === null ? $this->playerList : $players, $pk);
} }
@ -2212,7 +2212,7 @@ class Server{
$pk = new PlayerListPacket(); $pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_ADD; $pk->type = PlayerListPacket::TYPE_ADD;
foreach($this->playerList as $player){ foreach($this->playerList as $player){
$pk->entries[] = [$player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinName(), $player->getSkinData()]; $pk->entries[] = [$player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinId(), $player->getSkinData()];
} }
$p->dataPacket($pk); $p->dataPacket($pk);

View File

@ -60,7 +60,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public $height = 1.8; public $height = 1.8;
public $eyeHeight = 1.62; public $eyeHeight = 1.62;
protected $skinName; protected $skinId;
protected $skin; protected $skin;
protected $foodTickTimer = 0; protected $foodTickTimer = 0;
@ -72,8 +72,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $this->skin; return $this->skin;
} }
public function getSkinName(){ public function getSkinId(){
return $this->skinName; return $this->skinId;
} }
/** /**
@ -92,11 +92,11 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
/** /**
* @param string $str * @param string $str
* @param string $skinName * @param string $skinId
*/ */
public function setSkin($str, $skinName){ public function setSkin($str, $skinId){
$this->skin = $str; $this->skin = $str;
$this->skinName = $skinName; $this->skinId = $skinId;
} }
public function getFood() : float{ public function getFood() : float{
@ -443,7 +443,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if(strlen($this->getSkinData()) > 0){ if(strlen($this->getSkinData()) > 0){
$this->namedtag->Skin = new CompoundTag("Skin", [ $this->namedtag->Skin = new CompoundTag("Skin", [
"Data" => new StringTag("Data", $this->getSkinData()), "Data" => new StringTag("Data", $this->getSkinData()),
"Name" => new StringTag("Name", $this->getSkinName()) "Name" => new StringTag("Name", $this->getSkinId())
]); ]);
} }
} }
@ -457,7 +457,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
} }
if(!($this instanceof Player)){ if(!($this instanceof Player)){
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $this->skinName, $this->skin, [$player]); $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $this->skinId, $this->skin, [$player]);
} }
$pk = new AddPlayerPacket(); $pk = new AddPlayerPacket();

View File

@ -796,11 +796,10 @@ class Level implements ChunkManager, Metadatable{
* @param bool $optimizeRebuilds * @param bool $optimizeRebuilds
*/ */
public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, bool $optimizeRebuilds = false){ public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, bool $optimizeRebuilds = false){
$pk = new UpdateBlockPacket();
if($optimizeRebuilds){ if($optimizeRebuilds){
$chunks = []; $chunks = [];
foreach($blocks as $b){ foreach($blocks as $b){
$pk = new UpdateBlockPacket();
if($b === null){ if($b === null){
continue; continue;
} }
@ -812,28 +811,48 @@ class Level implements ChunkManager, Metadatable{
} }
if($b instanceof Block){ if($b instanceof Block){
$pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $first ? $flags : UpdateBlockPacket::FLAG_NONE]; $pk->x = $b->x;
$pk->z = $b->z;
$pk->y = $b->y;
$pk->blockId = $b->getId();
$pk->blockData = $b->getDamage();
$pk->flags = $first ? $flags : UpdateBlockPacket::FLAG_NONE;
}else{ }else{
$fullBlock = $this->getFullBlock($b->x, $b->y, $b->z); $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
$pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $first ? $flags : UpdateBlockPacket::FLAG_NONE]; $pk->x = $b->x;
$pk->z = $b->z;
$pk->y = $b->y;
$pk->blockId = $fullBlock >> 4;
$pk->blockData = $fullBlock & 0xf;
$pk->flags = $first ? $flags : UpdateBlockPacket::FLAG_NONE;
} }
Server::broadcastPacket($target, $pk);
} }
}else{ }else{
foreach($blocks as $b){ foreach($blocks as $b){
$pk = new UpdateBlockPacket();
if($b === null){ if($b === null){
continue; continue;
} }
if($b instanceof Block){ if($b instanceof Block){
$pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $flags]; $pk->x = $b->x;
$pk->z = $b->z;
$pk->y = $b->y;
$pk->blockId = $b->getId();
$pk->blockData = $b->getDamage();
$pk->flags = $flags;
}else{ }else{
$fullBlock = $this->getFullBlock($b->x, $b->y, $b->z); $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
$pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $flags]; $pk->x = $b->x;
$pk->z = $b->z;
$pk->y = $b->y;
$pk->blockId = $fullBlock >> 4;
$pk->blockData = $fullBlock & 0xf;
$pk->flags = $flags;
} }
Server::broadcastPacket($target, $pk);
} }
} }
Server::broadcastPacket($target, $pk);
} }
public function clearCache(bool $full = false){ public function clearCache(bool $full = false){

View File

@ -35,7 +35,7 @@ class LoginPacket extends DataPacket{
public $identityPublicKey; public $identityPublicKey;
public $serverAddress; public $serverAddress;
public $skinID; public $skinId;
public $skin = null; public $skin = null;
public function decode(){ public function decode(){

View File

@ -36,7 +36,12 @@ class UpdateBlockPacket extends DataPacket{
const FLAG_ALL = (self::FLAG_NEIGHBORS | self::FLAG_NETWORK); const FLAG_ALL = (self::FLAG_NEIGHBORS | self::FLAG_NETWORK);
const FLAG_ALL_PRIORITY = (self::FLAG_ALL | self::FLAG_PRIORITY); const FLAG_ALL_PRIORITY = (self::FLAG_ALL | self::FLAG_PRIORITY);
public $records = []; //x, z, y, blockId, blockData, flags public $x;
public $z;
public $y;
public $blockId;
public $blockData;
public $flags;
public function decode(){ public function decode(){
@ -44,14 +49,11 @@ class UpdateBlockPacket extends DataPacket{
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putInt(count($this->records)); $this->putInt($this->x);
foreach($this->records as $r){ $this->putInt($this->z);
$this->putInt($r[0]); $this->putByte($this->y);
$this->putInt($r[1]); $this->putByte($this->blockId);
$this->putByte($r[2]); $this->putByte(($this->flags << 4) | $this->blockData);
$this->putByte($r[3]);
$this->putByte(($r[5] << 4) | $r[4]);
}
} }
} }