PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
SetPlayerInventoryOptionsPacket.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;
21use pocketmine\network\mcpe\protocol\types\inventory\InventoryLayout;
22use pocketmine\network\mcpe\protocol\types\inventory\InventoryLeftTab;
23use pocketmine\network\mcpe\protocol\types\inventory\InventoryRightTab;
24
26 public const NETWORK_ID = ProtocolInfo::SET_PLAYER_INVENTORY_OPTIONS_PACKET;
27
28 private InventoryLeftTab $leftTab;
29 private InventoryRightTab $rightTab;
30 private bool $filtering;
31 private InventoryLayout $inventoryLayout;
32 private InventoryLayout $craftingLayout;
33
37 public static function create(InventoryLeftTab $leftTab, InventoryRightTab $rightTab, bool $filtering, InventoryLayout $inventoryLayout, InventoryLayout $craftingLayout) : self{
38 $result = new self;
39 $result->leftTab = $leftTab;
40 $result->rightTab = $rightTab;
41 $result->filtering = $filtering;
42 $result->inventoryLayout = $inventoryLayout;
43 $result->craftingLayout = $craftingLayout;
44 return $result;
45 }
46
47 public function getLeftTab() : InventoryLeftTab{ return $this->leftTab; }
48
49 public function getRightTab() : InventoryRightTab{ return $this->rightTab; }
50
51 public function isFiltering() : bool{ return $this->filtering; }
52
53 public function getInventoryLayout() : InventoryLayout{ return $this->inventoryLayout; }
54
55 public function getCraftingLayout() : InventoryLayout{ return $this->craftingLayout; }
56
57 protected function decodePayload(ByteBufferReader $in) : void{
58 $this->leftTab = InventoryLeftTab::fromPacket(VarInt::readSignedInt($in));
59 $this->rightTab = InventoryRightTab::fromPacket(VarInt::readSignedInt($in));
60 $this->filtering = CommonTypes::getBool($in);
61 $this->inventoryLayout = InventoryLayout::fromPacket(VarInt::readSignedInt($in));
62 $this->craftingLayout = InventoryLayout::fromPacket(VarInt::readSignedInt($in));
63 }
64
65 protected function encodePayload(ByteBufferWriter $out) : void{
66 VarInt::writeSignedInt($out, $this->leftTab->value);
67 VarInt::writeSignedInt($out, $this->rightTab->value);
68 CommonTypes::putBool($out, $this->filtering);
69 VarInt::writeSignedInt($out, $this->inventoryLayout->value);
70 VarInt::writeSignedInt($out, $this->craftingLayout->value);
71 }
72
73 public function handle(PacketHandlerInterface $handler) : bool{
74 return $handler->handleSetPlayerInventoryOptions($this);
75 }
76}
static create(InventoryLeftTab $leftTab, InventoryRightTab $rightTab, bool $filtering, InventoryLayout $inventoryLayout, InventoryLayout $craftingLayout)