PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
23
24class SetActorDataPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ //TODO: check why this is serverbound
25 public const NETWORK_ID = ProtocolInfo::SET_ACTOR_DATA_PACKET;
26
27 public int $actorRuntimeId;
32 public array $metadata;
33 public PropertySyncData $syncedProperties;
34 public int $tick = 0;
35
41 public static function create(int $actorRuntimeId, array $metadata, PropertySyncData $syncedProperties, int $tick) : self{
42 $result = new self;
43 $result->actorRuntimeId = $actorRuntimeId;
44 $result->metadata = $metadata;
45 $result->syncedProperties = $syncedProperties;
46 $result->tick = $tick;
47 return $result;
48 }
49
50 protected function decodePayload(ByteBufferReader $in) : void{
51 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
52 $this->metadata = CommonTypes::getEntityMetadata($in);
53 $this->syncedProperties = PropertySyncData::read($in);
54 $this->tick = VarInt::readUnsignedLong($in);
55 }
56
57 protected function encodePayload(ByteBufferWriter $out) : void{
58 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
59 CommonTypes::putEntityMetadata($out, $this->metadata);
60 $this->syncedProperties->write($out);
61 VarInt::writeUnsignedLong($out, $this->tick);
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleSetActorData($this);
66 }
67}
static create(int $actorRuntimeId, array $metadata, PropertySyncData $syncedProperties, int $tick)