public void MoveClientToWorld(RemoteClient client, World world, Vector3?spawnPoint = null) { if (client.World == world) { return; } lock (client.LoadedChunks) client.PauseChunkUpdates = true; EntityManager.Despawn(client.Entity); while (client.KnownEntities.Any()) { client.ForgetEntity(EntityManager.GetEntityById(client.KnownEntities[0])); } EntityManager.Update(); EntityManager.SpawnEntity(world, client.Entity); client.UnloadAllChunks(); // TODO: Allow player to save their positions in each world if (spawnPoint == null) { client.Entity.Position = world.WorldGenerator.SpawnPoint; } else { client.Entity.Position = spawnPoint.Value; } client.UpdateChunks(true); client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y + 0.1 + PlayerEntity.Height, client.Entity.Position.Z, client.Entity.Position.Y + 0.1, client.Entity.Yaw, client.Entity.Pitch, false)); EntityManager.SendClientEntities(client); lock (client.LoadedChunks) client.PauseChunkUpdates = false; }
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, client.Entity.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.Size.Height, client.Entity.Position.Z, client.Entity.Position.Y - client.Entity.Size.Height, client.Entity.Yaw, client.Entity.Pitch, true)); // TODO: Move 1.62 somewhere else // Send entities EntityManager.SendClientEntities(client); //Send Weather GetWeatherManagerForWorld(client.World).SendCurrentWeatherToClient(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."); } }
internal void LogInPlayer(RemoteClient client) { client.SendPacket(new LoginSuccessPacket(client.UUID, client.Username)); // Spawn player Level.LoadPlayer(client); client.PlayerManager = new PlayerManager(client, this); EntityManager.SpawnEntity(Level.DefaultWorld, client.Entity); client.SendPacket(new JoinGamePacket(client.Entity.EntityId, client.GameMode, Dimension.Overworld, Settings.Difficulty, Settings.MaxPlayers, Level.DefaultWorld.WorldGenerator.GeneratorName)); client.SendPacket(new SpawnPositionPacket((int)client.Entity.SpawnPoint.X, (int)client.Entity.SpawnPoint.Y, (int)client.Entity.SpawnPoint.Z)); client.SendPacket(new PlayerAbilitiesPacket(client.Entity.Abilities.AsFlags(), client.Entity.Abilities.FlyingSpeed, client.Entity.Abilities.WalkingSpeed)); // Adding 0.1 to Y here prevents the client from falling through the ground upon logging in // Presumably, Minecraft runs some physics stuff and if it spawns exactly at ground level, it falls a little and // clips through the ground. This fixes that. client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y + 0.1 + PlayerEntity.Height, client.Entity.Position.Z, client.Entity.Position.Y + 0.1, client.Entity.Yaw, client.Entity.Pitch, false)); client.SendPacket(new TimeUpdatePacket(Level.Time, Level.Time)); client.SendPacket(new SetWindowItemsPacket(0, client.Entity.Inventory.GetSlots())); // Send initial chunks client.UpdateChunks(true); UpdatePlayerList(); client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation)); client.SendPacket(new EntityPropertiesPacket(client.Entity.EntityId, new[] { new EntityProperty("generic.movementSpeed", client.Entity.Abilities.WalkingSpeed) })); // Send entities EntityManager.SendClientEntities(client); client.LastKeepAliveSent = DateTime.Now; client.IsLoggedIn = true; var args = new PlayerLogInEventArgs(client); OnPlayerLoggedIn(args); //LogProvider.Log(client.Username + " joined the game."); if (!args.Handled) { SendChat(new ChatMessage(string.Format("{0} joined the game.", args.Username), ChatColor.YELLOW)); } }