public void ToNbtTest() { var levelInfo = new LevelInfoBedrock(); levelInfo.GameType = 1; levelInfo.Generator = 1; levelInfo.LastPlayed = 1594911609; levelInfo.LevelName = "BedrockGeneratedLevel"; levelInfo.Platform = 2; levelInfo.RandomSeed = 3429004588; levelInfo.SpawnX = 44; levelInfo.SpawnY = 32767; levelInfo.SpawnZ = 4; levelInfo.Time = 269000; levelInfo.SpawnMobs = 1; NbtTag nbt = levelInfo.Serialize(); Console.WriteLine(nbt); Assert.IsNotNull(nbt); Assert.IsInstanceOfType(nbt, typeof(NbtCompound)); Assert.AreEqual(levelInfo.GameType, nbt["GameType"].IntValue); Assert.AreEqual(levelInfo.Generator, nbt["Generator"].IntValue); Assert.AreEqual(levelInfo.LevelName, nbt["LevelName"].StringValue); var file = new NbtFile { BigEndian = false, UseVarInt = false, }; file.RootTag = nbt; var bytes = file.SaveToBuffer(NbtCompression.None); using FileStream stream = File.Create(@"C:\Temp\TrashBedrockWorld\level_test_generated.dat"); stream.Write(new ReadOnlySpan <byte>(new byte[] { 0x08, 0, 0, 0 })); stream.Write(BitConverter.GetBytes(bytes.Length)); stream.Write(bytes); stream.Flush(); }
public static LevelInfoBedrock FromNbt(NbtTag tag) { LevelInfoBedrock obj = tag.Deserialize <LevelInfoBedrock>(); return(obj); }