PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
UpdateAttributesPacket.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;
22use function count;
23
25 public const NETWORK_ID = ProtocolInfo::UPDATE_ATTRIBUTES_PACKET;
26
27 public int $actorRuntimeId;
29 public array $entries = [];
30 public int $tick = 0;
31
36 public static function create(int $actorRuntimeId, array $entries, int $tick) : self{
37 $result = new self;
38 $result->actorRuntimeId = $actorRuntimeId;
39 $result->entries = $entries;
40 $result->tick = $tick;
41 return $result;
42 }
43
44 protected function decodePayload(ByteBufferReader $in) : void{
45 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
46 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
47 $this->entries[] = UpdateAttribute::read($in);
48 }
49 $this->tick = VarInt::readUnsignedLong($in);
50 }
51
52 protected function encodePayload(ByteBufferWriter $out) : void{
53 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
54 VarInt::writeUnsignedInt($out, count($this->entries));
55 foreach($this->entries as $entry){
56 $entry->write($out);
57 }
58 VarInt::writeUnsignedLong($out, $this->tick);
59 }
60
61 public function handle(PacketHandlerInterface $handler) : bool{
62 return $handler->handleUpdateAttributes($this);
63 }
64}
static create(int $actorRuntimeId, array $entries, int $tick)