public void NBTJsonSerializerTests_DeserializeTest() { ListTag list = new ListTag("list", NBTTagType.INT); list.Add(new IntTag(12345)); list.Add(new IntTag(67890)); CompoundTag subTag = new CompoundTag(); subTag.PutBool("bool", true); subTag.PutByte("byte", 123); CompoundTag tag = new CompoundTag(); tag.PutBool("bool", true); tag.PutByte("byte", 123); tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200)); tag.PutShort("short", 12345); tag.PutInt("int", 12345678); tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200)); tag.PutLong("long", 123456789123456); tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200)); tag.PutFloat("float", 12.3456f); tag.PutDouble("double", 12.3456789); tag.PutList(list); tag.PutCompound("com", subTag); JObject json = NBTJsonSerializer.Serialize(tag); Console.WriteLine(NBTJsonSerializer.Serialize(NBTJsonSerializer.Deserialize(json)).ToString()); }
public void WriteRawFileTest() { ListTag list = new ListTag(Data.NBTTagType.BYTE); list.Name = "listTag"; list.Add(new ByteTag(0xff)); list.Add(new ByteTag(0x00)); list.Add(new ByteTag(0xff)); CompoundTag tag = new CompoundTag(); tag.PutBool("bool", true); tag.PutByte("byte", 0xff); tag.PutShort("short", 0x7fff); tag.PutInt("int", 0x7fffffff); tag.PutLong("long", 0x7fffffffffffffff); tag.PutFloat("float", 0.0001f); tag.PutDouble("double", 0.00000001d); tag.PutString("string", "Hello NBT"); tag.PutByteArray("byte[]", ArrayUtils.CreateArray <byte>(100, 0xff)); tag.PutIntArray("int[]", ArrayUtils.CreateArray <int>(100, 0x7fffffff)); tag.PutLongArray("long[]", ArrayUtils.CreateArray <long>(100, 0x7fffffffffffffff)); tag.PutList(list); NBTIO.WriteRawFile(Path + "\\" + "raw.nbt", tag); }
public void NBTIOTests_WriteGZFileTest() { ListTag list = new ListTag("list", NBTTagType.COMPOUND); list.Add(new CompoundTag().PutInt("c1", 123)); list.Add(new CompoundTag().PutLong("c2", 123456)); CompoundTag subTag = new CompoundTag(); subTag.PutBool("bool", true); subTag.PutByte("byte", 123); CompoundTag tag = new CompoundTag(); tag.PutBool("bool", true); tag.PutByte("byte", 123); tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200)); tag.PutShort("short", 12345); tag.PutInt("int", 12345678); tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200)); tag.PutLong("long", 123456789123456); tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200)); tag.PutFloat("float", 12.3456f); tag.PutDouble("double", 12.3456789); tag.PutList(list); tag.PutCompound("com", subTag); NBTIO.WriteGZIPFile(Environment.CurrentDirectory + "\\test2.nbt", tag); }
private void ConvertChunkData(ChunkData data) { CompoundTag oldTag = data.Data.GetCompound("").GetCompound("Level"); CompoundTag newTag = (CompoundTag)oldTag.Clone(); ListTag sections = oldTag.GetList("Sections"); ListTag newSections = ConvertSections(sections); if (newSections != null) { newTag.Remove("Sections"); newTag.PutList(newSections); List <byte> biomes = new List <byte>(); foreach (int b in oldTag.GetIntArray("Biomes")) { biomes.Add((byte)b); } newTag.Remove("Biomes"); newTag.PutByteArray("Biomes", biomes.ToArray()); } CheckCancel(); if (newTag.Exist("Heightmaps")) { newTag.Remove("Heightmaps"); } else { newTag.Remove("HeightMap"); } int[] map = new int[256]; for (int i = 0; i < 256; i++) { map[i] = 0xff; } newTag.PutIntArray("HeightMap", map); newTag.PutList(new ListTag("TileTicks", NBTTagType.COMPOUND)); newTag.PutList(new ListTag("Entities", NBTTagType.COMPOUND)); newTag.PutList(new ListTag("TileEntities", NBTTagType.COMPOUND)); newTag.PutBool("TerrainPopulated", true); newTag.PutBool("TerrainGenerated", true); newTag.Remove("CarvingMasks"); newTag.Remove("Structures"); data.Data = new CompoundTag("").PutCompound("Level", newTag); }
public CompoundTag NBTSerialize(Chunk chunk) { CompoundTag tag = new CompoundTag("Level"); tag.PutInt("xPos", chunk.X); //Chunk X tag.PutInt("zPos", chunk.Z); //Chunk Z tag.PutLong("LastUpdate", chunk.LastUpdate); //Last Save Tick tag.PutByte("LightPopulated", chunk.LightPopulated ? (byte)1 : (byte)0); // tag.PutByte("TerrainPopulated", chunk.TerrainPopulated ? (byte)1 : (byte)0); // tag.PutByte("V", 1); //Version tag.PutLong("InhabitedTime", chunk.InhabitedTime); tag.PutByteArray("Biomes", chunk.Biomes); int[] cast = new int[256]; chunk.HeightMap.CopyTo(cast, 0); tag.PutIntArray("HeightMap", cast); ListTag sections = new ListTag("Sections", NBTTagType.COMPOUND); SubChunk[] subChunks = chunk.SubChunks; for (int i = 0; i < subChunks.Length; ++i) { if (subChunks[i].IsEnpty) { continue; } CompoundTag data = new CompoundTag(); data.PutByte("Y", (byte)i); data.PutIntArray("Blocks", subChunks[i].BlockDatas); data.PutByteArray("Data", subChunks[i].MetaDatas.ArrayData); data.PutByteArray("SkyLight", subChunks[i].SkyLights.ArrayData); data.PutByteArray("BlockLight", subChunks[i].BlockLigths.ArrayData); sections.Add(data); } tag.PutList(sections); ListTag entitiesTag = new ListTag("Entities", NBTTagType.COMPOUND); Entity[] entities = chunk.GetEntities(); for (int i = 0; i < entities.Length; ++i) { if (entities[i].IsPlayer) { continue; } entitiesTag.Add(entities[i].SaveNBT()); } tag.PutList(entitiesTag); ListTag blockEntitiesTag = new ListTag("TileEntities", NBTTagType.COMPOUND); BlockEntity[] blockEntities = chunk.GetBlockEntities(); for (int i = 0; i < blockEntities.Length; ++i) { blockEntitiesTag.Add(blockEntities[i].SaveNBT()); } tag.PutList(blockEntitiesTag); CompoundTag outTag = new CompoundTag(""); outTag.PutCompound(tag.Name, tag); return(outTag); }
public override CompoundTag SerializeChunk(Chunk chunk) { CompoundTag tag = new CompoundTag(); tag.PutInt("xPos", chunk.X); tag.PutInt("zPos", chunk.Z); tag.PutLong("LastUpdate", chunk.LastUpdate); tag.PutByte("LightPopulated", chunk.LightPopulated); tag.PutByte("TerrainPopulated", chunk.TerrainPopulated); tag.PutByte("V", chunk.V); tag.PutLong("InhabitedTime", chunk.InhabitedTime); tag.PutByteArray("Biomes", chunk.Biomes); int[] cast = new int[256]; chunk.HeightMap.CopyTo(cast, 0); tag.PutIntArray("HeightMap", cast); ListTag sections = new ListTag("Sections", NBTTagType.COMPOUND); SubChunk[] subChunks = chunk.SubChunks; for (int i = 0; i < subChunks.Length; ++i) { if (subChunks[i] == null) { continue; } CompoundTag data = new CompoundTag(); data.PutByte("Y", (byte)i); byte[] blocks = new byte[subChunks[i].BlockDatas.Length]; for (int j = 0; j < subChunks[i].BlockDatas.Length; ++j) { blocks[j] = (byte)subChunks[i].BlockDatas[j]; } data.PutByteArray("Blocks", blocks); data.PutByteArray("Data", subChunks[i].MetaDatas.ArrayData); data.PutByteArray("BlockLight", subChunks[i].BlockLight); data.PutByteArray("SkyLight", subChunks[i].SkyLight); sections.Add(data); } tag.PutList(sections); ListTag entitiesTag = new ListTag("Entities", NBTTagType.COMPOUND); CompoundTag[] entities = chunk.EntitiesTag; for (int i = 0; i < entities.Length; ++i) { entitiesTag.Add(entities[i]); } tag.PutList(entitiesTag); ListTag blockEntitiesTag = new ListTag("TileEntities", NBTTagType.COMPOUND); CompoundTag[] blockEntities = chunk.BlockEntitiesTag; for (int i = 0; i < blockEntities.Length; ++i) { blockEntitiesTag.Add(blockEntities[i]); } tag.PutList(blockEntitiesTag); return(new CompoundTag().PutCompound("", new CompoundTag().PutCompound("Level", tag))); }