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(); } }
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); }
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(); } } } }
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!"); }
public void DespawnEntity(long entityId) { WorldReceiver.DespawnEntity(entityId); }
public void SpawnEntity(long entityId, IEntity entity) { WorldReceiver.SpawnEntity(entityId, entity); }
protected void UnloadChunk(int x, int z) { WorldReceiver.ChunkUnload(x, z); }
protected void LoadChunk(IChunkColumn chunk, int x, int z, bool update) { WorldReceiver.ChunkReceived(chunk, x, z, update); }