PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
InventorySlotPacket.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
25 public const NETWORK_ID = ProtocolInfo::INVENTORY_SLOT_PACKET;
26
27 public int $windowId;
28 public int $inventorySlot;
29 public FullContainerName $containerName;
30 public ItemStackWrapper $storage;
31 public ItemStackWrapper $item;
32
36 public static function create(int $windowId, int $inventorySlot, FullContainerName $containerName, ItemStackWrapper $storage, ItemStackWrapper $item) : self{
37 $result = new self;
38 $result->windowId = $windowId;
39 $result->inventorySlot = $inventorySlot;
40 $result->containerName = $containerName;
41 $result->storage = $storage;
42 $result->item = $item;
43 return $result;
44 }
45
46 protected function decodePayload(ByteBufferReader $in) : void{
47 $this->windowId = VarInt::readUnsignedInt($in);
48 $this->inventorySlot = VarInt::readUnsignedInt($in);
49 $this->containerName = FullContainerName::read($in);
50 $this->storage = CommonTypes::getItemStackWrapper($in);
51 $this->item = CommonTypes::getItemStackWrapper($in);
52 }
53
54 protected function encodePayload(ByteBufferWriter $out) : void{
55 VarInt::writeUnsignedInt($out, $this->windowId);
56 VarInt::writeUnsignedInt($out, $this->inventorySlot);
57 $this->containerName->write($out);
58 CommonTypes::putItemStackWrapper($out, $this->storage);
59 CommonTypes::putItemStackWrapper($out, $this->item);
60 }
61
62 public function handle(PacketHandlerInterface $handler) : bool{
63 return $handler->handleInventorySlot($this);
64 }
65}
static create(int $windowId, int $inventorySlot, FullContainerName $containerName, ItemStackWrapper $storage, ItemStackWrapper $item)