示例#1
0
        public ChunkColumn GenerateChunkColumn(ChunkCoordinates chunkCoordinates)
        {
            var sw           = Stopwatch.StartNew();
            var playerCoords = (BlockCoordinates)chunkCoordinates;

            var movePlayerPacket = McpeMovePlayer.CreateObject();

            movePlayerPacket.runtimeEntityId = _client.EntityId;
            movePlayerPacket.x = playerCoords.X;
            movePlayerPacket.y = 255;
            movePlayerPacket.z = playerCoords.Z;
            _client.SendPacket(movePlayerPacket);

            int         count = 0;
            ChunkColumn chunk = null;

            while (count++ < 100 && !_client.Chunks.TryGetValue(chunkCoordinates, out chunk))
            {
                Thread.Sleep(50);
            }

            if (chunk == null)
            {
                Log.Warn($"Failed to locate chunk {chunkCoordinates}. Tried {count} times");
            }
            else
            {
                Log.Debug($"Successful return of chunk {chunkCoordinates} in {sw.ElapsedMilliseconds}ms. Tried {count} times");
            }

            return(chunk);
        }
示例#2
0
        private static void SendCommand(MiNetClient client, string command)
        {
            var request = new McpeCommandRequest();

            request.command     = command;
            request.unknownUuid = new UUID(Guid.NewGuid().ToString());
            client.SendPacket(request);
        }
示例#3
0
        public ChunkColumn GenerateChunkColumn(ChunkCoordinates chunkCoordinates)
        {
            var sw           = Stopwatch.StartNew();
            var playerCoords = (BlockCoordinates)chunkCoordinates;

            if (_client.Chunks.TryGetValue(chunkCoordinates, out ChunkColumn chunk))
            {
                Log.Debug($"Successful return of chunk {chunkCoordinates} from cache.");
                _client.Chunks.TryRemove(chunkCoordinates, out _);
                return(chunk);
            }

            _client.Chunks.TryAdd(chunkCoordinates, null);             // register to receive chunks.

            var movePlayerPacket = McpeMovePlayer.CreateObject();

            movePlayerPacket.runtimeEntityId = _client.EntityId;
            movePlayerPacket.x = playerCoords.X;
            movePlayerPacket.y = 255;
            movePlayerPacket.z = playerCoords.Z;
            _client.SendPacket(movePlayerPacket);

            while (sw.ElapsedMilliseconds < 2000)
            {
                _client.Chunks.TryGetValue(chunkCoordinates, out chunk);
                if (chunk != null)
                {
                    break;
                }
                Thread.Sleep(50);
            }

            if (chunk == null)
            {
                Log.Warn($"Failed to locate chunk {chunkCoordinates}. Tried {sw.ElapsedMilliseconds}ms");
            }
            else
            {
                Log.Debug($"Successful return of chunk {chunkCoordinates} in {sw.ElapsedMilliseconds}ms. Have {_client.Chunks.Count} chunks in memory now.");
            }

            return(chunk);
        }