PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
PreSpawnPacketHandler.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\network\mcpe\handler;
25
42use pocketmine\network\mcpe\protocol\types\ServerAuthMovementMode;
48use Ramsey\Uuid\Uuid;
49use function sprintf;
50
55 public function __construct(
56 private Server $server,
57 private Player $player,
58 private NetworkSession $session,
59 private InventoryManager $inventoryManager
60 ){}
61
62 public function setUp() : void{
63 Timings::$playerNetworkSendPreSpawnGameData->startTiming();
64 try{
65 $location = $this->player->getLocation();
66 $world = $location->getWorld();
67
68 $typeConverter = $this->session->getTypeConverter();
69
70 $this->session->getLogger()->debug("Preparing StartGamePacket");
71 $levelSettings = new LevelSettings();
72 $levelSettings->seed = -1;
73 $levelSettings->spawnSettings = new SpawnSettings(SpawnSettings::BIOME_TYPE_DEFAULT, "", DimensionIds::OVERWORLD); //TODO: implement this properly
74 $levelSettings->worldGamemode = $typeConverter->coreGameModeToProtocol($this->server->getGamemode());
75 $levelSettings->difficulty = $world->getDifficulty();
76 $levelSettings->spawnPosition = BlockPosition::fromVector3($world->getSpawnLocation());
77 $levelSettings->hasAchievementsDisabled = true;
78 $levelSettings->time = $world->getTime();
79 $levelSettings->eduEditionOffer = 0;
80 $levelSettings->rainLevel = 0; //TODO: implement these properly
81 $levelSettings->lightningLevel = 0;
82 $levelSettings->commandsEnabled = true;
83 $levelSettings->gameRules = [
84 "naturalregeneration" => new BoolGameRule(false, false) //Hack for client side regeneration
85 ];
86 $levelSettings->experiments = new Experiments([], false);
87
88 $this->session->sendDataPacket(StartGamePacket::create(
89 $this->player->getId(),
90 $this->player->getId(),
91 $typeConverter->coreGameModeToProtocol($this->player->getGamemode()),
92 $this->player->getOffsetPosition($location),
93 $location->pitch,
94 $location->yaw,
95 new CacheableNbt(CompoundTag::create()), //TODO: we don't care about this right now
96 $levelSettings,
97 "",
98 $this->server->getMotd(),
99 "",
100 false,
101 new PlayerMovementSettings(ServerAuthMovementMode::SERVER_AUTHORITATIVE_V2, 0, false),
102 0,
103 0,
104 "",
105 true,
106 sprintf("%s %s", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true)),
107 Uuid::fromString(Uuid::NIL),
108 false,
109 false,
110 new NetworkPermissions(disableClientSounds: true),
111 [],
112 0,
113 $typeConverter->getItemTypeDictionary()->getEntries(),
114 ));
115
116 $this->session->getLogger()->debug("Sending actor identifiers");
117 $this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers());
118
119 $this->session->getLogger()->debug("Sending biome definitions");
120 $this->session->sendDataPacket(StaticPacketCache::getInstance()->getBiomeDefs());
121
122 $this->session->getLogger()->debug("Sending attributes");
123 $this->session->getEntityEventBroadcaster()->syncAttributes([$this->session], $this->player, $this->player->getAttributeMap()->getAll());
124
125 $this->session->getLogger()->debug("Sending available commands");
126 $this->session->syncAvailableCommands();
127
128 $this->session->getLogger()->debug("Sending abilities");
129 $this->session->syncAbilities($this->player);
130 $this->session->syncAdventureSettings();
131
132 $this->session->getLogger()->debug("Sending effects");
133 foreach($this->player->getEffects()->all() as $effect){
134 $this->session->getEntityEventBroadcaster()->onEntityEffectAdded([$this->session], $this->player, $effect, false);
135 }
136
137 $this->session->getLogger()->debug("Sending actor metadata");
138 $this->player->sendData([$this->player]);
139
140 $this->session->getLogger()->debug("Sending inventory");
141 $this->inventoryManager->syncAll();
142 $this->inventoryManager->syncSelectedHotbarSlot();
143
144 $this->session->getLogger()->debug("Sending creative inventory data");
145 $this->inventoryManager->syncCreative();
146
147 $this->session->getLogger()->debug("Sending crafting data");
148 $this->session->sendDataPacket(CraftingDataCache::getInstance()->getCache($this->server->getCraftingManager()));
149
150 $this->session->getLogger()->debug("Sending player list");
151 $this->session->syncPlayerList($this->server->getOnlinePlayers());
152 }finally{
153 Timings::$playerNetworkSendPreSpawnGameData->stopTiming();
154 }
155 }
156
157 public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
158 $this->player->setViewDistance($packet->radius);
159
160 return true;
161 }
162
163 public function handlePlayerAuthInput(PlayerAuthInputPacket $packet) : bool{
164 //the client will send this every tick once we start sending chunks, but we don't handle it in this stage
165 //this is very spammy so we filter it out
166 return true;
167 }
168}
static create(int $actorUniqueId, int $actorRuntimeId, int $playerGamemode, Vector3 $playerPosition, float $pitch, float $yaw, CacheableNbt $playerActorProperties, LevelSettings $levelSettings, string $levelId, string $worldName, string $premiumWorldTemplateId, bool $isTrial, PlayerMovementSettings $playerMovementSettings, int $currentTick, int $enchantmentSeed, string $multiplayerCorrelationId, bool $enableNewInventorySystem, string $serverSoftwareVersion, UuidInterface $worldTemplateId, bool $enableClientSideChunkGeneration, bool $blockNetworkIdsAreHashes, NetworkPermissions $networkPermissions, array $blockPalette, int $blockPaletteChecksum, array $itemTable,)