From be7b057fa5816e9a51657055f79b99cadc16d586 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 17 Jun 2017 20:00:45 +0100 Subject: [PATCH] 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 --- src/pocketmine/Player.php | 3 ++- src/pocketmine/entity/Entity.php | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 51d3ae6f5..d361aaa1d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -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; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 5a9dbe9c6..44ee9b750 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -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;