public RegionChunkData(DataNode parent, RegionFile file, int x, int z)
     : base(parent)
 {
     Region = file;
     X = x;
     Z = z;
 }
 public RegionChunkDataNode(RegionFile regionFile, int x, int z)
 {
     _regionFile = regionFile;
     _x = x;
     _z = z;
     _container = new CompoundTagContainer(new TagNodeCompound());
 }
Example #3
0
 public ChunkBuffer(RegionFile r, int x, int z)
     : base(8096)
 {
     this.region = r;
     this.x      = x;
     this.z      = z;
 }
Example #4
0
        private RegionFile GetRegionFile()
        {
            RegionFile rf = _regionFile.Target as RegionFile;

            if (rf == null)
            {
                rf = new RegionFile(GetFilePath());
                _regionFile.Target = rf;
            }

            return(rf);
        }
Example #5
0
        /// <inherits />
        public Stream GetChunkOutStream(int lcx, int lcz)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? null : alt.GetChunkOutStream(ForeignX(lcx), ForeignZ(lcz)));
            }

            RegionFile rf = GetRegionFile();

            return(rf.GetChunkDataOutputStream(lcx, lcz));
        }
Example #6
0
        /// <summary>
        /// Checks if a chunk exists at the given local coordinates relative to this region.
        /// </summary>
        /// <param name="lcx">The local X-coordinate of a chunk relative to this region.</param>
        /// <param name="lcz">The local Z-coordinate of a chunk relative to this region.</param>
        /// <returns>True if there is a chunk at the given coordinates; false otherwise.</returns>
        /// <remarks>If the local coordinates are out of bounds for this region, the action will be forwarded to the correct region
        /// transparently.</remarks>
        public bool ChunkExists(int lcx, int lcz)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? false : alt.ChunkExists(ForeignX(lcx), ForeignZ(lcz)));
            }

            RegionFile rf = GetRegionFile();

            return(rf.HasChunk(lcx, lcz));
        }
Example #7
0
        /// <inherits />
        public int GetChunkTimestamp(int lcx, int lcz)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? 0 : alt.GetChunkTimestamp(ForeignX(lcx), ForeignZ(lcz)));
            }

            RegionFile rf = GetRegionFile();

            return(rf.GetTimestamp(lcx, lcz));
        }
Example #8
0
        /// <inherits />
        public void SetChunkTimestamp(int lcx, int lcz, int timestamp)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                if (alt != null)
                {
                    alt.SetChunkTimestamp(ForeignX(lcx), ForeignZ(lcz), timestamp);
                }
            }

            RegionFile rf = GetRegionFile();

            rf.SetTimestamp(lcx, lcz, timestamp);
        }
Example #9
0
        /// <inherits />
        public IRegion CreateRegion(int rx, int rz)
        {
            IRegion r = GetRegion(rx, rz);

            if (r == null)
            {
                string fp = "r." + rx + "." + rz + ".mca";
                using (RegionFile rf = CreateRegionFileCore(rx, rz)) {
                }

                r = CreateRegionCore(rx, rz);

                RegionKey k = new RegionKey(rx, rz);
                _cache[k] = r;
            }

            return(r);
        }
Example #10
0
        /// <inherits />
        public int ChunkCount()
        {
            RegionFile rf = GetRegionFile();

            int count = 0;

            for (int x = 0; x < XDIM; x++)
            {
                for (int z = 0; z < ZDIM; z++)
                {
                    if (rf.HasChunk(x, z))
                    {
                        count++;
                    }
                }
            }

            return(count);
        }
Example #11
0
        /// <summary>
        /// Conditionally dispose managed or unmanaged resources.
        /// </summary>
        /// <param name="disposing">True if the call to Dispose was explicit.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // Cleanup managed resources
                    RegionFile rf = _regionFile.Target as RegionFile;
                    if (rf != null)
                    {
                        rf.Dispose();
                        rf = null;
                    }
                }

                // Cleanup unmanaged resources
            }
            _disposed = true;
        }
