Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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(ChatColors.Yellow + client.Username + " joined the game.");
        }
Ejemplo n.º 4
0
 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;
 }