Improved metadata sending and made it less spammy

Add changed properties to a list to send in a group on tick in a single packet
This commit is contained in:
Dylan K. Taylor 2017-06-17 20:00:45 +01:00
parent 8637e0224f
commit be7b057fa5
2 changed files with 12 additions and 5 deletions

View File

@ -874,6 +874,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->sendSettings();
$this->sendPotionEffects($this);
$this->sendData($this);
$this->inventory->sendContents($this);
$this->inventory->sendArmorContents($this);
@ -2730,7 +2731,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->setSneaking(false);
$this->extinguish();
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 400, false);
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 400);
$this->deadTicks = 0;
$this->noDamageTicks = 60;

View File

@ -229,7 +229,6 @@ abstract class Entity extends Location implements Metadatable{
protected $id;
protected $dataFlags = 0;
protected $dataProperties = [
self::DATA_FLAGS => [self::DATA_TYPE_LONG, 0],
self::DATA_AIR => [self::DATA_TYPE_SHORT, 400],
@ -239,6 +238,8 @@ abstract class Entity extends Location implements Metadatable{
self::DATA_SCALE => [self::DATA_TYPE_FLOAT, 1]
];
protected $changedDataProperties = [];
public $passenger = null;
public $vehicle = null;
@ -1132,6 +1133,11 @@ abstract class Entity extends Location implements Metadatable{
return false;
}
if(count($this->changedDataProperties) > 0){
$this->sendData($this->hasSpawned, $this->changedDataProperties);
$this->changedDataProperties = [];
}
if(count($this->effects) > 0){
foreach($this->effects as $effect){
if($effect->canTick()){
@ -1866,11 +1872,11 @@ abstract class Entity extends Location implements Metadatable{
*
* @return bool
*/
public function setDataProperty($id, $type, $value, $send = true){
public function setDataProperty($id, $type, $value, bool $send = true){
if($this->getDataProperty($id) !== $value){
$this->dataProperties[$id] = [$type, $value];
if($send === true){
$this->sendData($this->hasSpawned, [$id => $this->dataProperties[$id]]);
if($send){
$this->changedDataProperties[$id] = $this->dataProperties[$id]; //This will be sent on the next tick
}
return true;