PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
StructureTemplateDataRequestPacket.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;
23
25 public const NETWORK_ID = ProtocolInfo::STRUCTURE_TEMPLATE_DATA_REQUEST_PACKET;
26
27 public const TYPE_EXPORT_FROM_SAVE_MODE = 1;
28 public const TYPE_EXPORT_FROM_LOAD_MODE = 2;
29 public const TYPE_QUERY_SAVED_STRUCTURE = 3;
30
31 public string $structureTemplateName;
32 public BlockPosition $structureBlockPosition;
33 public StructureSettings $structureSettings;
34 public int $requestType;
35
39 public static function create(string $structureTemplateName, BlockPosition $structureBlockPosition, StructureSettings $structureSettings, int $requestType) : self{
40 $result = new self;
41 $result->structureTemplateName = $structureTemplateName;
42 $result->structureBlockPosition = $structureBlockPosition;
43 $result->structureSettings = $structureSettings;
44 $result->requestType = $requestType;
45 return $result;
46 }
47
48 protected function decodePayload(ByteBufferReader $in) : void{
49 $this->structureTemplateName = CommonTypes::getString($in);
50 $this->structureBlockPosition = CommonTypes::getBlockPosition($in);
51 $this->structureSettings = CommonTypes::getStructureSettings($in);
52 $this->requestType = Byte::readUnsigned($in);
53 }
54
55 protected function encodePayload(ByteBufferWriter $out) : void{
56 CommonTypes::putString($out, $this->structureTemplateName);
57 CommonTypes::putBlockPosition($out, $this->structureBlockPosition);
58 CommonTypes::putStructureSettings($out, $this->structureSettings);
59 Byte::writeUnsigned($out, $this->requestType);
60 }
61
62 public function handle(PacketHandlerInterface $handler) : bool{
63 return $handler->handleStructureTemplateDataRequest($this);
64 }
65}
static create(string $structureTemplateName, BlockPosition $structureBlockPosition, StructureSettings $structureSettings, int $requestType)