player = $player; $this->server = $server; $this->session = $session; } public function setUp() : void{ $spawnPosition = $this->player->getSpawn(); $pk = new StartGamePacket(); $pk->entityUniqueId = $this->player->getId(); $pk->entityRuntimeId = $this->player->getId(); $pk->playerGamemode = NetworkSession::getClientFriendlyGamemode($this->player->getGamemode()); $pk->playerPosition = $this->player->getOffsetPosition($this->player); $pk->pitch = $this->player->pitch; $pk->yaw = $this->player->yaw; $pk->seed = -1; $pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly $pk->worldGamemode = NetworkSession::getClientFriendlyGamemode($this->server->getGamemode()); $pk->difficulty = $this->player->getWorld()->getDifficulty(); $pk->spawnX = $spawnPosition->getFloorX(); $pk->spawnY = $spawnPosition->getFloorY(); $pk->spawnZ = $spawnPosition->getFloorZ(); $pk->hasAchievementsDisabled = true; $pk->time = $this->player->getWorld()->getTime(); $pk->eduMode = false; $pk->rainLevel = 0; //TODO: implement these properly $pk->lightningLevel = 0; $pk->commandsEnabled = true; $pk->levelId = ""; $pk->worldName = $this->server->getMotd(); $this->session->sendDataPacket($pk); $this->session->sendDataPacket(new AvailableActorIdentifiersPacket()); $this->session->sendDataPacket(new BiomeDefinitionListPacket()); $this->player->setImmobile(); //HACK: fix client-side falling pre-spawn $this->session->syncAttributes($this->player, true); $this->session->syncAvailableCommands(); $this->session->syncAdventureSettings($this->player); foreach($this->player->getEffects()->all() as $effect){ $this->session->onEntityEffectAdded($this->player, $effect, false); } $this->player->sendData($this->player); $this->session->getInvManager()->syncAll(); $this->session->getInvManager()->syncCreative(); $this->session->getInvManager()->syncSelectedHotbarSlot(); $this->session->queueCompressed($this->server->getCraftingManager()->getCraftingDataPacket()); $this->session->syncPlayerList(); } public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{ $this->player->setViewDistance($packet->radius); return true; } public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{ $this->player->setImmobile(false); //HACK: this is set to prevent client-side falling before spawn $this->session->onSpawn(); return true; } }