PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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
19
21 public const NETWORK_ID = ProtocolInfo::CONTAINER_OPEN_PACKET;
22
23 public int $windowId;
24 public int $windowType;
25 public BlockPosition $blockPosition;
26 public int $actorUniqueId = -1;
27
31 private static function create(int $windowId, int $windowType, BlockPosition $blockPosition, int $actorUniqueId) : self{
32 $result = new self;
33 $result->windowId = $windowId;
34 $result->windowType = $windowType;
35 $result->blockPosition = $blockPosition;
36 $result->actorUniqueId = $actorUniqueId;
37 return $result;
38 }
39
40 public static function blockInv(int $windowId, int $windowType, BlockPosition $blockPosition) : self{
41 return self::create($windowId, $windowType, $blockPosition, -1);
42 }
43
44 public static function entityInv(int $windowId, int $windowType, int $actorUniqueId) : self{
45 return self::create($windowId, $windowType, new BlockPosition(0, 0, 0), $actorUniqueId);
46 }
47
48 protected function decodePayload(PacketSerializer $in) : void{
49 $this->windowId = $in->getByte();
50 $this->windowType = $in->getByte();
51 $this->blockPosition = $in->getBlockPosition();
52 $this->actorUniqueId = $in->getActorUniqueId();
53 }
54
55 protected function encodePayload(PacketSerializer $out) : void{
56 $out->putByte($this->windowId);
57 $out->putByte($this->windowType);
58 $out->putBlockPosition($this->blockPosition);
59 $out->putActorUniqueId($this->actorUniqueId);
60 }
61
62 public function handle(PacketHandlerInterface $handler) : bool{
63 return $handler->handleContainerOpen($this);
64 }
65}