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