/// <summary> /// Deletes a chunk from the underlying data store 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 was deleted; 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 DeleteChunk(int lcx, int lcz) { if (!LocalBoundsCheck(lcx, lcz)) { IRegion alt = GetForeignRegion(lcx, lcz); return((alt == null) ? false : alt.DeleteChunk(ForeignX(lcx), ForeignZ(lcz))); } RegionFile rf = GetRegionFile(); if (!rf.HasChunk(lcx, lcz)) { return(false); } rf.DeleteChunk(lcx, lcz); ChunkKey k = new ChunkKey(ChunkGlobalX(lcx), ChunkGlobalZ(lcz)); _cache.Remove(k); if (ChunkCount() == 0) { _regionMan.DeleteRegion(X, Z); _regionFile.Target = null; } return(true); }
/// <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)); }
/// <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); }
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); } } } }