コード例 #1
0
        public void LoadRegion(int RegionX, int RegionZ)
        {
            SetSegmentOffset(RegionX, RegionZ, 0, 0);

            if (lastX != RegionX || lastZ != RegionZ)
            {
                lastX = RegionX;
                lastZ = RegionZ;

                FileInfo f = new FileInfo(Path.Combine(mcaFilePath, $@"r.{lastX}.{lastZ}.mca"));

                LastModified = DateTime.MaxValue;

                if (f.Exists)
                {
                    LastModified = f.LastWriteTime;

                    for (int c = 0; c < 1024; c++)
                    {
                        chunks[c] = null;
                    }

                    Count = 0;


                    using (FileStream fs = f.OpenRead())
                    {
                        for (int c = 0; c < 1024; c++)
                        {
                            chunkhdr[c]  = NbtReader.TagInt24(fs) * 4096;
                            chunksect[c] = NbtReader.TagByte(fs) * 4096;
                        }

                        for (int c = 0; c < 1024; c++)
                        {
                            timehdr[c] = DateTime.FromBinary(NbtReader.TagInt(fs));
                        }


                        for (int c = 0; c < 1024; c++)
                        {
                            try
                            {
                                fs.Seek(chunkhdr[c], SeekOrigin.Begin);
                                chunks[c] = new ChunkMCA(chunkhdr[c], chunksect[c], fs);
                                Count    += 1;
                            }
                            catch (Exception)
                            {
                                break;
                            }
                        }

                        fs.Close();
                    }
                }
            }
        }
コード例 #2
0
        public void LoadRegion(Stream Data, int RegionX, int RegionZ, DateTime Modified)
        {
            SetSegmentOffset(RegionX, RegionZ, 0, 0);

            if (lastX != RegionX || lastZ != RegionZ)
            {
                lastX = RegionX;
                lastZ = RegionZ;

                LastModified = Modified;


                for (int c = 0; c < 1024; c++)
                {
                    chunks[c] = null;
                }

                Count = 0;


                using (Stream fs = Data)
                {
                    for (int c = 0; c < 1024; c++)
                    {
                        chunkhdr[c]  = NbtReader.TagInt24(fs) * 4096;
                        chunksect[c] = NbtReader.TagByte(fs) * 4096;
                    }

                    for (int c = 0; c < 1024; c++)
                    {
                        timehdr[c] = DateTime.FromBinary(NbtReader.TagInt(fs));
                    }


                    for (int c = 0; c < 1024; c++)
                    {
                        try
                        {
                            fs.Seek(chunkhdr[c], SeekOrigin.Begin);
                            chunks[c] = new ChunkMCA(chunkhdr[c], chunksect[c], fs);
                            Count    += 1;
                        }
                        catch (Exception)
                        {
                            break;
                        }
                    }

                    fs.Close();
                }
            }
        }