Пример #1
0
        public ChunkData GetOverworldChunkData(int x, int z)
        {
            if (db == null)
            {
                throw new InvalidOperationException("Open Db first");
            }

            var ret = new ChunkData();
            var key = CreateKey(x, z);

            for (byte subChunkIdx = 0; subChunkIdx < 15; subChunkIdx++)
            {
                key[9] = subChunkIdx;
                UIntPtr length;
                var     data = db.Get(key, out length);
                if (data != null)
                {
                    var subChunkData = new SubChunkData()
                    {
                        Index      = subChunkIdx,
                        Data       = data,
                        DataLength = (int)length,
                        Key        = key,
                        Crc32      = Force.Crc32.Crc32CAlgorithm.Compute(data, 0, (int)length)
                    };
                    ret.SubChunks.Add(subChunkData);
                }
            }

            return(ret);
        }
Пример #2
0
        public ChunkData GetChunkData(IGrouping <ulong, LevelDbWorldKey2> groupedChunkSubKeys)
        {
            if (db == null)
            {
                throw new InvalidOperationException("Open Db first");
            }

            var ret = new ChunkData
            {
                X = (int)((ulong)groupedChunkSubKeys.Key >> 32),
                Z = (int)((ulong)groupedChunkSubKeys.Key & 0xffffffff)
            };


            foreach (var kvp in groupedChunkSubKeys)
            {
                var     key = kvp;
                UIntPtr length;
                var     data = db.Get(key.Key, out length);
                if (data != null)
                {
                    var subChunkData = new SubChunkData()
                    {
                        Index      = key.SubChunkId,
                        Data       = data,
                        DataLength = (int)length,
                        Key        = key.Key,
                        Crc32      = Force.Crc32.Crc32CAlgorithm.Compute(data, 0, (int)length),
                    };
                    ret.SubChunks.Add(subChunkData);
                }
            }

            return(ret);
        }
Пример #3
0
        public ChunkData GetChunkData(int x, int z)
        {
            if (db == null)
            {
                throw new InvalidOperationException("Open Db first");
            }

            var ret = new ChunkData
            {
                X = x,
                Z = z,
            };


            foreach (var kvp in Enumerable.Range(0, 15))
            {
                var key = CreateKey(x, z);
                key[9] = (byte)kvp;

                var data = db.Get(key);
                if (data != null)
                {
                    var subChunkData = new SubChunkData()
                    {
                        Index = (byte)kvp,
                        Data  = data,
                        Key   = key,
                        Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data),
                    };
                    ret.SubChunks.Add(subChunkData);
                }
            }

            return(ret);
        }
Пример #4
0
        public ChunkData GetChunkData(GroupedChunkSubKeys groupedChunkSubKeys)
        {
            if (db == null)
            {
                throw new InvalidOperationException("Open Db first");
            }

            var firstSubChunk = groupedChunkSubKeys.Subchunks.First();

            var ret = new ChunkData
            {
                X = firstSubChunk.Value.X,
                Z = firstSubChunk.Value.Z
            };


            foreach (var kvp in groupedChunkSubKeys.Subchunks)
            {
                var     key = kvp.Value;
                UIntPtr length;
                var     data = db.Get(key.Key, out length);
                if (data != null)
                {
                    var subChunkData = new SubChunkData()
                    {
                        Index      = kvp.Key,
                        Data       = data,
                        DataLength = (int)length,
                        Key        = kvp.Value.Key,
                        Crc32      = Force.Crc32.Crc32CAlgorithm.Compute(data, 0, (int)length),
                    };
                    ret.SubChunks.Add(subChunkData);
                }
            }

            return(ret);
        }