Example #12
0
        protected override void ExpandCore()
        {
            try {
                if (_region == null)
                    _region = new RegionFile(_path);

                for (int x = 0; x < 32; x++) {
                    for (int z = 0; z < 32; z++) {
                        if (_region.HasChunk(x, z)) {
                            Nodes.Add(new RegionChunkDataNode(_region, x, z));
                        }
                    }
                }
            }
            catch {
                if (FormRegistry.MessageBox != null)
                    FormRegistry.MessageBox("Not a valid region file.");
            }
        }
Example #13
0
        /// <inherits />
        public NbtTree GetChunkTree(int lcx, int lcz)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? null : alt.GetChunkTree(ForeignX(lcx), ForeignZ(lcz)));
            }

            RegionFile rf     = GetRegionFile();
            Stream     nbtstr = rf.GetChunkDataInputStream(lcx, lcz);

            if (nbtstr == null)
            {
                return(null);
            }

            NbtTree tree = new NbtTree(nbtstr);

            nbtstr.Close();
            return(tree);
        }
Example #14
0
        private bool SaveChunkTree(int lcx, int lcz, NbtTree tree, int?timestamp)
        {
            if (!LocalBoundsCheck(lcx, lcz))
            {
                IRegion alt = GetForeignRegion(lcx, lcz);
                return((alt == null) ? false : alt.SaveChunkTree(ForeignX(lcx), ForeignZ(lcz), tree));
            }

            RegionFile rf     = GetRegionFile();
            Stream     zipstr = (timestamp == null)
                ? rf.GetChunkDataOutputStream(lcx, lcz)
                : rf.GetChunkDataOutputStream(lcx, lcz, (int)timestamp);

            if (zipstr == null)
            {
                return(false);
            }

            tree.WriteTo(zipstr);
            zipstr.Close();

            return(true);
        }
Example #15
0
 public ChunkBuffer(RegionFile r, int x, int z, int timestamp)
     : this(r, x, z)
 {
     _timestamp = timestamp;
 }
Example #16
0
 public ChunkBuffer(RegionFile r, int x, int z)
     : base(8096)
 {
     this.region = r;
     this.x = x;
     this.z = z;
 }
Example #17
0
        private RegionFile GetRegionFile()
        {
            RegionFile rf = _regionFile.Target as RegionFile;
            if (rf == null) {
                rf = new RegionFile(GetFilePath());
                _regionFile.Target = rf;
            }

            return rf;
        }
Example #18
0
 public ChunkBuffer(RegionFile r, int x, int z, int timestamp)
     : this(r, x, z)
 {
     _timestamp = timestamp;
 }
Example #19
0
 protected override void ReleaseCore()
 {
     if (_region != null)
         _region.Close();
     _region = null;
     Nodes.Clear();
 }
 internal static TreeNode CreateLazyChunk(RegionFile rf, int x, int z)
 {
     return InitializeParentNode(9, "Chunk [" + x + ", " + z + "]", new RegionChunkData(rf, x, z));
 }
        internal static void LoadRegion(TreeNode node, string path)
        {
            RegionFile rf = new RegionFile(path);

            for (int x = 0; x < 32; x++)
            {
                for (int y = 0; y < 32; y++)
                {
                    if (rf.HasChunk(x, y))
                    {
                        TreeNode child = CreateLazyChunk(rf, x, y);
                        node.Nodes.Add(child);
                        LinkDataNodeParent(child, node);
                    }
                }
            }
        }
 public RegionChunkData(RegionFile file, int x, int z)
     : this(null, file, x, z)
 {
 }
Example #23
0
 public ChunkBuffer(RegionFile r, int x, int z)
     : base(8096)
 {
     // super(8096); // initialize to 8KB
     this.region = r;
     this.x = x;
     this.z = z;
 }