PocketMine-MP 5.40.1 git-25718e8ccd903d1408fb25666ef84028379bbea6
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 null,
117 new ServerTelemetryData("", "", "", ""),
118 [],
119 0,
120 ));
121
122 $this->session->getLogger()->debug("Sending items");
123 $this->session->sendDataPacket(ItemRegistryPacket::create($typeConverter->getItemTypeDictionary()->getEntries()));
124
125 $this->session->getLogger()->debug("Sending actor identifiers");
126 $this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers());
127
128 $this->session->getLogger()->debug("Sending biome definitions");
129 $this->session->sendDataPacket(StaticPacketCache::getInstance()->getBiomeDefs());
130
131 $this->session->getLogger()->debug("Sending attributes");
132 $this->session->getEntityEventBroadcaster()->syncAttributes([$this->session], $this->player, $this->player->getAttributeMap()->getAll());
133
134 $this->session->getLogger()->debug("Sending available commands");
135 $this->session->syncAvailableCommands();
136
137 $this->session->getLogger()->debug("Sending abilities");
138 $this->session->syncAbilities($this->player);
139 $this->session->syncAdventureSettings();
140
141 $this->session->getLogger()->debug("Sending effects");
142 foreach($this->player->getEffects()->all() as $effect){
143 $this->session->getEntityEventBroadcaster()->onEntityEffectAdded([$this->session], $this->player, $effect, false);
144 }
145
146 $this->session->getLogger()->debug("Sending actor metadata");
147 $this->player->sendData([$this->player]);
148
149 $this->session->getLogger()->debug("Sending inventory");
150 $this->inventoryManager->syncAll();
151 $this->inventoryManager->syncSelectedHotbarSlot();
152
153 $this->session->getLogger()->debug("Sending creative inventory data");
154 $this->inventoryManager->syncCreative();
155
156 $this->session->getLogger()->debug("Sending crafting data");
157 $this->session->sendDataPacket(CraftingDataCache::getInstance()->getCache($this->server->getCraftingManager()));
158
159 $this->session->getLogger()->debug("Sending player list");
160 $this->session->syncPlayerList($this->server->getOnlinePlayers());
161 }finally{
162 Timings::$playerNetworkSendPreSpawnGameData->stopTiming();
163 }
164 }
165
166 public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
167 $this->player->setViewDistance($packet->radius);
168
169 return true;
170 }
171}
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, ?ServerJoinInformation $serverJoinInformation, ServerTelemetryData $serverTelemetryData, array $blockPalette, int $blockPaletteChecksum,)