PocketMine-MP 5.19.1 git-5cc1068cd43264d3363295eb8d6901e02f467897
SetActorDataPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
20
21class SetActorDataPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ //TODO: check why this is serverbound
22 public const NETWORK_ID = ProtocolInfo::SET_ACTOR_DATA_PACKET;
23
24 public int $actorRuntimeId;
29 public array $metadata;
30 public PropertySyncData $syncedProperties;
31 public int $tick = 0;
32
38 public static function create(int $actorRuntimeId, array $metadata, PropertySyncData $syncedProperties, int $tick) : self{
39 $result = new self;
40 $result->actorRuntimeId = $actorRuntimeId;
41 $result->metadata = $metadata;
42 $result->syncedProperties = $syncedProperties;
43 $result->tick = $tick;
44 return $result;
45 }
46
47 protected function decodePayload(PacketSerializer $in) : void{
48 $this->actorRuntimeId = $in->getActorRuntimeId();
49 $this->metadata = $in->getEntityMetadata();
50 $this->syncedProperties = PropertySyncData::read($in);
51 $this->tick = $in->getUnsignedVarLong();
52 }
53
54 protected function encodePayload(PacketSerializer $out) : void{
55 $out->putActorRuntimeId($this->actorRuntimeId);
56 $out->putEntityMetadata($this->metadata);
57 $this->syncedProperties->write($out);
58 $out->putUnsignedVarLong($this->tick);
59 }
60
61 public function handle(PacketHandlerInterface $handler) : bool{
62 return $handler->handleSetActorData($this);
63 }
64}
static create(int $actorRuntimeId, array $metadata, PropertySyncData $syncedProperties, int $tick)