コード例 #1
0
 // TODO: Find a better way
 private void WorldSpawnEntityRequested(object sender, SpawnEntityEventArgs e)
 {
     if (e.Entity is Entity)
     {
         EntityManager.SpawnEntity(sender as World, e.Entity as Entity);
     }
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: MinecraftServer.cs プロジェクト: Zynx87/Craft.Net
 /// <summary>
 /// Adds a worldBlockChangedr's list of worlds.
 /// </summary>
 public void AddLevel(Level level)
 {
     level.World.BlockChanged += HandleOnBlockChanged;
     level.World.SpawnEntity  += (sender, args) =>
                                 EntityManager.SpawnEntity(sender as World, args.Entity);
     level.World.DestroyEntity += (sender, args) =>
                                  EntityManager.DespawnEntity(sender as World, args.Entity);
     WeatherManagers.Add(new WeatherManager(level.World, this));
     Levels.Add(level);
 }
コード例 #4
0
        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.");
            }
        }
コード例 #5
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));
            }
        }