public void WriteToFile(File path) { // Write region file RegionFile regionFile = new RegionFile(path); try { for (int x = 0; x < ChunksPerRegionSide; x++) { for (int z = 0; z < ChunksPerRegionSide; z++) { Chunk chunk = _chunks.Get(x, z); if (chunk == null || !chunk.HasBlocks) { continue; } NBTOutputStream outt = new NBTOutputStream(regionFile.GetChunkDataOutputStream(x, z), false); try { outt.writeTag(_chunks.Get(x, z).Tag); } finally { outt.close(); } } } } finally { regionFile.Close(); } }
public File Save() { // Creates worlds directory File worldDir = new File("worlds"); if (!DirExists(worldDir)) { worldDir.mkdir(); } // Get level directory string levelName = _level.Name; File levelDir = new File(worldDir, levelName); if (DirExists(levelDir)) { int dirPostFix = 0; do { dirPostFix++; levelDir = new File(worldDir, levelName + dirPostFix); } while (DirExists(levelDir)); } // Create directories levelDir.mkdir(); File regionDir = new File(levelDir, "region"); regionDir.mkdir(); // Write session.lock File sessionLockFile = new File(levelDir, "session.lock"); DataOutputStream dos = new DataOutputStream(new FileOutputStream(sessionLockFile)); try { dos.writeLong(CurrentTimeMillis()); } finally { dos.close(); } // Write level.dat File levelFile = new File(levelDir, "level.dat"); FileOutputStream fos = new FileOutputStream(levelFile); NBTOutputStream nbtOut = new NBTOutputStream(fos, true); try { nbtOut.writeTag(_level.Tag); } finally { nbtOut.close(); } // Calculate height maps foreach (Region region in _regions.Values) { region.CalculateHeightMap(); } // Set sky light AddSkyLight(); // Spread sky light for (int i = DefaultSkyLight; i > 1; i--) { SpreadSkyLight((byte)i); } // Iterate regions for (int index = 0; index <= _regions.Count - 1; index++) { Point point = _regions.Keys.ToList()[index]; Region region = _regions.Values.ToList()[index]; // Save region File regionFile = new File(regionDir, "r." + point.X + "." + point.Y + ".mca"); region.WriteToFile(regionFile); } return(levelDir); }