mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-28 06:09:57 +00:00
NetworkSession: allow sending an arbitrary set of attributes for an entity
This commit is contained in:
parent
f6f714c158
commit
d1b28ce17a
@ -680,12 +680,14 @@ class NetworkSession{
|
|||||||
$this->sendDataPacket($pk);
|
$this->sendDataPacket($pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function syncAttributes(Living $entity, bool $sendAll = false) : void{
|
/**
|
||||||
$entries = $sendAll ? $entity->getAttributeMap()->getAll() : $entity->getAttributeMap()->needSend();
|
* @param Attribute[] $attributes
|
||||||
if(count($entries) > 0){
|
*/
|
||||||
|
public function syncAttributes(Living $entity, array $attributes) : void{
|
||||||
|
if(count($attributes) > 0){
|
||||||
$this->sendDataPacket(UpdateAttributesPacket::create($entity->getId(), array_map(function(Attribute $attr) : NetworkAttribute{
|
$this->sendDataPacket(UpdateAttributesPacket::create($entity->getId(), 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());
|
||||||
}, $entries)));
|
}, $attributes)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ class PreSpawnPacketHandler extends PacketHandler{
|
|||||||
|
|
||||||
$this->player->setImmobile(); //HACK: fix client-side falling pre-spawn
|
$this->player->setImmobile(); //HACK: fix client-side falling pre-spawn
|
||||||
|
|
||||||
$this->session->syncAttributes($this->player, true);
|
$this->session->syncAttributes($this->player, $this->player->getAttributeMap()->getAll());
|
||||||
$this->session->syncAvailableCommands();
|
$this->session->syncAvailableCommands();
|
||||||
$this->session->syncAdventureSettings($this->player);
|
$this->session->syncAdventureSettings($this->player);
|
||||||
foreach($this->player->getEffects()->all() as $effect){
|
foreach($this->player->getEffects()->all() as $effect){
|
||||||
|
@ -1291,8 +1291,9 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$this->lastUpdate = $currentTick;
|
$this->lastUpdate = $currentTick;
|
||||||
|
|
||||||
//TODO: move this to network session ticking (this is specifically related to net sync)
|
//TODO: move this to network session ticking (this is specifically related to net sync)
|
||||||
$this->networkSession->syncAttributes($this);
|
$dirtyAttributes = $this->attributeMap->needSend();
|
||||||
foreach($this->attributeMap->getAll() as $attribute){
|
$this->networkSession->syncAttributes($this, $dirtyAttributes);
|
||||||
|
foreach($dirtyAttributes as $attribute){
|
||||||
$attribute->markSynchronized();
|
$attribute->markSynchronized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user