PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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
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
27 public string $structureTemplateName;
30 public int $responseType;
31
36 public static function create(string $structureTemplateName, ?CacheableNbt $nbt, int $responseType) : self{
37 $result = new self;
38 $result->structureTemplateName = $structureTemplateName;
39 $result->nbt = $nbt;
40 $result->responseType = $responseType;
41 return $result;
42 }
43
44 protected function decodePayload(PacketSerializer $in) : void{
45 $this->structureTemplateName = $in->getString();
46 if($in->getBool()){
47 $this->nbt = new CacheableNbt($in->getNbtCompoundRoot());
48 }
49 $this->responseType = $in->getByte();
50 }
51
52 protected function encodePayload(PacketSerializer $out) : void{
53 $out->putString($this->structureTemplateName);
54 $out->putBool($this->nbt !== null);
55 if($this->nbt !== null){
56 $out->put($this->nbt->getEncodedNbt());
57 }
58 $out->putByte($this->responseType);
59 }
60
61 public function handle(PacketHandlerInterface $handler) : bool{
62 return $handler->handleStructureTemplateDataResponse($this);
63 }
64}
static create(string $structureTemplateName, ?CacheableNbt $nbt, int $responseType)