mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Entity: split getSyncedNetworkData() into two functions
to avoid opaque boolean parameters
This commit is contained in:
@ -589,7 +589,7 @@ abstract class Entity{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$changedProperties = $this->getSyncedNetworkData(true);
|
$changedProperties = $this->getDirtyNetworkData();
|
||||||
if(count($changedProperties) > 0){
|
if(count($changedProperties) > 0){
|
||||||
$this->sendData(null, $changedProperties);
|
$this->sendData(null, $changedProperties);
|
||||||
$this->networkProperties->clearDirtyProperties();
|
$this->networkProperties->clearDirtyProperties();
|
||||||
@ -1436,7 +1436,7 @@ abstract class Entity{
|
|||||||
$pk->attributes = array_map(function(Attribute $attr) : NetworkAttribute{
|
$pk->attributes = array_map(function(Attribute $attr) : NetworkAttribute{
|
||||||
return new NetworkAttribute($attr->getId(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getValue(), $attr->getDefaultValue());
|
return new NetworkAttribute($attr->getId(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getValue(), $attr->getDefaultValue());
|
||||||
}, $this->attributeMap->getAll());
|
}, $this->attributeMap->getAll());
|
||||||
$pk->metadata = $this->getSyncedNetworkData(false);
|
$pk->metadata = $this->getAllNetworkData();
|
||||||
|
|
||||||
$player->getNetworkSession()->sendDataPacket($pk);
|
$player->getNetworkSession()->sendDataPacket($pk);
|
||||||
}
|
}
|
||||||
@ -1557,7 +1557,7 @@ abstract class Entity{
|
|||||||
*/
|
*/
|
||||||
public function sendData(?array $targets, ?array $data = null) : void{
|
public function sendData(?array $targets, ?array $data = null) : void{
|
||||||
$targets = $targets ?? $this->hasSpawned;
|
$targets = $targets ?? $this->hasSpawned;
|
||||||
$data = $data ?? $this->getSyncedNetworkData(false);
|
$data = $data ?? $this->getAllNetworkData();
|
||||||
|
|
||||||
foreach($targets as $p){
|
foreach($targets as $p){
|
||||||
$p->getNetworkSession()->syncActorData($this, $data);
|
$p->getNetworkSession()->syncActorData($this, $data);
|
||||||
@ -1568,10 +1568,18 @@ abstract class Entity{
|
|||||||
* @return MetadataProperty[]
|
* @return MetadataProperty[]
|
||||||
* @phpstan-return array<int, MetadataProperty>
|
* @phpstan-return array<int, MetadataProperty>
|
||||||
*/
|
*/
|
||||||
final protected function getSyncedNetworkData(bool $dirtyOnly) : array{
|
final protected function getDirtyNetworkData() : array{
|
||||||
$this->syncNetworkData($this->networkProperties);
|
$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{
|
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||||
|
@ -399,7 +399,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
|||||||
$pk->yaw = $this->location->yaw;
|
$pk->yaw = $this->location->yaw;
|
||||||
$pk->pitch = $this->location->pitch;
|
$pk->pitch = $this->location->pitch;
|
||||||
$pk->item = TypeConverter::getInstance()->coreItemStackToNet($this->getInventory()->getItemInHand());
|
$pk->item = TypeConverter::getInstance()->coreItemStackToNet($this->getInventory()->getItemInHand());
|
||||||
$pk->metadata = $this->getSyncedNetworkData(false);
|
$pk->metadata = $this->getAllNetworkData();
|
||||||
$player->getNetworkSession()->sendDataPacket($pk);
|
$player->getNetworkSession()->sendDataPacket($pk);
|
||||||
|
|
||||||
//TODO: Hack for MCPE 1.2.13: DATA_NAMETAG is useless in AddPlayerPacket, so it has to be sent separately
|
//TODO: Hack for MCPE 1.2.13: DATA_NAMETAG is useless in AddPlayerPacket, so it has to be sent separately
|
||||||
|
@ -210,7 +210,7 @@ class ItemEntity extends Entity{
|
|||||||
$pk->position = $this->location->asVector3();
|
$pk->position = $this->location->asVector3();
|
||||||
$pk->motion = $this->getMotion();
|
$pk->motion = $this->getMotion();
|
||||||
$pk->item = TypeConverter::getInstance()->coreItemStackToNet($this->getItem());
|
$pk->item = TypeConverter::getInstance()->coreItemStackToNet($this->getItem());
|
||||||
$pk->metadata = $this->getSyncedNetworkData(false);
|
$pk->metadata = $this->getAllNetworkData();
|
||||||
|
|
||||||
$player->getNetworkSession()->sendDataPacket($pk);
|
$player->getNetworkSession()->sendDataPacket($pk);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user