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