PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
StructureTemplateDataResponsePacket.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::STRUCTURE_TEMPLATE_DATA_RESPONSE_PACKET;
25
26 public const TYPE_FAILURE = 0;
27 public const TYPE_EXPORT = 1;
28 public const TYPE_QUERY = 2;
29
30 public string $structureTemplateName;
33 public int $responseType;
34
39 public static function create(string $structureTemplateName, ?CacheableNbt $nbt, int $responseType) : self{
40 $result = new self;
41 $result->structureTemplateName = $structureTemplateName;
42 $result->nbt = $nbt;
43 $result->responseType = $responseType;
44 return $result;
45 }
46
47 protected function decodePayload(ByteBufferReader $in) : void{
48 $this->structureTemplateName = CommonTypes::getString($in);
49 if(CommonTypes::getBool($in)){
50 $this->nbt = new CacheableNbt(CommonTypes::getNbtCompoundRoot($in));
51 }
52 $this->responseType = Byte::readUnsigned($in);
53 }
54
55 protected function encodePayload(ByteBufferWriter $out) : void{
56 CommonTypes::putString($out, $this->structureTemplateName);
57 CommonTypes::putBool($out, $this->nbt !== null);
58 if($this->nbt !== null){
59 $out->writeByteArray($this->nbt->getEncodedNbt());
60 }
61 Byte::writeUnsigned($out, $this->responseType);
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleStructureTemplateDataResponse($this);
66 }
67}
static create(string $structureTemplateName, ?CacheableNbt $nbt, int $responseType)