Entity: split getSyncedNetworkData() into two functions

to avoid opaque boolean parameters
This commit is contained in:
Dylan K. Taylor 2021-01-08 13:59:52 +00:00
parent e53b57732b
commit 053a7a1a61
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 15 additions and 7 deletions

View File

@ -589,7 +589,7 @@ abstract class Entity{
}
}
$changedProperties = $this->getSyncedNetworkData(true);
$changedProperties = $this->getDirtyNetworkData();
if(count($changedProperties) > 0){
$this->sendData(null, $changedProperties);
$this->networkProperties->clearDirtyProperties();
@ -1436,7 +1436,7 @@ abstract class Entity{
$pk->attributes = array_map(function(Attribute $attr) : NetworkAttribute{
return new NetworkAttribute($attr->getId(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getValue(), $attr->getDefaultValue());
}, $this->attributeMap->getAll());
$pk->metadata = $this->getSyncedNetworkData(false);
$pk->metadata = $this->getAllNetworkData();
$player->getNetworkSession()->sendDataPacket($pk);
}
@ -1557,7 +1557,7 @@ abstract class Entity{
*/
public function sendData(?array $targets, ?array $data = null) : void{
$targets = $targets ?? $this->hasSpawned;
$data = $data ?? $this->getSyncedNetworkData(false);
$data = $data ?? $this->getAllNetworkData();
foreach($targets as $p){
$p->getNetworkSession()->syncActorData($this, $data);
@ -1568,10 +1568,18 @@ abstract class Entity{
* @return MetadataProperty[]
* @phpstan-return array<int, MetadataProperty>
*/
final protected function getSyncedNetworkData(bool $dirtyOnly) : array{
final protected function getDirtyNetworkData() : array{
$this->syncNetworkData($this->networkProperties);
return $this->networkProperties->getDirty();
}
return $dirtyOnly ? $this->networkProperties->getDirty() : $this->networkProperties->getAll();
/**
* @return MetadataProperty[]
* @phpstan-return array<int, MetadataProperty>
*/
final protected function getAllNetworkData() : array{
$this->syncNetworkData($this->networkProperties);
return $this->networkProperties->getAll();
}
protected function syncNetworkData(EntityMetadataCollection $properties) : void{

View File

@ -399,7 +399,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
$pk->yaw = $this->location->yaw;
$pk->pitch = $this->location->pitch;
$pk->item = TypeConverter::getInstance()->coreItemStackToNet($this->getInventory()->getItemInHand());
$pk->metadata = $this->getSyncedNetworkData(false);
$pk->metadata = $this->getAllNetworkData();
$player->getNetworkSession()->sendDataPacket($pk);
//TODO: Hack for MCPE 1.2.13: DATA_NAMETAG is useless in AddPlayerPacket, so it has to be sent separately

View File

@ -210,7 +210,7 @@ class ItemEntity extends Entity{
$pk->position = $this->location->asVector3();
$pk->motion = $this->getMotion();
$pk->item = TypeConverter::getInstance()->coreItemStackToNet($this->getItem());
$pk->metadata = $this->getSyncedNetworkData(false);
$pk->metadata = $this->getAllNetworkData();
$player->getNetworkSession()->sendDataPacket($pk);
}