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); }
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 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); }
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); }