示例#1
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();
                    }
                }
            }
        }