internal void LogInPlayer(MinecraftClient client) { client.IsLoggedIn = true; // Spawn player client.Entity = DefaultLevel.LoadPlayer(client.Username); client.Entity.Username = client.Username; client.Entity.InventoryChanged += EntityInventoryChanged; EntityManager.SpawnEntity(DefaultWorld, client.Entity); client.SendPacket(new LoginRequestPacket(client.Entity.Id, DefaultWorld.LevelType, DefaultLevel.GameMode, client.Entity.Dimension, Settings.Difficulty, Settings.MaxPlayers)); client.SendPacket(new SpawnPositionPacket((int)client.Entity.SpawnPoint.X, (int)client.Entity.SpawnPoint.Y, (int)client.Entity.SpawnPoint.Z)); client.SendPacket(new TimeUpdatePacket(DefaultLevel.Time, DefaultLevel.Time)); UpdatePlayerList(null); client.SendPacket(new SetWindowItemsPacket(0, client.Entity.Inventory.GetSlots())); // Send initial chunks client.UpdateChunks(true); client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y, client.Entity.Position.Z, client.Entity.Position.Y - 1.62, client.Entity.Yaw, client.Entity.Pitch, true)); // TODO: Move 1.62 somewhere else // Send entities EntityManager.SendClientEntities(client); client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation)); var args = new PlayerLogInEventArgs(client); OnPlayerLoggedIn(args); LogProvider.Log(client.Username + " joined the game."); if (!args.Handled) SendChat(ChatColors.Yellow + client.Username + " joined the game."); client.StartWorkers(); }
internal void LogInPlayer(MinecraftClient client) { client.IsLoggedIn = true; // Spawn player client.Entity = DefaultLevel.LoadPlayer(client.Username); client.Entity.Username = client.Username; client.Entity.InventoryChanged += EntityInventoryChanged; EntityManager.SpawnEntity(DefaultWorld, client.Entity); client.SendPacket(new LoginPacket(client.Entity.Id, DefaultWorld.LevelType, DefaultLevel.GameMode, client.Entity.Dimension, Settings.Difficulty, Settings.MaxPlayers)); // Send initial chunks client.UpdateChunks(true); client.SendPacket(new PlayerPositionAndLookPacket( client.Entity.Position, client.Entity.Yaw, client.Entity.Pitch, true)); client.SendQueue.Last().OnPacketSent += (sender, e) => { client.ReadyToSpawn = true; }; // Send entities EntityManager.SendClientEntities(client); client.SendPacket(new SetWindowItemsPacket(0, client.Entity.Inventory.GetSlots())); client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation)); client.SendPacket(new SpawnPositionPacket(client.Entity.SpawnPoint)); client.SendPacket(new TimeUpdatePacket(DefaultLevel.Time)); UpdatePlayerList(null); // Should also process send queue var args = new PlayerLogInEventArgs(client); OnPlayerLoggedIn(args); LogProvider.Log(client.Username + " logged in."); if (!args.Handled) SendChat(client.Username + " logged in."); client.StartWorkers(); }