private void LoadFromFile(string directory) { NbtFile file = new NbtFile(); using (var stream = File.Open(Path.Combine(LevelDirectory, "level.dat"), FileMode.Open)) file.LoadFromStream(stream, NbtCompression.None, null); var data = file.RootTag.Get <NbtCompound>("Data"); var serializer = new NbtSerializer(typeof(SavedLevel)); SavedLevel level = (SavedLevel)serializer.Deserialize(data); Name = level.LevelName; Time = level.Time; GameMode = (GameMode)level.GameMode; MapFeatures = level.MapFeatures; Seed = level.Seed; // Find world generator string generatorName = level.GeneratorName; WorldGenerator = GetGenerator(generatorName); WorldGenerator.Seed = Seed; GeneratorOptions = level.GeneratorOptions; WorldGenerator.Initialize(this); SpawnPoint = level.SpawnPoint; World = new World(this, WorldGenerator, Path.Combine(directory, "region")); }
public void Save() { NbtFile file = new NbtFile(); var serializer = new NbtSerializer(typeof(SavedLevel)); var level = new SavedLevel { IsRaining = Raining, GeneratorVersion = 0, Time = Time, GameMode = (int)GameMode, MapFeatures = MapFeatures, GeneratorName = WorldGenerator.GeneratorName, Initialized = true, Seed = Seed, SpawnPoint = SpawnPoint, SizeOnDisk = 0, ThunderTime = ThunderTime, RainTime = RainTime, Version = 19133, Thundering = Thundering, LevelName = Name, LastPlayed = DateTime.UtcNow.Ticks }; if (!string.IsNullOrEmpty(PlayerName)) { if (File.Exists(Path.Combine(LevelDirectory, "players", PlayerName + ".dat"))) { var player = new NbtFile(); using (Stream stream = File.Open(Path.Combine(LevelDirectory, "players", PlayerName + ".dat"), FileMode.Open)) player.LoadFromStream(stream, NbtCompression.GZip, null); level.Player = player.RootTag; level.Player.Name = "Player"; } } var data = serializer.Serialize(level); file.RootTag = new NbtCompound(""); file.RootTag.Add(data); using (var stream = File.Create(Path.Combine(LevelDirectory, "level.dat"))) file.SaveToStream(stream, NbtCompression.GZip); if (World.Directory == null) { World.Save(Path.Combine(LevelDirectory, "region")); } else { World.Save(); } }
public void Save() { NbtFile file = new NbtFile(); var serializer = new NbtSerializer(typeof(SavedLevel)); var level = new SavedLevel { IsRaining = Raining, GeneratorVersion = 0, Time = Time, GameMode = (int)GameMode, MapFeatures = MapFeatures, GeneratorName = WorldGenerator.GeneratorName, Initialized = true, Seed = Seed, SpawnPoint = SpawnPoint, SizeOnDisk = 0, ThunderTime = ThunderTime, RainTime = RainTime, Version = 19133, Thundering = Thundering, LevelName = Name, LastPlayed = DateTime.UtcNow.Ticks }; if (!string.IsNullOrEmpty(PlayerName)) { if (File.Exists(Path.Combine(LevelDirectory, "players", PlayerName + ".dat"))) { var player = new NbtFile(); using (Stream stream = File.Open(Path.Combine(LevelDirectory, "players", PlayerName + ".dat"), FileMode.Open)) player.LoadFromStream(stream, NbtCompression.GZip, null); level.Player = player.RootTag; level.Player.Name = "Player"; } } var data = serializer.Serialize(level); file.RootTag = new NbtCompound(""); file.RootTag.Add(data); using (var stream = File.Create(Path.Combine(LevelDirectory, "level.dat"))) file.SaveToStream(stream, NbtCompression.GZip); if (World.Directory == null) World.Save(Path.Combine(LevelDirectory, "region")); else World.Save(); }