PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
UpdateEquipPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
23
25 public const NETWORK_ID = ProtocolInfo::UPDATE_EQUIP_PACKET;
26
27 public int $windowId;
28 public int $windowType;
29 public int $windowSlotCount; //useless, seems to be part of a standard container header
30 public int $actorUniqueId;
33
38 public static function create(int $windowId, int $windowType, int $windowSlotCount, int $actorUniqueId, CacheableNbt $nbt) : self{
39 $result = new self;
40 $result->windowId = $windowId;
41 $result->windowType = $windowType;
42 $result->windowSlotCount = $windowSlotCount;
43 $result->actorUniqueId = $actorUniqueId;
44 $result->nbt = $nbt;
45 return $result;
46 }
47
48 protected function decodePayload(ByteBufferReader $in) : void{
49 $this->windowId = Byte::readUnsigned($in);
50 $this->windowType = Byte::readUnsigned($in);
51 $this->windowSlotCount = VarInt::readSignedInt($in);
52 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
53 $this->nbt = new CacheableNbt(CommonTypes::getNbtCompoundRoot($in));
54 }
55
56 protected function encodePayload(ByteBufferWriter $out) : void{
57 Byte::writeUnsigned($out, $this->windowId);
58 Byte::writeUnsigned($out, $this->windowType);
59 VarInt::writeSignedInt($out, $this->windowSlotCount);
60 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
61 $out->writeByteArray($this->nbt->getEncodedNbt());
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleUpdateEquip($this);
66 }
67}
static create(int $windowId, int $windowType, int $windowSlotCount, int $actorUniqueId, CacheableNbt $nbt)