private void GameTick(object state) { if (World == null) { return; } if (_initiated) { _tickTime++; if (World.Player != null && Client.HasSpawned) { // player.IsSpawned = Spawned; if (World.Player.IsFlying != _flying) { _flying = World.Player.IsFlying; McpeAdventureSettings settings = McpeAdventureSettings.CreateObject(); settings.flags = GetAdventureFlags(); Client.SendPacket(settings); //SendPlayerAbilities(player); } var pos = (PlayerLocation)World.Player.KnownPosition.Clone(); if (pos.DistanceTo(_lastSentLocation) > 0.0f || MathF.Abs(pos.HeadYaw - _lastSentLocation.HeadYaw) > 0.0f || MathF.Abs(pos.Pitch - _lastSentLocation.Pitch) > 0.0f) { SendLocation(pos); _lastSentLocation = pos; } if ((pos.DistanceTo(_lastLocation) > 16f || MathF.Abs(pos.HeadYaw - _lastLocation.HeadYaw) >= 5.0f) && (_tickTime - _lastPrioritization >= 10)) { World.ChunkManager.FlagPrioritization(); SendLocation(pos); _lastLocation = pos; UnloadChunks(new ChunkCoordinates(pos), Client.ChunkRadius + 3); _lastPrioritization = _tickTime; } } if (_tickTime % 20 == 0 && CustomConnectedPong.CanPing) { Client.SendPing(); } World.Player.OnTick(); World.EntityManager.Tick(); World.PhysicsEngine.Tick(); } }
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(); } } } }
private void SendLocation(PlayerLocation location) { Client.SendMcpeMovePlayer(new MiNET.Utils.PlayerLocation(location.X, location.Y + Player.EyeLevel, location.Z, location.HeadYaw, location.Yaw, location.Pitch), location.OnGround); }
private void GameTick(object state) { var isRealTick = _isRealTick; _isRealTick = !isRealTick; if (World == null) { return; } if (_initiated) { if (_isRealTick) { _tickTime++; } var p = World.Player; if (p != null && p is Player player && Client.HasSpawned) { // player.IsSpawned = Spawned; if (player.IsFlying != _flying && _isRealTick) { _flying = player.IsFlying; McpeAdventureSettings settings = McpeAdventureSettings.CreateObject(); settings.flags = GetAdventureFlags(); Client.SendPacket(settings); //SendPlayerAbilities(player); } var pos = (PlayerLocation)player.KnownPosition.Clone(); if (pos.DistanceTo(_lastSentLocation) > 0.0f) { Client.SendMcpeMovePlayer(new MiNET.Utils.PlayerLocation(pos.X, pos.Y + Player.EyeLevel, pos.Z, pos.HeadYaw, pos.Yaw, -pos.Pitch), player.KnownPosition.OnGround); _lastSentLocation = pos; } if ((pos.DistanceTo(_lastLocation) > 16f || MathF.Abs(pos.HeadYaw - _lastLocation.HeadYaw) >= 10f) && (_tickTime - _lastPrioritization >= 10 && _isRealTick)) { World.ChunkManager.FlagPrioritization(); _lastLocation = pos; UnloadChunks(new ChunkCoordinates(pos), Client.ChunkRadius + 3); _lastPrioritization = _tickTime; } } if (_isRealTick && _tickTime % 20 == 0 && CustomConnectedPong.CanPing) { Client.SendPing(); } if (_isRealTick) { World.Player.OnTick(); World.EntityManager.Tick(); World.PhysicsEngine.Tick(); } } }