Esempio n. 1
0
        protected override void HandlePacket(Packet packet)
        {
            if (packet == null)
            {
                return;
            }

            switch (ConnectionState)
            {
            case ConnectionState.Handshake:
                WorldReceiver.HandleHandshake(packet);
                break;

            case ConnectionState.Status:
                WorldReceiver.HandleStatus(packet);
                break;

            case ConnectionState.Login:
                WorldReceiver.HandleLogin(packet);
                break;

            case ConnectionState.Play:
                WorldReceiver.HandlePlay(packet);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 2
0
        protected override void Initiate(out LevelInfo info, out IChatProvider chatProvider)
        {
            info                 = new LevelInfo();
            chatProvider         = Client;
            _initiated           = true;
            Client.WorldReceiver = WorldReceiver;
            WorldReceiver?.UpdatePlayerPosition(new API.Utils.PlayerLocation(
                                                    new Vector3(Client.CurrentLocation.X, Client.CurrentLocation.Y, Client.CurrentLocation.Z),
                                                    Client.CurrentLocation.HeadYaw, Client.CurrentLocation.Yaw, Client.CurrentLocation.Pitch));

            _gameTickTimer = new System.Threading.Timer(GameTick, null, 50, 50);
        }
Esempio n. 3
0
        private void GameTick(object state)
        {
            if (WorldReceiver == null)
            {
                return;
            }

            if (_initiated)
            {
                var p = WorldReceiver.GetPlayerEntity();
                if (p != null && p is Player player && Client.HasSpawned)
                {
                    //	player.IsSpawned = Spawned;

                    if (player.IsFlying != _flying)
                    {
                        _flying = player.IsFlying;

                        McpeAdventureSettings settings = McpeAdventureSettings.CreateObject();
                        settings.flags = GetAdventureFlags();
                        Client.SendPacket(settings);
                        //SendPlayerAbilities(player);
                    }

                    var pos = (PlayerLocation)player.KnownPosition.Clone();
                    Client.CurrentLocation = new MiNET.Utils.PlayerLocation(pos.X,
                                                                            pos.Y + Player.EyeLevel, pos.Z, pos.HeadYaw,
                                                                            pos.Yaw, -pos.Pitch);

                    if (pos.DistanceTo(_lastSentLocation) > 0.0f)
                    {
                        Client.SendMcpeMovePlayer();
                    }

                    if (pos.DistanceTo(_lastLocation) > 16f && _stopwatch.ElapsedMilliseconds > 500)
                    {
                        _stopwatch.Stop();
                        _stopwatch.Reset();
                        _lastLocation = pos;
                        UnloadChunks(new ChunkCoordinates(pos), Client.ChunkRadius);
                        _stopwatch.Restart();
                    }
                }
            }
        }
Esempio n. 4
0
        protected override void Initiate(out LevelInfo info, out IChatProvider chatProvider)
        {
            info         = _generator.GetInfo();
            chatProvider = null;

            /*lock (genLock)
             * {
             *      while (_preGeneratedChunks.TryDequeue(out ChunkColumn chunk))
             *      {
             *              if (chunk != null)
             *              {
             *                      base.LoadChunk(chunk, chunk.X, chunk.Z, false);
             *                      LoadEntities(chunk);
             *              }
             *      }
             *
             *      _preGeneratedChunks = null;
             * }*/

            UpdateThread = new Thread(RunThread)
            {
                IsBackground = true
            };

            UpdateThread.Start();

            if (WorldReceiver is World world)
            {
                world.Player.CanFly               = true;
                world.Player.IsFlying             = true;
                world.Player.Controller.IsFreeCam = true;
            }

            WorldReceiver?.UpdatePlayerPosition(new PlayerLocation(GetSpawnPoint()));

            Log.Info($"World {info.LevelName} loaded!");
        }
Esempio n. 5
0
 public void DespawnEntity(long entityId)
 {
     WorldReceiver.DespawnEntity(entityId);
 }
Esempio n. 6
0
 public void SpawnEntity(long entityId, IEntity entity)
 {
     WorldReceiver.SpawnEntity(entityId, entity);
 }
Esempio n. 7
0
 protected void UnloadChunk(int x, int z)
 {
     WorldReceiver.ChunkUnload(x, z);
 }
Esempio n. 8
0
 protected void LoadChunk(IChunkColumn chunk, int x, int z, bool update)
 {
     WorldReceiver.ChunkReceived(chunk, x, z, update);
 }