private Region LoadOrGenerateRegion(Coordinates2D coordinates, bool generate = true) { if (Regions.ContainsKey(coordinates)) { return((Region)Regions[coordinates]); } if (!generate) { return(null); } Region region; if (BaseDirectory != null) { var file = Path.Combine(BaseDirectory, Region.GetRegionFileName(coordinates)); if (File.Exists(file)) { region = new Region(coordinates, this, file); } else { region = new Region(coordinates, this); } } else { region = new Region(coordinates, this); } lock (Regions) Regions[coordinates] = region; return(region); }
public void UnloadRegion(Coordinates2D coordinates) { lock (Regions) { Regions[coordinates].Save(Path.Combine(BaseDirectory, Region.GetRegionFileName(coordinates))); Regions.Remove(coordinates); } }
public void Save() { lock (Regions) { foreach (var region in Regions) { region.Value.Save(Path.Combine(BaseDirectory, Region.GetRegionFileName(region.Key))); } } var file = new NbtFile(); file.RootTag.Add(new NbtCompound("SpawnPoint", new[] { new NbtInt("X", this.SpawnPoint.X), new NbtInt("Y", this.SpawnPoint.Y), new NbtInt("Z", this.SpawnPoint.Z) })); file.RootTag.Add(new NbtInt("Seed", this.Seed)); file.RootTag.Add(new NbtString("ChunkProvider", this.ChunkProvider.GetType().FullName)); file.SaveToFile(Path.Combine(this.BaseDirectory, "manifest.nbt"), NbtCompression.ZLib); }