22declare(strict_types=1);
24namespace pocketmine\network\mcpe;
47use
function array_map;
50use
const SORT_NUMERIC;
54 public function __construct(
62 private function sendDataPacket(array $recipients,
ClientboundPacket $packet) :
void{
63 $this->broadcaster->broadcastPackets($recipients, [$packet]);
67 if(count($attributes) > 0){
70 array_map(fn(
Attribute $attr) =>
new UpdateAttribute($attr->getId(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getValue(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getDefaultValue(), []), $attributes),
79 ksort($properties, SORT_NUMERIC);
88 EffectIdMap::getInstance()->toId($effect->getType()),
89 $effect->getAmplifier(),
91 $effect->getDuration(),
97 $this->sendDataPacket($recipients,
MobEffectPacket::remove($entity->getId(),
EffectIdMap::getInstance()->toId($effect->getType()), tick: 0));
106 $inv = $mob->getInventory();
107 $this->sendDataPacket($recipients, MobEquipmentPacket::create(
109 ItemStackWrapper::legacy($this->typeConverter->coreItemStackToNet($inv->getItemInHand())),
110 $inv->getHeldItemIndex(),
111 $inv->getHeldItemIndex(),
112 ContainerIds::INVENTORY
117 $inv = $mob->getOffHandInventory();
118 $this->sendDataPacket($recipients, MobEquipmentPacket::create(
120 ItemStackWrapper::legacy($this->typeConverter->coreItemStackToNet($inv->getItem(0))),
123 ContainerIds::OFFHAND
128 $inv = $mob->getArmorInventory();
129 $converter = $this->typeConverter;
130 $this->sendDataPacket($recipients, MobArmorEquipmentPacket::create(
132 ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getHelmet())),
133 ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getChestplate())),
134 ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getLeggings())),
135 ItemStackWrapper::legacy($converter->coreItemStackToNet($inv->getBoots())),
141 $this->sendDataPacket($recipients,
TakeItemActorPacket::create($collector->getId(), $pickedUp->getId()));
144 public function onEmote(array $recipients,
Human $from,
string $emoteId) : void{
145 $this->sendDataPacket($recipients,
EmotePacket::create(
onEntityEffectAdded(array $recipients, Living $entity, EffectInstance $effect, bool $replacesOldEffect)
syncAttributes(array $recipients, Living $entity, array $attributes)
onEmote(array $recipients, Human $from, string $emoteId)
syncActorData(array $recipients, Entity $entity, array $properties)
onMobOffHandItemChange(array $recipients, Human $mob)
onMobMainHandItemChange(array $recipients, Human $mob)
onMobArmorChange(array $recipients, Living $mob)
onEntityRemoved(array $recipients, Entity $entity)
onEntityEffectRemoved(array $recipients, Living $entity, EffectInstance $effect)
onPickUpItem(array $recipients, Entity $collector, Entity $pickedUp)
static create(int $actorRuntimeId, array $metadata, PropertySyncData $syncedProperties, int $tick)
static create(int $actorRuntimeId, array $entries, int $tick)