PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
AddVolumeEntityPacket.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\VarInt;
23
25 public const NETWORK_ID = ProtocolInfo::ADD_VOLUME_ENTITY_PACKET;
26
27 private int $entityNetId;
29 private CacheableNbt $data;
30 private string $jsonIdentifier;
31 private string $instanceName;
32 private BlockPosition $minBound;
33 private BlockPosition $maxBound;
34 private int $dimension;
35 private string $engineVersion;
36
41 public static function create(
42 int $entityNetId,
43 CacheableNbt $data,
44 string $jsonIdentifier,
45 string $instanceName,
46 BlockPosition $minBound,
47 BlockPosition $maxBound,
48 int $dimension,
49 string $engineVersion,
50 ) : self{
51 $result = new self;
52 $result->entityNetId = $entityNetId;
53 $result->data = $data;
54 $result->jsonIdentifier = $jsonIdentifier;
55 $result->instanceName = $instanceName;
56 $result->minBound = $minBound;
57 $result->maxBound = $maxBound;
58 $result->dimension = $dimension;
59 $result->engineVersion = $engineVersion;
60 return $result;
61 }
62
63 public function getEntityNetId() : int{ return $this->entityNetId; }
64
66 public function getData() : CacheableNbt{ return $this->data; }
67
68 public function getJsonIdentifier() : string{ return $this->jsonIdentifier; }
69
70 public function getInstanceName() : string{ return $this->instanceName; }
71
72 public function getMinBound() : BlockPosition{ return $this->minBound; }
73
74 public function getMaxBound() : BlockPosition{ return $this->maxBound; }
75
76 public function getDimension() : int{ return $this->dimension; }
77
78 public function getEngineVersion() : string{ return $this->engineVersion; }
79
80 protected function decodePayload(ByteBufferReader $in) : void{
81 $this->entityNetId = VarInt::readUnsignedInt($in);
82 $this->data = new CacheableNbt(CommonTypes::getNbtCompoundRoot($in));
83 $this->jsonIdentifier = CommonTypes::getString($in);
84 $this->instanceName = CommonTypes::getString($in);
85 $this->minBound = CommonTypes::getBlockPosition($in);
86 $this->maxBound = CommonTypes::getBlockPosition($in);
87 $this->dimension = VarInt::readSignedInt($in);
88 $this->engineVersion = CommonTypes::getString($in);
89 }
90
91 protected function encodePayload(ByteBufferWriter $out) : void{
92 VarInt::writeUnsignedInt($out, $this->entityNetId);
93 $out->writeByteArray($this->data->getEncodedNbt());
94 CommonTypes::putString($out, $this->jsonIdentifier);
95 CommonTypes::putString($out, $this->instanceName);
96 CommonTypes::putBlockPosition($out, $this->minBound);
97 CommonTypes::putBlockPosition($out, $this->maxBound);
98 VarInt::writeSignedInt($out, $this->dimension);
99 CommonTypes::putString($out, $this->engineVersion);
100 }
101
102 public function handle(PacketHandlerInterface $handler) : bool{
103 return $handler->handleAddVolumeEntity($this);
104 }
105}
static create(int $entityNetId, CacheableNbt $data, string $jsonIdentifier, string $instanceName, BlockPosition $minBound, BlockPosition $maxBound, int $dimension, string $engineVersion,)