PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ChangeDimensionPacket.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\LE;
20use pmmp\encoding\VarInt;
23
25 public const NETWORK_ID = ProtocolInfo::CHANGE_DIMENSION_PACKET;
26
27 public int $dimension;
28 public Vector3 $position;
29 public bool $respawn = false;
30 private ?int $loadingScreenId = null;
31
35 public static function create(int $dimension, Vector3 $position, bool $respawn, ?int $loadingScreenId) : self{
36 $result = new self;
37 $result->dimension = $dimension;
38 $result->position = $position;
39 $result->respawn = $respawn;
40 $result->loadingScreenId = $loadingScreenId;
41 return $result;
42 }
43
44 public function getLoadingScreenId() : ?int{ return $this->loadingScreenId; }
45
46 protected function decodePayload(ByteBufferReader $in) : void{
47 $this->dimension = VarInt::readSignedInt($in);
48 $this->position = CommonTypes::getVector3($in);
49 $this->respawn = CommonTypes::getBool($in);
50 $this->loadingScreenId = CommonTypes::readOptional($in, LE::readUnsignedInt(...));
51 }
52
53 protected function encodePayload(ByteBufferWriter $out) : void{
54 VarInt::writeSignedInt($out, $this->dimension);
55 CommonTypes::putVector3($out, $this->position);
56 CommonTypes::putBool($out, $this->respawn);
57 CommonTypes::writeOptional($out, $this->loadingScreenId, LE::writeUnsignedInt(...));
58 }
59
60 public function handle(PacketHandlerInterface $handler) : bool{
61 return $handler->handleChangeDimension($this);
62 }
63}
static create(int $dimension, Vector3 $position, bool $respawn, ?int $loadingScreenId)