PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
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
19
21 public const NETWORK_ID = ProtocolInfo::STRUCTURE_TEMPLATE_DATA_RESPONSE_PACKET;
22
23 public const TYPE_FAILURE = 0;
24 public const TYPE_EXPORT = 1;
25 public const TYPE_QUERY = 2;
26 public const TYPE_IMPORT = 3;
27
28 public string $structureTemplateName;
31 public int $responseType;
32
37 public static function create(string $structureTemplateName, ?CacheableNbt $nbt, int $responseType) : self{
38 $result = new self;
39 $result->structureTemplateName = $structureTemplateName;
40 $result->nbt = $nbt;
41 $result->responseType = $responseType;
42 return $result;
43 }
44
45 protected function decodePayload(PacketSerializer $in) : void{
46 $this->structureTemplateName = $in->getString();
47 if($in->getBool()){
48 $this->nbt = new CacheableNbt($in->getNbtCompoundRoot());
49 }
50 $this->responseType = $in->getByte();
51 }
52
53 protected function encodePayload(PacketSerializer $out) : void{
54 $out->putString($this->structureTemplateName);
55 $out->putBool($this->nbt !== null);
56 if($this->nbt !== null){
57 $out->put($this->nbt->getEncodedNbt());
58 }
59 $out->putByte($this->responseType);
60 }
61
62 public function handle(PacketHandlerInterface $handler) : bool{
63 return $handler->handleStructureTemplateDataResponse($this);
64 }
65}
static create(string $structureTemplateName, ?CacheableNbt $nbt, int $responseType)