public Chunk NBTDeserialize(CompoundTag tag) { CompoundTag level = (CompoundTag)tag["Level"]; int x = level.GetInt("xPos"); int z = level.GetInt("zPos"); SubChunk[] subChunks = ArrayUtils.CreateArray <SubChunk>(16); ListTag sections = level.GetList("Sections"); for (int i = 0; i < sections.Count; ++i) { CompoundTag section = ((CompoundTag)sections[i]); SubChunk subChunk = new SubChunk(); byte y = section.GetByte("Y"); subChunk.BlockDatas = section.GetByteArray("Blocks"); subChunk.MetaDatas = new NibbleArray(section.GetByteArray("Data")); subChunk.SkyLights = new NibbleArray(section.GetByteArray("SkyLight")); subChunk.BlockLigths = new NibbleArray(section.GetByteArray("BlockLight")); subChunks[y] = subChunk; } byte[] biomes = level.GetByteArray("Biomes"); short[] cast = new short[256]; int[] heightMap = level.GetIntArray("HeightMap"); heightMap.CopyTo(cast, 0); Chunk chunk = new Chunk(x, z, subChunks, biomes, cast, level.GetList("Entities"), level.GetList("TileEntities")); chunk.LastUpdate = level.GetLong("LastUpdate"); chunk.InhabitedTime = level.GetLong("InhabitedTime"); chunk.LightPopulated = level.GetByte("LightPopulated") == 1; chunk.TerrainPopulated = level.GetByte("TerrainPopulated") == 1; return(chunk); }
public override Chunk DeserializeChunk(CompoundTag tag) { CompoundTag level = tag.GetCompound("").GetCompound("Level"); int x = level.GetInt("xPos"); int z = level.GetInt("zPos"); byte[] biomes = level.GetByteArray("Biomes"); short[] cast = new short[256]; int[] heightMap = level.GetIntArray("HeightMap"); for (int i = 0; i < 256; ++i) { cast[i] = (short)heightMap[i]; } ListTag sections = level.GetList("Sections"); SubChunk[] subChunks = new SubChunk[16]; for (int i = 0; i < sections.Count; ++i) { CompoundTag section = (CompoundTag)sections[i]; SubChunk subChunk = new SubChunk(); byte y = section.GetByte("Y"); byte[] bytes = section.GetByteArray("Blocks"); int[] blocks = new int[4096]; for (int j = 0; j < 4096; ++j) { blocks[j] = bytes[j]; } subChunk.BlockDatas = blocks; subChunk.MetaDatas = new NibbleArray(section.GetByteArray("Data")); subChunk.BlockLight = section.GetByteArray("BlockLight"); subChunk.SkyLight = section.GetByteArray("SkyLight"); subChunks[y] = subChunk; } Chunk chunk = new Chunk(x, z, subChunks, level.GetList("Entities"), level.GetList("TileEntities")) { LastUpdate = level.GetLong("LastUpdate"), LightPopulated = level.GetByte("LightPopulated"), TerrainPopulated = level.GetByte("TerrainPopulated"), V = level.GetByte("V"), InhabitedTime = level.GetLong("InhabitedTime"), Biomes = biomes, HeightMap = cast }; return(chunk); }
internal static JObject CompoundTagSerialize(CompoundTag tag) { JObject json = new JObject(); foreach (KeyValuePair <string, Tag> kv in tag.Tags) { Tag t = kv.Value; if (t is ByteTag) { json.Add(t.Name, new JValue(tag.GetByte(t.Name))); } else if (t is CompoundTag) { json.Add(t.Name, NBTJsonSerializer.CompoundTagSerialize((CompoundTag)t)); } else if (t is DoubleTag) { json.Add(t.Name, new JValue(tag.GetDouble(t.Name))); } else if (t is FloatTag) { json.Add(t.Name, new JValue(tag.GetFloat(t.Name))); } else if (t is IntTag) { json.Add(t.Name, new JValue(tag.GetInt(t.Name))); } else if (t is ListTag) { json.Add(t.Name, new JArray(NBTJsonSerializer.ListTagSerialize((ListTag)t))); } else if (t is LongTag) { json.Add(t.Name, new JValue(tag.GetLong(t.Name))); } else if (t is ShortTag) { json.Add(t.Name, new JValue(tag.GetShort(t.Name))); } else if (t is StringTag) { json.Add(t.Name, new JValue(tag.GetString(t.Name))); } } return(json); }
public void NBTIOTests_ReadRawFileTest() { CompoundTag tag = NBTIO.ReadRawFile(Environment.CurrentDirectory + "\\test.nbt"); tag.GetBool("bool"); tag.GetByte("byte"); tag.GetByteArray("byteArray"); tag.GetShort("short"); tag.GetInt("int"); tag.GetIntArray("intArray"); tag.GetLong("long"); tag.GetLongArray("longArray"); tag.GetFloat("float"); tag.GetDouble("double"); tag.GetList("list"); tag.GetCompound("com"); Console.WriteLine(tag); }