PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
SetSpawnPositionPacket.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
20
22 public const NETWORK_ID = ProtocolInfo::SET_SPAWN_POSITION_PACKET;
23
24 public const TYPE_PLAYER_SPAWN = 0;
25 public const TYPE_WORLD_SPAWN = 1;
26
27 public int $spawnType;
28 public BlockPosition $spawnPosition;
29 public int $dimension;
36
40 private static function create(int $spawnType, BlockPosition $spawnPosition, int $dimension, BlockPosition $causingBlockPosition) : self{
41 $result = new self;
42 $result->spawnType = $spawnType;
43 $result->spawnPosition = $spawnPosition;
44 $result->dimension = $dimension;
45 $result->causingBlockPosition = $causingBlockPosition;
46 return $result;
47 }
48
49 public static function playerSpawn(BlockPosition $spawnPosition, int $dimension, BlockPosition $causingBlockPosition) : self{
50 return self::create(self::TYPE_PLAYER_SPAWN, $spawnPosition, $dimension, $causingBlockPosition);
51 }
52
53 public static function worldSpawn(BlockPosition $spawnPosition, int $dimension) : self{
54 return self::create(self::TYPE_WORLD_SPAWN, $spawnPosition, $dimension, new BlockPosition(Limits::INT32_MIN, Limits::INT32_MIN, Limits::INT32_MIN));
55 }
56
57 protected function decodePayload(PacketSerializer $in) : void{
58 $this->spawnType = $in->getVarInt();
59 $this->spawnPosition = $in->getBlockPosition();
60 $this->dimension = $in->getVarInt();
61 $this->causingBlockPosition = $in->getBlockPosition();
62 }
63
64 protected function encodePayload(PacketSerializer $out) : void{
65 $out->putVarInt($this->spawnType);
66 $out->putBlockPosition($this->spawnPosition);
67 $out->putVarInt($this->dimension);
68 $out->putBlockPosition($this->causingBlockPosition);
69 }
70
71 public function handle(PacketHandlerInterface $handler) : bool{
72 return $handler->handleSetSpawnPosition($this);
73 }
74}