PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ContainerOpenPacket.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;
22
24 public const NETWORK_ID = ProtocolInfo::CONTAINER_OPEN_PACKET;
25
26 public int $windowId;
27 public int $windowType;
28 public BlockPosition $blockPosition;
29 public int $actorUniqueId = -1;
30
34 private static function create(int $windowId, int $windowType, BlockPosition $blockPosition, int $actorUniqueId) : self{
35 $result = new self;
36 $result->windowId = $windowId;
37 $result->windowType = $windowType;
38 $result->blockPosition = $blockPosition;
39 $result->actorUniqueId = $actorUniqueId;
40 return $result;
41 }
42
43 public static function blockInv(int $windowId, int $windowType, BlockPosition $blockPosition) : self{
44 return self::create($windowId, $windowType, $blockPosition, -1);
45 }
46
47 public static function entityInv(int $windowId, int $windowType, int $actorUniqueId) : self{
48 return self::create($windowId, $windowType, new BlockPosition(0, 0, 0), $actorUniqueId);
49 }
50
51 protected function decodePayload(ByteBufferReader $in) : void{
52 $this->windowId = Byte::readUnsigned($in);
53 $this->windowType = Byte::readUnsigned($in);
54 $this->blockPosition = CommonTypes::getBlockPosition($in);
55 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
56 }
57
58 protected function encodePayload(ByteBufferWriter $out) : void{
59 Byte::writeUnsigned($out, $this->windowId);
60 Byte::writeUnsigned($out, $this->windowType);
61 CommonTypes::putBlockPosition($out, $this->blockPosition);
62 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
63 }
64
65 public function handle(PacketHandlerInterface $handler) : bool{
66 return $handler->handleContainerOpen($this);
67 }
68}