PocketMine-MP 5.44.4 git-6a7cc02e9dff59b69241aa0bcffdb9903ce86beb
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
50use Ramsey\Uuid\Uuid;
51use function sprintf;
52
56#[SilentDiscard(PlayerAuthInputPacket::class, comment: "Spammed after StartGame even though player has no controls")]
57#[SilentDiscard(ServerboundLoadingScreenPacket::class, "Not needed")]
59 public function __construct(
60 private Server $server,
61 private Player $player,
62 private NetworkSession $session,
63 private InventoryManager $inventoryManager
64 ){}
65
66 public function setUp() : void{
67 Timings::$playerNetworkSendPreSpawnGameData->startTiming();
68 try{
69 $location = $this->player->getLocation();
70 $world = $location->getWorld();
71
72 $typeConverter = $this->session->getTypeConverter();
73
74 $this->session->getLogger()->debug("Preparing StartGamePacket");
75 $levelSettings = new LevelSettings();
76 $levelSettings->seed = -1;
77 $levelSettings->spawnSettings = new SpawnSettings(SpawnSettings::BIOME_TYPE_DEFAULT, "", DimensionIds::OVERWORLD); //TODO: implement this properly
78 $levelSettings->worldGamemode = $typeConverter->coreGameModeToProtocol($this->server->getGamemode());
79 $levelSettings->difficulty = $world->getDifficulty();
80 $levelSettings->spawnPosition = BlockPosition::fromVector3($world->getSpawnLocation());
81 $levelSettings->hasAchievementsDisabled = true;
82 $levelSettings->time = $world->getTime();
83 $levelSettings->eduEditionOffer = 0;
84 $levelSettings->rainLevel = 0; //TODO: implement these properly
85 $levelSettings->lightningLevel = 0;
86 $levelSettings->commandsEnabled = true;
87 $levelSettings->gameRules = [
88 "naturalregeneration" => new BoolGameRule(false, false), //Hack for client side regeneration
89 "locatorbar" => new BoolGameRule(false, false) //Disable client-side tracking of nearby players
90 ];
91 $levelSettings->experiments = new Experiments([], false);
92
93 $this->session->sendDataPacket(StartGamePacket::create(
94 $this->player->getId(),
95 $this->player->getId(),
96 $typeConverter->coreGameModeToProtocol($this->player->getGamemode()),
97 $this->player->getOffsetPosition($location),
98 $location->pitch,
99 $location->yaw,
100 new CacheableNbt(CompoundTag::create()), //TODO: we don't care about this right now
101 $levelSettings,
102 "",
103 $this->server->getMotd(),
104 "",
105 false,
106 new PlayerMovementSettings(0, true),
107 0,
108 0,
109 "",
110 true,
111 sprintf("%s %s", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true)),
112 Uuid::fromString(Uuid::NIL),
113 false,
114 false,
115 new NetworkPermissions(disableClientSounds: true),
116 true,
117 null,
118 new ServerTelemetryData("", "", "", ""),
119 [],
120 0,
121 ));
122
123 $this->session->getLogger()->debug("Sending items");
124 $this->session->sendDataPacket(ItemRegistryPacket::create($typeConverter->getItemTypeDictionary()->getEntries()));
125
126 $this->session->getLogger()->debug("Sending actor identifiers");
127 $this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers());
128
129 $this->session->getLogger()->debug("Sending biome definitions");
130 $this->session->sendDataPacket(StaticPacketCache::getInstance()->getBiomeDefs());
131
132 $this->session->getLogger()->debug("Sending attributes");
133 $this->session->getEntityEventBroadcaster()->syncAttributes([$this->session], $this->player, $this->player->getAttributeMap()->getAll());
134
135 $this->session->getLogger()->debug("Sending available commands");
136 $this->session->syncAvailableCommands();
137
138 $this->session->getLogger()->debug("Sending abilities");
139 $this->session->syncAbilities($this->player);
140 $this->session->syncAdventureSettings();
141
142 $this->session->getLogger()->debug("Sending effects");
143 foreach($this->player->getEffects()->all() as $effect){
144 $this->session->getEntityEventBroadcaster()->onEntityEffectAdded([$this->session], $this->player, $effect, false);
145 }
146
147 $this->session->getLogger()->debug("Sending actor metadata");
148 $this->player->sendData([$this->player]);
149
150 $this->session->getLogger()->debug("Sending inventory");
151 $this->inventoryManager->syncAll();
152 $this->inventoryManager->syncSelectedHotbarSlot();
153
154 $this->session->getLogger()->debug("Sending creative inventory data");
155 $this->inventoryManager->syncCreative();
156
157 $this->session->getLogger()->debug("Sending crafting data");
158 $this->session->sendDataPacket(CraftingDataCache::getInstance()->getCache($this->server->getCraftingManager()));
159
160 $this->session->getLogger()->debug("Sending player list");
161 $this->session->syncPlayerList($this->server->getOnlinePlayers());
162 }finally{
163 Timings::$playerNetworkSendPreSpawnGameData->stopTiming();
164 }
165 }
166
167 public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
168 $this->player->setViewDistance($packet->radius);
169
170 return true;
171 }
172}
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, bool $isLoggingChat, ?ServerJoinInformation $serverJoinInformation, ServerTelemetryData $serverTelemetryData, array $blockPalette, int $blockPaletteChecksum,)