public bool IsResearchedPrefix(Item item) { String iTag = ResearchFrom14.ItemToTag(item) + ":p"; if (research.ContainsKey(iTag)) { if (research[iTag] is int || research[iTag] is byte) { if ((byte)(research[iTag]) == item.prefix) { return(true); } } else { byte[] ba = research.GetByteArray(ResearchFrom14.ItemToTag(item) + ":p"); foreach (byte b in ba) { if (b == item.prefix) { return(true); } } } } return(item.prefix == 0); }
public override void Load(TagCompound c) { _blocks = c.GetByteArray("Blocks"); if (c.ContainsKey("Add", TagType.ByteArray)) { _addBlocks = (new NibbleArray(c.GetByteArray("Add"), 4)); } _data = (new NibbleArray(c.GetByteArray("Data"), 4)); base.Load(c); }
public override void Load(TagCompound tag) { pieces = 0; byte[] arr = tag.GetByteArray("candy"); for (int i = Math.Min(arr.Length, candy.Length) - 1; i >= 0; i--) { pieces += (candy[i] = arr[i]); } arr = tag.GetByteArray("variants"); for (int i = Math.Min(arr.Length, variants.Length) - 1; i >= 0; i--) { variants[i] = arr[i]; } }
//////////////// internal void Load(BetterPaintMod mymod, TagCompound tags, string prefix) { var myworld = ModContent.GetInstance <BetterPaintWorld>(); this.Colors.Clear(); this.Glows.Clear(); if (tags.ContainsKey(prefix + "_x")) { int[] fgX = tags.GetIntArray(prefix + "_x"); for (int i = 0; i < fgX.Length; i++) { ushort tileX = (ushort)fgX[i]; int[] fgY = tags.GetIntArray(prefix + "_" + tileX + "_y"); for (int j = 0; j < fgY.Length; j++) { ushort tileY = (ushort)fgY[j]; byte[] clrArr = tags.GetByteArray(prefix + "_" + tileX + "_" + tileY); Color color = new Color(clrArr[0], clrArr[1], clrArr[2], clrArr[3]); Tile tile = Main.tile[tileX, tileY]; if (this.CanPaintAt(tile)) { this.SetRawColorAt(color, tileX, tileY); } } } } if (tags.ContainsKey(prefix + "_g_x")) { int[] fgX = tags.GetIntArray(prefix + "_g_x"); for (int i = 0; i < fgX.Length; i++) { ushort tileX = (ushort)fgX[i]; int[] fgY = tags.GetIntArray(prefix + "_g_" + tileX + "_y"); for (int j = 0; j < fgY.Length; j++) { ushort tileY = (ushort)fgY[j]; byte glow = tags.GetByte(prefix + "_g_" + tileX + "_" + tileY); Tile tile = Main.tile[tileX, tileY]; if (this.CanPaintAt(tile)) { this.SetGlowAt(glow, tileX, tileY); } } } } }
internal static void LoadContainers(TagCompound tag) { if (tag.HasTag("data")) ReadContainers(new BinaryReader(new MemoryStream(tag.GetByteArray("data")))); foreach (var frameTag in tag.GetList<TagCompound>("itemFrames")) { TEItemFrame itemFrame = TileEntity.ByID[tag.GetInt("id")] as TEItemFrame; ItemIO.Load(itemFrame.item, frameTag.GetCompound("item")); } }
public static void Load(Item item, TagCompound tag) { if (tag.Count == 0) { item.netDefaults(0); return; } string modName = tag.GetString("mod"); if (modName == "Terraria") { item.netDefaults(tag.GetInt("id")); if (tag.HasTag("legacyData")) LoadLegacyModData(item, tag.GetByteArray("legacyData"), tag.GetBool("hasGlobalSaving")); } else { int type = ModLoader.GetMod(modName)?.ItemType(tag.GetString("name")) ?? 0; if (type > 0) { item.netDefaults(type); if (tag.HasTag("legacyData")) LoadLegacyModData(item, tag.GetByteArray("legacyData"), tag.GetBool("hasGlobalSaving")); else item.modItem.Load(tag.GetCompound("data")); } else { item.netDefaults(ModLoader.GetMod("ModLoader").ItemType("MysteryItem")); ((MysteryItem)item.modItem).Setup(tag); } } item.Prefix(tag.GetByte("prefix")); item.stack = tag.GetTag<int?>("stack") ?? 1; item.favorited = tag.GetBool("fav"); if (!(item.modItem is MysteryItem)) LoadGlobals(item, tag.GetList<TagCompound>("globalData")); }
public override void LoadWorldData(TagCompound tag) { byte[] bytes = tag.GetByteArray("WirelessCoords"); for (int i = 0; i < bytes.Length; i += 8) { var transmitter = new Point16(BitConverter.ToInt16(bytes, i), BitConverter.ToInt16(bytes, i + 2)); var receiver = new Point16(BitConverter.ToInt16(bytes, i + 4), BitConverter.ToInt16(bytes, i + 6)); // Wireless.Log("{0}, {1}", transmitter, receiver); if (!WirelessUtils.AlreadyExists(transmitter, receiver)) { Links.Add(transmitter, receiver); } } }
/// <summary> /// 从nbt数据中获取salt /// </summary> /// <param name="data"></param> /// <param name="is112">是否是1.12版本, 如果是, 那么只需要处理一位数字</param> /// <returns></returns> public static string GetSaltFromNBTByteArray(byte[] data, bool is112) { MemoryStream ms = new MemoryStream(removeLength(data, is112)); TagCompound tag = NBTFile.FromStream(ms); byte[] saltarr = tag.GetByteArray("salt"); string salt = System.Text.Encoding.UTF8.GetString(saltarr); if (saltarr.Length > 100) { salt = ASACUtil.RSADecodeSalt(saltarr); } return(salt); }
/// <summary> /// Try to get from tag, else default to specified value. Supports int, float, double, bool, long, string, int[], byte[] /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tag"></param> /// <param name="key"></param> /// <param name="defaultValue"></param> /// <returns></returns> public static T TryGet <T>(TagCompound tag, string key, T defaultValue) { try { T val; Type type = typeof(T); if (type == typeof(int)) { val = (T)Convert.ChangeType(tag.GetInt(key), type); } else if (type == typeof(float)) { val = (T)Convert.ChangeType(tag.GetFloat(key), type); } else if (type == typeof(double)) { val = (T)Convert.ChangeType(tag.GetDouble(key), type); } else if (type == typeof(bool)) { val = (T)Convert.ChangeType(tag.GetBool(key), type); } else if (type == typeof(long)) { val = (T)Convert.ChangeType(tag.GetLong(key), type); } else if (type == typeof(string)) { val = (T)Convert.ChangeType(tag.GetString(key), type); } else if (type == typeof(int[])) { val = (T)Convert.ChangeType(tag.GetIntArray(key), type); } else if (type == typeof(byte[])) { val = (T)Convert.ChangeType(tag.GetByteArray(key), type); } else { throw new Exception(); } return(val); } catch { return(defaultValue); } }
/// <summary> /// Load all abilities from the given <see cref="TagCompound"/>. /// </summary> /// <param name="tag"><see cref="TagCompound"/> to load abilities from.</param> public void Load(TagCompound tag) { if (!tag.ContainsKey(AbilityTagKey)) { return; } byte[] arr = tag.GetByteArray(AbilityTagKey); foreach (Ability ability in this) { if (ability is ILevelable levelable) { levelable.Level = arr[ability.Id]; } } }
public void GetByteArray_returns_null_item() { // arrange TagCompound target; Tag actual; string name; name = "alpha"; target = new TagCompound(); // act actual = target.GetByteArray(name); // assert Assert.IsNull(actual); }
//////////////// public override void Load(TagCompound tag) { if (tag.ContainsKey("color")) { byte[] bytes = tag.GetByteArray("color"); this.MyColor = new Color(bytes[0], bytes[1], bytes[2], bytes[3]); } if (tag.ContainsKey("paint_quantity")) { this.Quantity = tag.GetFloat("paint_quantity"); } if (tag.ContainsKey("is_init")) { this.IsInitialized = tag.GetBool("is_init"); } }
public void GetByteArray_returns_existing_tag() { // arrange TagCompound target; Tag actual; string name; name = "alpha"; target = new TagCompound(); target.Value.Add(name, new byte[] { 2, 4, 8, 16, 32, 64, 128 }); // act actual = target.GetByteArray(name); // assert Assert.IsNotNull(actual); Assert.IsInstanceOf <TagByteArray>(actual); }
public static TileSaveData DeserializeData(TagCompound tag) { return(new TileSaveData( tag.GetBool("Active"), tag.GetString("Tile"), tag.GetString("Wall"), tag.GetShort("FrameX"), tag.GetShort("FrameY"), tag.GetShort("WFrameX"), tag.GetShort("WFrameY"), tag.GetByte("Slope"), tag.GetBool("HalfSlab"), tag.GetBool("HasActuator"), tag.GetBool("Actuated"), tag.GetByte("Liquid"), tag.GetByte("LiquidType"), tag.GetByte("Color"), tag.GetByte("WallColor"), tag.GetByteArray("Wire"), tag.GetString("TEType"), tag.Get <TagCompound>("TEData") )); }
public void TestLoadComplexNbt() { Tag tag; tag = this.CreateComplexData(); Assert.IsNotNull(tag); Assert.IsInstanceOf <TagCompound>(tag); TagCompound level = tag as TagCompound; Assert.AreEqual("Level", level.Name); TagShort shortTest = level.GetShort("shortTest"); Assert.IsNotNull(shortTest); Assert.AreEqual("shortTest", shortTest.Name); Assert.AreEqual(32767, shortTest.Value); TagLong longTest = level.GetLong("longTest"); Assert.IsNotNull(longTest); Assert.AreEqual("longTest", longTest.Name); Assert.AreEqual(9223372036854775807, longTest.Value); TagFloat floatTest = level.GetFloat("floatTest"); Assert.IsNotNull(floatTest); Assert.AreEqual("floatTest", floatTest.Name); Assert.AreEqual(0.49823147f, floatTest.Value); TagString stringTest = level.GetString("stringTest"); Assert.IsNotNull(stringTest); Assert.AreEqual("stringTest", stringTest.Name); Assert.AreEqual("HELLO WORLD THIS IS A TEST STRING едж!", stringTest.Value); TagInt intTest = level.GetInt("intTest"); Assert.IsNotNull(intTest); Assert.AreEqual("intTest", intTest.Name); Assert.AreEqual(2147483647, intTest.Value); TagCompound nestedCompoundTest = level.GetCompound("nested compound test"); Assert.IsNotNull(nestedCompoundTest); Assert.AreEqual("nested compound test", nestedCompoundTest.Name); TagCompound ham = nestedCompoundTest.GetCompound("ham"); Assert.IsNotNull(ham); Assert.AreEqual("ham", ham.Name); TagString ham_name = ham.GetString("name"); Assert.IsNotNull(ham_name); Assert.AreEqual("name", ham_name.Name); Assert.AreEqual("Hampus", ham_name.Value); TagFloat ham_value = ham.GetFloat("value"); Assert.IsNotNull(ham_value); Assert.AreEqual("value", ham_value.Name); Assert.AreEqual(0.75f, ham_value.Value); TagCompound egg = nestedCompoundTest.GetCompound("egg"); Assert.IsNotNull(egg); Assert.AreEqual("egg", egg.Name); TagString egg_name = egg.GetString("name"); Assert.IsNotNull(egg_name); Assert.AreEqual("name", egg_name.Name); Assert.AreEqual("Eggbert", egg_name.Value); TagFloat egg_value = egg.GetFloat("value"); Assert.IsNotNull(egg_value); Assert.AreEqual("value", egg_value.Name); Assert.AreEqual(0.5f, egg_value.Value); TagByte byteTest = level.GetByte("byteTest"); Assert.IsNotNull(byteTest); Assert.AreEqual("byteTest", byteTest.Name); Assert.AreEqual(0x7f, byteTest.Value); TagDouble doubleTest = level.GetDouble("doubleTest"); Assert.IsNotNull(doubleTest); Assert.AreEqual("doubleTest", doubleTest.Name); Assert.AreEqual(0.4931287132182315, doubleTest.Value); TagList listTest_long = level.GetList("listTest (long)"); Assert.IsNotNull(listTest_long); Assert.AreEqual("listTest (long)", listTest_long.Name); Assert.IsNotNull(listTest_long.Value); Assert.AreEqual(5, listTest_long.Value.Count); Assert.AreEqual(11, (listTest_long.Value[0] as TagLong).Value); Assert.AreEqual(12, (listTest_long.Value[1] as TagLong).Value); Assert.AreEqual(13, (listTest_long.Value[2] as TagLong).Value); Assert.AreEqual(14, (listTest_long.Value[3] as TagLong).Value); Assert.AreEqual(15, (listTest_long.Value[4] as TagLong).Value); TagList listTest_compound = level.GetList("listTest (compound)"); Assert.IsNotNull(listTest_compound); Assert.AreEqual("listTest (compound)", listTest_compound.Name); Assert.IsNotNull(listTest_compound.Value); Assert.AreEqual(2, listTest_compound.Value.Count); TagCompound listTest_compound_tag0 = listTest_compound.Value[0] as TagCompound; Assert.IsNotNull(listTest_compound_tag0); TagString listTest_compound_tag0_name = listTest_compound_tag0.GetString("name"); Assert.IsNotNull(listTest_compound_tag0_name); Assert.AreEqual("name", listTest_compound_tag0_name.Name); Assert.AreEqual("Compound tag #0", listTest_compound_tag0_name.Value); TagLong listTest_compound_tag0_createdOn = listTest_compound_tag0.GetLong("created-on"); Assert.IsNotNull(listTest_compound_tag0_createdOn); Assert.AreEqual("created-on", listTest_compound_tag0_createdOn.Name); Assert.AreEqual(1264099775885, listTest_compound_tag0_createdOn.Value); TagCompound listTest_compound_tag1 = listTest_compound.Value[1] as TagCompound; Assert.IsNotNull(listTest_compound_tag1); TagString listTest_compound_tag1_name = listTest_compound_tag1.GetString("name"); Assert.IsNotNull(listTest_compound_tag1_name); Assert.AreEqual("name", listTest_compound_tag1_name.Name); Assert.AreEqual("Compound tag #1", listTest_compound_tag1_name.Value); TagLong listTest_compound_tag1_createdOn = listTest_compound_tag1.GetLong("created-on"); Assert.IsNotNull(listTest_compound_tag1_createdOn); Assert.AreEqual("created-on", listTest_compound_tag1_createdOn.Name); Assert.AreEqual(1264099775885, listTest_compound_tag1_createdOn.Value); TagByteArray byteArrayTest = level.GetByteArray("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))"); Assert.IsNotNull(byteArrayTest); Assert.AreEqual("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))", byteArrayTest.Name); Assert.IsNotNull(byteArrayTest.Value); Assert.AreEqual(1000, byteArrayTest.Value.Length); }
public static Tile[,] LoadTilesFromBase64(string data) { int oldX = Main.maxTilesX; int oldY = Main.maxTilesY; Tile[,] oldTiles = Main.tile; Tile[,] loadedTiles = new Tile[0, 0]; try { TagCompound tagCompound = TagIO.FromStream(new MemoryStream(Convert.FromBase64String(data))); if (LoadTilesMethodInfo == null) { LoadTilesMethodInfo = typeof(Main).Assembly.GetType("Terraria.ModLoader.IO.TileIO").GetMethod("LoadTiles", BindingFlags.Static | BindingFlags.NonPublic); } if (LoadWorldTilesVanillaMethodInfo == null) { LoadWorldTilesVanillaMethodInfo = typeof(Main).Assembly.GetType("Terraria.IO.WorldFile").GetMethod("LoadWorldTiles", BindingFlags.Static | BindingFlags.NonPublic); } bool[] importance = new bool[TileID.Count]; for (int i = 0; i < TileID.Count; i++) { importance[i] = Main.tileFrameImportant[i]; } Point16 dimensions = tagCompound.Get <Point16>("d"); Main.maxTilesX = dimensions.X; Main.maxTilesY = dimensions.Y; loadedTiles = new Tile[Main.maxTilesX, Main.maxTilesY]; for (int i = 0; i < Main.maxTilesX; i++) { for (int j = 0; j < Main.maxTilesY; j++) { loadedTiles[i, j] = new Tile(); } } Main.tile = loadedTiles; using (MemoryStream memoryStream = new MemoryStream(tagCompound.GetByteArray("v"))) { using (BinaryReader binaryReader = new BinaryReader(memoryStream)) { LoadWorldTilesVanillaMethodInfo.Invoke(null, new object[] { binaryReader, importance }); } } if (tagCompound.ContainsKey("m")) { LoadTilesMethodInfo.Invoke(null, new object[] { tagCompound["m"] }); } // Expand because TileFrame ignores edges of map. Main.maxTilesX = dimensions.X + 12; Main.maxTilesY = dimensions.Y + 12; Tile[,] loadedTilesExpanded = new Tile[Main.maxTilesX, Main.maxTilesY]; for (int i = 0; i < Main.maxTilesX; i++) { for (int j = 0; j < Main.maxTilesY; j++) { if (i < 6 || i >= Main.maxTilesX - 6 || j < 6 || j >= Main.maxTilesY - 6) { loadedTilesExpanded[i, j] = new Tile(); } else { loadedTilesExpanded[i, j] = Main.tile[i - 6, j - 6]; } } } Main.tile = loadedTilesExpanded; for (int i = 0; i < Main.maxTilesX; i++) { for (int j = 0; j < Main.maxTilesY; j++) { //WorldGen.TileFrame(i, j, true, false); //if (i > 5 && j > 5 && i < Main.maxTilesX - 5 && j < Main.maxTilesY - 5 // 0 needs to be 6 , MaxX == 5, 4 index, // need tp add 6? 4(10) < 5(11) - 5 if (Main.tile[i, j].active()) { WorldGen.TileFrame(i, j, true, false); } if (Main.tile[i, j].wall > 0) { Framing.WallFrame(i, j, true); } } } } catch { } Main.maxTilesX = oldX; Main.maxTilesY = oldY; Main.tile = oldTiles; return(loadedTiles); }
internal static void LoadTiles(TagCompound tag) { if (!tag.HasTag("data")) return; var tables = TileTables.Create(); foreach (var tileTag in tag.GetList<TagCompound>("tileMap")) { ushort type = (ushort)tileTag.GetShort("value"); string modName = tileTag.GetString("mod"); string name = tileTag.GetString("name"); Mod mod = ModLoader.GetMod(modName); tables.tiles[type] = mod == null ? (ushort)0 : (ushort)mod.TileType(name); if (tables.tiles[type] == 0) { tables.tiles[type] = (ushort)ModLoader.GetMod("ModLoader").TileType("PendingMysteryTile"); tables.tileModNames[type] = modName; tables.tileNames[type] = name; } tables.frameImportant[type] = tileTag.GetBool("framed"); } foreach (var wallTag in tag.GetList<TagCompound>("wallMap")) { ushort wall = (ushort)wallTag.GetShort("value"); string modName = wallTag.GetString("mod"); string name = wallTag.GetString("name"); Mod mod = ModLoader.GetMod(modName); tables.walls[wall] = mod == null ? (ushort)0 : (ushort)mod.WallType(name); } ReadTileData(new BinaryReader(new MemoryStream(tag.GetByteArray("data"))), tables); }
public override void Load(TagCompound tag) { gems = tag.GetByteArray(nameof(gems)); }
private void TestNbt(TagCompound compoundTag) { var byteMin = compoundTag.GetByte("byte_min"); Assert.AreEqual(-128, byteMin.Value); var byteMax = compoundTag.GetByte("byte_max"); Assert.AreEqual(127, byteMax.Value); var shortMin = compoundTag.GetShort("short_min"); Assert.AreEqual(-32768, shortMin.Value); var shortMax = compoundTag.GetShort("short_max"); Assert.AreEqual(32767, shortMax.Value); var intMin = compoundTag.GetInt("int_min"); Assert.AreEqual(-2147483648, intMin.Value); var intMax = compoundTag.GetInt("int_max"); Assert.AreEqual(2147483647, intMax.Value); var longMin = compoundTag.GetLong("long_min"); Assert.AreEqual(-9223372036854775808, longMin.Value); var longMax = compoundTag.GetLong("long_max"); Assert.AreEqual(9223372036854775807, longMax.Value); var floatTag = compoundTag.GetFloat("float"); Assert.AreEqual(12345.6f, floatTag.Value); var doubleTag = compoundTag.GetDouble("double"); Assert.AreEqual(12345.6, doubleTag.Value); var byteArray = compoundTag.GetByteArray("byte_array"); Assert.AreEqual(3, byteArray.Value.Length); Assert.AreEqual(0x12, byteArray.Value[0]); Assert.AreEqual(0x34, byteArray.Value[1]); Assert.AreEqual(0x56, byteArray.Value[2]); var stringTag = compoundTag.GetString("string"); Assert.AreEqual("hello!", stringTag.Value); var list = compoundTag.GetList("string_list"); var listValue = list.GetArrayString(); Assert.AreEqual(3, listValue.Length); Assert.AreEqual("i'm in an array!", listValue[0].Value); Assert.AreEqual("i am also in an array!", listValue[1].Value); Assert.AreEqual("walter", listValue[2].Value); var emptyList = compoundTag.GetList("empty_list"); var emptyListValue = emptyList.GetArrayByte(); Assert.AreEqual(0, emptyListValue.Length); var listList = compoundTag.GetList("list_list"); var listListValue = listList.GetArrayList(); Assert.AreEqual(3, listListValue.Length); var listListValue0 = listListValue[0].GetArrayFloat(); Assert.AreEqual(3, listListValue0.Length); Assert.AreEqual(1.1f, listListValue0[0].Value); Assert.AreEqual(2.2f, listListValue0[1].Value); Assert.AreEqual(3.3f, listListValue0[2].Value); var listListValue1 = listListValue[1].GetArrayDouble(); Assert.AreEqual(3, listListValue1.Length); Assert.AreEqual(4.4, listListValue1[0].Value); Assert.AreEqual(5.5, listListValue1[1].Value); Assert.AreEqual(6.6, listListValue1[2].Value); var listListValue2 = listListValue[2].GetArrayString(); Assert.AreEqual(3, listListValue2.Length); Assert.AreEqual("wa", listListValue2[0].Value); Assert.AreEqual("ta", listListValue2[1].Value); Assert.AreEqual("shi", listListValue2[2].Value); var compound = compoundTag.GetCompound("compound"); Assert.AreEqual(3, compound.Count); Assert.AreEqual(123, compound.GetByte("compound_byte").Value); Assert.AreEqual(694201337, compound.GetInt("compound_int").Value); Assert.AreEqual("*holds a gun to your temple*", compound.GetString("compound_string").Value); var emptyCompound = compoundTag.GetCompound("empty_compound"); Assert.AreEqual(0, emptyCompound.Count); var intArray = compoundTag.GetIntArray("int_array"); Assert.AreEqual(4, intArray.Value.Length); Assert.AreEqual(69, intArray.Value[0]); Assert.AreEqual(420, intArray.Value[1]); Assert.AreEqual(1337, intArray.Value[2]); Assert.AreEqual(117, intArray.Value[3]); var longArray = compoundTag.GetLongArray("long_array"); Assert.AreEqual(4, longArray.Value.Length); Assert.AreEqual(69, longArray.Value[0]); Assert.AreEqual(420, longArray.Value[1]); Assert.AreEqual(1337, longArray.Value[2]); Assert.AreEqual(117, longArray.Value[3]); }
public void TestAnvilRegion() { string filename = this.AnvilRegionFileName; FileStream input = File.OpenRead(filename); int[] locations = new int[1024]; byte[] buffer = new byte[4096]; input.Read(buffer, 0, 4096); for (int i = 0; i < 1024; i++) { locations[i] = BitConverter.ToInt32(buffer, i * 4); } int[] timestamps = new int[1024]; input.Read(buffer, 0, 4096); for (int i = 0; i < 1024; i++) { timestamps[i] = BitConverter.ToInt32(buffer, i * 4); } input.Read(buffer, 0, 4); if (BitConverter.IsLittleEndian) { BitHelper.SwapBytes(buffer, 0, 4); } int sizeOfChunkData = BitConverter.ToInt32(buffer, 0) - 1; int compressionType = input.ReadByte(); buffer = new byte[sizeOfChunkData]; input.Read(buffer, 0, sizeOfChunkData); Stream inputStream = null; if (compressionType == 1) { inputStream = new GZipStream(new MemoryStream(buffer), CompressionMode.Decompress); } else if (compressionType == 2) { inputStream = new DeflateStream(new MemoryStream(buffer, 2, buffer.Length - 6), CompressionMode.Decompress); } TagReader reader; reader = new BinaryTagReader(inputStream); TagCompound tag = (TagCompound)reader.ReadTag(); string strTag = tag.ToString(); Assert.IsNotNull(tag); Assert.AreEqual(TagType.Compound, tag.GetTag("Level").Type); TagCompound levelTag = tag.GetCompound("Level"); Tag aTag = levelTag.GetTag("Entities"); Assert.AreEqual(TagType.List, aTag.Type); TagList entitiesTag = aTag as TagList; Assert.AreEqual(0, entitiesTag.Value.Count); aTag = levelTag.GetTag("Biomes"); Assert.AreEqual(TagType.ByteArray, aTag.Type); TagByteArray biomesTag = aTag as TagByteArray; Assert.AreEqual(256, biomesTag.Value.Length); aTag = levelTag.GetTag("LastUpdate"); Assert.AreEqual(TagType.Long, aTag.Type); TagLong lastUpdateTag = aTag as TagLong; Assert.AreEqual(2861877, lastUpdateTag.Value); aTag = levelTag.GetTag("xPos"); Assert.AreEqual(TagType.Int, aTag.Type); TagInt xPosTag = aTag as TagInt; Assert.AreEqual(10, xPosTag.Value); aTag = levelTag.GetTag("zPos"); Assert.AreEqual(TagType.Int, aTag.Type); TagInt zPosTag = aTag as TagInt; Assert.AreEqual(0, zPosTag.Value); aTag = levelTag.GetTag("TileEntities"); Assert.AreEqual(TagType.List, aTag.Type); TagList tileEntitiesTag = aTag as TagList; Assert.AreEqual(0, tileEntitiesTag.Value.Count); aTag = levelTag.GetTag("TerrainPopulated"); Assert.AreEqual(TagType.Byte, aTag.Type); TagByte terrainPopulatedTag = aTag as TagByte; Assert.AreEqual(1, terrainPopulatedTag.Value); aTag = levelTag.GetTag("HeightMap"); Assert.AreEqual(TagType.IntArray, aTag.Type); TagIntArray heightmapTag = aTag as TagIntArray; Assert.AreEqual(256, heightmapTag.Value.Length); aTag = levelTag.GetTag("Sections"); Assert.AreEqual(TagType.List, aTag.Type); TagList sectionsTag = aTag as TagList; Assert.AreEqual(4, sectionsTag.Value.Count); TagCompound section_0 = sectionsTag.Value[0] as TagCompound; Assert.IsNotNull(section_0); TagByteArray section_0_data = section_0.GetByteArray("Data"); Assert.IsNotNull(section_0_data); Assert.AreEqual(2048, section_0_data.Value.Length); TagByteArray section_0_skyLight = section_0.GetByteArray("SkyLight"); Assert.IsNotNull(section_0_skyLight); Assert.AreEqual(2048, section_0_skyLight.Value.Length); TagByteArray section_0_blockLight = section_0.GetByteArray("BlockLight"); Assert.IsNotNull(section_0_blockLight); Assert.AreEqual(2048, section_0_blockLight.Value.Length); TagByte section_0_y = section_0.GetByte("Y"); Assert.IsNotNull(section_0_y); Assert.AreEqual(0, section_0_y.Value); TagByteArray section_0_blocks = section_0.GetByteArray("Blocks"); Assert.IsNotNull(section_0_blocks); Assert.AreEqual(4096, section_0_blocks.Value.Length); TagCompound section_1 = sectionsTag.Value[1] as TagCompound; Assert.IsNotNull(section_1); TagByteArray section_1_data = section_1.GetByteArray("Data"); Assert.IsNotNull(section_1_data); Assert.AreEqual(2048, section_1_data.Value.Length); TagByteArray section_1_skyLight = section_1.GetByteArray("SkyLight"); Assert.IsNotNull(section_1_skyLight); Assert.AreEqual(2048, section_1_skyLight.Value.Length); TagByteArray section_1_blockLight = section_1.GetByteArray("BlockLight"); Assert.IsNotNull(section_1_blockLight); Assert.AreEqual(2048, section_1_blockLight.Value.Length); TagByte section_1_y = section_1.GetByte("Y"); Assert.IsNotNull(section_1_y); Assert.AreEqual(1, section_1_y.Value); TagByteArray section_1_blocks = section_1.GetByteArray("Blocks"); Assert.IsNotNull(section_1_blocks); Assert.AreEqual(4096, section_1_blocks.Value.Length); TagCompound section_2 = sectionsTag.Value[2] as TagCompound; Assert.IsNotNull(section_2); TagByteArray section_2_data = section_2.GetByteArray("Data"); Assert.IsNotNull(section_2_data); Assert.AreEqual(2048, section_2_data.Value.Length); TagByteArray section_2_skyLight = section_2.GetByteArray("SkyLight"); Assert.IsNotNull(section_2_skyLight); Assert.AreEqual(2048, section_2_skyLight.Value.Length); TagByteArray section_2_blockLight = section_2.GetByteArray("BlockLight"); Assert.IsNotNull(section_2_blockLight); Assert.AreEqual(2048, section_2_blockLight.Value.Length); TagByte section_2_y = section_2.GetByte("Y"); Assert.IsNotNull(section_2_y); Assert.AreEqual(2, section_2_y.Value); TagByteArray section_2_blocks = section_2.GetByteArray("Blocks"); Assert.IsNotNull(section_2_blocks); Assert.AreEqual(4096, section_2_blocks.Value.Length); TagCompound section_3 = sectionsTag.Value[3] as TagCompound; Assert.IsNotNull(section_3); TagByteArray section_3_data = section_3.GetByteArray("Data"); Assert.IsNotNull(section_3_data); Assert.AreEqual(2048, section_3_data.Value.Length); TagByteArray section_3_skyLight = section_3.GetByteArray("SkyLight"); Assert.IsNotNull(section_3_skyLight); Assert.AreEqual(2048, section_3_skyLight.Value.Length); TagByteArray section_3_blockLight = section_3.GetByteArray("BlockLight"); Assert.IsNotNull(section_3_blockLight); Assert.AreEqual(2048, section_3_blockLight.Value.Length); TagByte section_3_y = section_3.GetByte("Y"); Assert.IsNotNull(section_3_y); Assert.AreEqual(3, section_3_y.Value); TagByteArray section_3_blocks = section_3.GetByteArray("Blocks"); Assert.IsNotNull(section_3_blocks); Assert.AreEqual(4096, section_3_blocks.Value.Length); }
public new static AnvilChunk Load(AnvilChunkManager manager, TagCompound compound) { if (compound == null || !compound.ContainsKey("Level")) { return(null); } if (compound.ContainsKey("DataVersion") && compound.GetInt("DataVersion") < BorderVersion) { return(AnvilChunk.Load(manager, compound)); } TagCompound level = compound["Level"] as TagCompound; int cx = level.GetInt("xPos"); int cy = level.GetInt("zPos"); AnvilChunkImproved c = new AnvilChunkImproved(manager, new ChunkCoord(cx, cy)); if (compound.ContainsKey("DataVersion")) { c._dataVersion = compound.GetInt("DataVersion"); } c._status = ChunkStatusHelper.Parse(level.GetString("Status")); //c.InhabitedTime = tag.GetLong("InhabitedTime"); TagList sections = (TagList)level["Sections"]; c._sections = new AnvilSection[SectionsPerChunk]; for (int i = 0; i < sections.Count; i++) { TagCompound sec = sections[i] as TagCompound; if (sec == null) { continue; } c._sections[i] = new AnvilSectionImproved(sec.GetByte("Y"), true); c._sections[i].Load(sec); } if (level.ContainsKey("Biomes", TagType.IntArray)) { c._biomes = level.GetIntArray("Biomes"); } if (level.ContainsKey("Heightmaps")) { foreach (TagLongArray t in (TagCompound)level["Heightmaps"]) { c._heightMaps.Add(t.Name, new HeightMap(t.Name, t.Value)); } } if (level.ContainsKey("CarvingMasks")) { TagCompound tag = (TagCompound)level["CarvingMasks"]; if (tag.ContainsKey("AIR")) { c._carvingMaskAir = tag.GetByteArray("AIR"); } if (tag.ContainsKey("LIQUID")) { c._carvingMaskLiquid = tag.GetByteArray("LIQUID"); } } if (level.ContainsKey("Structures")) { c._structures = (TagCompound)level["Structures"]; } for (int i = 0; i < ListOfList.Length; i++) { if (level.ContainsKey(ListOfList[i])) { c._lists.Add(ListOfList[i], (TagList)level[ListOfList[i]]); } } TagList entities = (TagList)level["Entities"]; foreach (TagCompound t in entities) { c.Entities.Add(t); } TagList tiles = (TagList)level["TileEntities"]; foreach (TagCompound t in tiles) { int x = t.GetInt("x"); int y = t.GetInt("y"); int z = t.GetInt("z"); c._tileEntities.Add(new BlockPos(x, y, z), t); } return(c); }