PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
ClientboundDataDrivenUIShowScreenPacket.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\LE;
21
23 public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_DATA_DRIVEN_UI_SHOW_SCREEN_PACKET;
24
25 private string $screenId;
26 private int $formId;
27 private ?int $dataInstanceId;
28
32 public static function create(string $screenId, int $formId, ?int $dataInstanceId) : self{
33 $result = new self;
34 $result->screenId = $screenId;
35 $result->formId = $formId;
36 $result->dataInstanceId = $dataInstanceId;
37 return $result;
38 }
39
40 public function getScreenId() : string{ return $this->screenId; }
41
42 public function getFormId() : int{ return $this->formId; }
43
44 public function getDataInstanceId() : ?int{ return $this->dataInstanceId; }
45
46 protected function decodePayload(ByteBufferReader $in) : void{
47 $this->screenId = CommonTypes::getString($in);
48 $this->formId = LE::readUnsignedInt($in);
49 $this->dataInstanceId = CommonTypes::readOptional($in, LE::readUnsignedInt(...));
50 }
51
52 protected function encodePayload(ByteBufferWriter $out) : void{
53 CommonTypes::putString($out, $this->screenId);
54 LE::writeUnsignedInt($out, $this->formId);
55 CommonTypes::writeOptional($out, $this->dataInstanceId, LE::writeUnsignedInt(...));
56 }
57
58 public function handle(PacketHandlerInterface $handler) : bool{
59 return $handler->handleClientboundDataDrivenUIShowScreen($this);
60 }
61}