Example #1
0
        public void LoadFromFile(string file)
        {
            Console.WriteLine(file);
            using (NbtFile rdr = new NbtFile(file))
            {
                if (rdr.RootTag is NbtCompound)
                {
                    foreach (NbtTag tag in rdr.RootTag.Tags)
                    {
                        switch (tag.Name)
                        {
                        case "MaterialTable":
                            NbtCompound c = (NbtCompound)tag;
                            mMaterials.FromNbt(c);
                            break;

                        case "Voxels":
                            NbtByteArray vba = (NbtByteArray)tag;
                            FromBytes(vba.Value);
                            break;
                        }
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Creates a new schematic of a specified size
 /// </summary>
 /// <param name="Width">The width of the schematic</param>
 /// <param name="Height">The height of the schematic</param>
 /// <param name="Length">The length of the schematic</param>
 public NbtSchematic(short Width, short Height, short Length)
 {
     this.Width   = new NbtShort("Width", Width);
     this.Height  = new NbtShort("Height", Height);
     this.Length  = new NbtShort("Length", Length);
     Materials    = new NbtString("Materials", "Alpha");
     Blocks       = new NbtByteArray("Blocks", new byte[Width * Height * Length]);
     Data         = new NbtByteArray("Data", new byte[Width * Height * Length]);
     TileEntities = new NbtList("TileEntities", NbtTagType.Compound);
 }
Example #3
0
        // get the next byte array, prefixed by array length (signed int, 4 bytes)
        public static NbtByteArray ParseNbtByteArray(NbtByteReader reader, bool parseName = true)
        {
            NbtByteArray byteArray = new NbtByteArray(parseName ? ParseString(reader) : "");

            int arrayLength = reader.ReadInt();

            for (int i = 0; i < arrayLength; i++)
            {
                byteArray.Value.Add(reader.ReadSByte());
            }

            return(byteArray);
        }
Example #4
0
    public static byte[] getByteArray(this NbtCompound tag, string name)
    {
        NbtByteArray tag1 = tag.Get <NbtByteArray>(name);

        if (tag1 == null)
        {
            return(new byte[0]);
        }
        else
        {
            return(tag1.Value);
        }
    }
        private static List <String> GetBlockNames3D(string filePath)
        {
            // Open schematic file as NBTFile and get root tag
            NbtFile model = new NbtFile();

            model.LoadFromFile(filePath);
            var compoundTag = model.RootTag;

            // Check if schematic is 16 x 16 x 16
            short length = compoundTag.Get <NbtShort>("Length").ShortValue;
            short width  = compoundTag.Get <NbtShort>("Width").ShortValue;
            short height = compoundTag.Get <NbtShort>("Height").ShortValue;

            if ((length == width) && (length == height) && (length == 16))
            {
                // Get NBTByteArray of blockIDs and metadata (in bytes)
                NbtByteArray blocksNbt  = compoundTag.Get <NbtByteArray>("BlockData");
                NbtCompound  paletteNbt = compoundTag.Get <NbtCompound>("Palette");

                // Convert ByteArray into int array to be iterated over
                int[] blockPositions = blocksNbt.Value.Select(x => (int)x).ToArray();

                // Convert NBTCompound → Dictionary for iteration
                Dictionary <int, string> palette = new Dictionary <int, string>();
                foreach (NbtTag tag in paletteNbt.Tags)
                {
                    // Remove namespace and blockdata i.e. 'minecraft:grass[snowy=false]' → grass'
                    String newName = tag.Name.Replace("minecraft:", "");
                    newName = Regex.Replace(newName, "\\[.+\\]", "");
                    palette.Add(tag.IntValue, newName);
                }

                // Maps palette to block positions
                // Creates a 2D Array to be broken down using triple YZX loop in the GenerateModel() Function.
                List <String> blockNames3D = new List <String>();
                foreach (int paletteID in blockPositions)
                {
                    if (palette.TryGetValue(paletteID, out string blockName))
                    {
                        blockNames3D.Add(blockName);
                    }
                }

                return(blockNames3D);
            }
            else
            {
                System.Windows.MessageBox.Show("Schematic file is not 16x16x16!", "Incorrect Size Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
        }
Example #6
0
 public void ByteArrayIndexerTest()
 {
     // test getting/settings values of byte array tag via indexer
     var byteArray = new NbtByteArray("Test");
     CollectionAssert.AreEqual(byteArray.Value, new byte[0]);
     byteArray.Value = new byte[] {
         1, 2, 3
     };
     Assert.AreEqual(byteArray[0], 1);
     Assert.AreEqual(byteArray[1], 2);
     Assert.AreEqual(byteArray[2], 3);
     byteArray[0] = 4;
     Assert.AreEqual(byteArray[0], 4);
 }
Example #7
0
        public void ByteArrayIndexerTest()
        {
            // test getting/settings values of byte array tag via indexer
            var byteArray = new NbtByteArray("Test");

            CollectionAssert.AreEqual(new byte[0], byteArray.Value);
            byteArray.Value = new byte[] {
                1, 2, 3
            };
            Assert.AreEqual(1, byteArray[0]);
            Assert.AreEqual(2, byteArray[1]);
            Assert.AreEqual(3, byteArray[2]);
            byteArray[0] = 4;
            Assert.AreEqual(4, byteArray[0]);
        }
Example #8
0
 public void NbtByteArrayTest()
 {
     object dummy;
     byte[] bytes = new byte[] { 1, 2, 3, 4, 5 };
     NbtTag test = new NbtByteArray( bytes );
     CollectionAssert.AreEqual( bytes, test.ByteArrayValue );
     Assert.Throws<InvalidCastException>( () => dummy = test.ByteValue );
     Assert.Throws<InvalidCastException>( () => dummy = test.DoubleValue );
     Assert.Throws<InvalidCastException>( () => dummy = test.FloatValue );
     Assert.Throws<InvalidCastException>( () => dummy = test.IntArrayValue );
     Assert.Throws<InvalidCastException>( () => dummy = test.IntValue );
     Assert.Throws<InvalidCastException>( () => dummy = test.LongValue );
     Assert.Throws<InvalidCastException>( () => dummy = test.ShortValue );
     Assert.Throws<InvalidCastException>( () => dummy = test.StringValue );
 }
        public static void UpdateBlockNibble(NbtByteArray Bnibble, int BlockPos, byte Data)
        {
            byte blockadd = Bnibble.tagvalue[BlockPos / 2];

            if (BlockPos % 2 == 0)
            {
                blockadd = (byte)((blockadd & 0xF0) | (Data & 0x0F));
            }
            else
            {
                blockadd = (byte)(((Data << 4) & 0x00F0) | (blockadd & 0x000F));
            }

            Bnibble.tagvalue[BlockPos / 2] = blockadd;
        }
Example #10
0
        public void NbtByteArrayTest()
        {
            object dummy;

            byte[] bytes = { 1, 2, 3, 4, 5 };
            NbtTag test  = new NbtByteArray(bytes);

            CollectionAssert.AreEqual(bytes, test.ByteArrayValue);
            Assert.Throws <InvalidCastException>(() => dummy = test.ByteValue);
            Assert.Throws <InvalidCastException>(() => dummy = test.DoubleValue);
            Assert.Throws <InvalidCastException>(() => dummy = test.FloatValue);
            Assert.Throws <InvalidCastException>(() => dummy = test.IntArrayValue);
            Assert.Throws <InvalidCastException>(() => dummy = test.IntValue);
            Assert.Throws <InvalidCastException>(() => dummy = test.LongValue);
            Assert.Throws <InvalidCastException>(() => dummy = test.ShortValue);
            Assert.Throws <InvalidCastException>(() => dummy = test.StringValue);
        }
        public void UpdateBlockId(int BlockPos, int BlockID)
        {
            byte block_a = (byte)(BlockID & 0x00FF);
            byte block_b = (byte)((BlockID & 0x0F00) >> 8);

            if (Add == null && block_b > 0)
            {
                Add          = new NbtByteArray();
                Add.tagvalue = new byte[2048];
            }
            if (block_b > 0)
            {
                UpdateBlockNibble(Add, BlockPos, block_b);
            }

            Blocks.tagvalue[BlockPos] = block_a;
        }
 public void LoadBlockData(NbtCompound section)
 {
     if (section != null)
     {
         Y          = (NbtByte)section["Y"];
         Blocks     = (NbtByteArray)section["Blocks"];
         Add        = (NbtByteArray)section["Add"];
         Data       = (NbtByteArray)section["Data"];
         SkyLight   = (NbtByteArray)section["SkyLight"];
         BlockLight = (NbtByteArray)section["BlockLight"];
         IsLoaded   = true;
     }
     else
     {
         IsLoaded = false;
     }
 }
    public static void EditArray(Rect buttonRect, NbtByteArray byteArray)
    {
        NbtMassArrayEdit win = ScriptableObject.CreateInstance <NbtMassArrayEdit>();

        win.titleContent = new GUIContent("Byte Array");
        win.byteTag      = byteArray;
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < byteArray.Value.Length; i++)
        {
            if (i != 0)
            {
                sb.Append(" ");
            }
            sb.Append(byteArray.Value[i]);
        }
        win.text = sb.ToString();
        win.ShowAsDropDown(buttonRect, new Vector2(256, 128));
    }
 private void InputForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (this.DialogResult == DialogResult.OK)
     {
         string[] text = this.textBox1.Lines;
         if (!ValidateInput(text))
         {
             textBox1.ForeColor = Color.Tomato;//TODO find a better color
             button1.Enabled    = false;
             e.Cancel           = true;
             (new AlertForm("The input is invalid!")
             {
                 Icon = SystemIcons.Error,
                 Text = "Invalid input!"
             }).ShowDialog();
         }
         else
         {
             NBTTag = new NbtByteArray(NBTTag.Name, MainClass.StringToByteArray(text));
         }
         return;
     }
 }
Example #15
0
        public static NbtTag TreeToNBT(TreeNodeCollection tree)
        {
            NbtTag NBTTag = null;

            if (tree != null)
            {
                foreach (TreeNode node in tree)
                {
                    string value = node.Text.Replace($"{node.Name}: ", string.Empty).Replace(".", ",");//TODO , or . by language
                    try
                    {
                        switch (node.ImageKey)
                        {
                        case "buttonstring.png":
                        {
                            NBTTag = new NbtString(node.Name, value);
                            break;
                        }

                        case "buttonint.png":
                        {
                            NBTTag = new NbtInt(node.Name, int.Parse(value));
                            break;
                        }

                        case "buttonbyte.png":
                        {
                            NBTTag = new NbtByte(node.Name, byte.Parse(value));
                            break;
                        }

                        case "buttonlong.png":
                        {
                            NBTTag = new NbtLong(node.Name, long.Parse(value));
                            break;
                        }

                        case "buttonshort.png":
                        {
                            NBTTag = new NbtShort(node.Name, short.Parse(value));
                            break;
                        }

                        case "buttonfloat.png":
                        {
                            NBTTag = new NbtFloat(node.Name, float.Parse(value));
                            break;
                        }

                        case "buttondouble.png":
                        {
                            NBTTag = new NbtDouble(node.Name, double.Parse(value));
                            break;
                        }

                        case "buttoncompound.png":
                        {
                            NBTTag = new NbtCompound(node.Name);
                            foreach (object c in node.Nodes)
                            {
                                (new AlertForm(c.ToString())).ShowDialog();
                                if (c is TreeNode && ((TreeNode)c).Nodes.Count > 0)
                                {
                                    ((NbtCompound)NBTTag).Add(TreeToNBT(((TreeNode)c).Nodes));
                                }
                                else
                                {
                                    (new AlertForm(c.GetType().ToString())).ShowDialog();
                                }
                            }
                            break;
                        }

                        case "buttonlist.png":
                        {
                            NBTTag = new NbtList(node.Name);
                            foreach (object c in node.Nodes)
                            {
                                (new AlertForm(c.ToString())).ShowDialog();
                                if (c is TreeNode && ((TreeNode)c).Nodes.Count > 0)
                                {
                                    ((NbtList)NBTTag).Add(TreeToNBT(((TreeNode)c).Nodes));
                                }
                                else
                                {
                                    (new AlertForm(c.GetType().ToString())).ShowDialog();
                                }
                            }
                            break;
                        }

                        case "buttonbytearray.png":
                        {
                            NBTTag = new NbtByteArray(node.Name, NodesToByteArray(node.Nodes));
                            (new AlertForm(NBTTag.ToString())).ShowDialog();
                            break;
                        }

                        case "buttonintarray.png":
                        {
                            NBTTag = new NbtIntArray(node.Name, NodesToIntArray(node.Nodes));
                            (new AlertForm(NBTTag.ToString())).ShowDialog();
                            break;
                        }

                        default:
                        {
                            throw new WarningException($"Warning: unhandeled node {node.ImageKey} can not be edited");
                        }
                        }
                    }
                    catch (Exception exception)
                    {
                        if (exception is InvalidOperationException || exception is WarningException)
                        {
                            new AlertForm(exception.ToString())
                            {
                                Text = "Warning!",
                                Icon = System.Drawing.SystemIcons.Warning
                            }.ShowDialog();
                        }
                        else
                        {
                            new AlertForm(exception.ToString())
                            {
                                Text = exception.GetType().ToString(),
                                Icon = System.Drawing.SystemIcons.Error
                            }.ShowDialog();
                        }
                    }
                }
            }
            return(NBTTag);
        }
Example #16
0
 public ByteArrayByteProvider(NbtByteArray tag) : base(tag)
 {
 }
        public static byte BlockNibble(NbtByteArray arr, int BlockPos)
        {
            int k = BlockPos % 2 == 0 ? arr.tagvalue[BlockPos / 2] & 0x0F : (arr.tagvalue[BlockPos / 2] >> 4) & 0x0F;

            return((byte)k);
        }
Example #18
0
        public void CopyConstructorTest()
        {
            NbtByte byteTag = new NbtByte("byteTag", 1);
            NbtByte byteTagClone = (NbtByte)byteTag.Clone();
            Assert.AreNotSame(byteTag, byteTagClone);
            Assert.AreEqual(byteTag.Name, byteTagClone.Name);
            Assert.AreEqual(byteTag.Value, byteTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtByte((NbtByte)null));

            NbtByteArray byteArrTag = new NbtByteArray("byteArrTag", new byte[] { 1, 2, 3, 4 });
            NbtByteArray byteArrTagClone = (NbtByteArray)byteArrTag.Clone();
            Assert.AreNotSame(byteArrTag, byteArrTagClone);
            Assert.AreEqual(byteArrTag.Name, byteArrTagClone.Name);
            Assert.AreNotSame(byteArrTag.Value, byteArrTagClone.Value);
            CollectionAssert.AreEqual(byteArrTag.Value, byteArrTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtByteArray((NbtByteArray)null));

            NbtCompound compTag = new NbtCompound("compTag", new NbtTag[] { new NbtByte("innerTag", 1) });
            NbtCompound compTagClone = (NbtCompound)compTag.Clone();
            Assert.AreNotSame(compTag, compTagClone);
            Assert.AreEqual(compTag.Name, compTagClone.Name);
            Assert.AreNotSame(compTag["innerTag"], compTagClone["innerTag"]);
            Assert.AreEqual(compTag["innerTag"].Name, compTagClone["innerTag"].Name);
            Assert.AreEqual(compTag["innerTag"].ByteValue, compTagClone["innerTag"].ByteValue);
            Assert.Throws<ArgumentNullException>(() => new NbtCompound((NbtCompound)null));

            NbtDouble doubleTag = new NbtDouble("doubleTag", 1);
            NbtDouble doubleTagClone = (NbtDouble)doubleTag.Clone();
            Assert.AreNotSame(doubleTag, doubleTagClone);
            Assert.AreEqual(doubleTag.Name, doubleTagClone.Name);
            Assert.AreEqual(doubleTag.Value, doubleTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtDouble((NbtDouble)null));

            NbtFloat floatTag = new NbtFloat("floatTag", 1);
            NbtFloat floatTagClone = (NbtFloat)floatTag.Clone();
            Assert.AreNotSame(floatTag, floatTagClone);
            Assert.AreEqual(floatTag.Name, floatTagClone.Name);
            Assert.AreEqual(floatTag.Value, floatTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtFloat((NbtFloat)null));

            NbtInt intTag = new NbtInt("intTag", 1);
            NbtInt intTagClone = (NbtInt)intTag.Clone();
            Assert.AreNotSame(intTag, intTagClone);
            Assert.AreEqual(intTag.Name, intTagClone.Name);
            Assert.AreEqual(intTag.Value, intTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtInt((NbtInt)null));

            NbtIntArray intArrTag = new NbtIntArray("intArrTag", new[] { 1, 2, 3, 4 });
            NbtIntArray intArrTagClone = (NbtIntArray)intArrTag.Clone();
            Assert.AreNotSame(intArrTag, intArrTagClone);
            Assert.AreEqual(intArrTag.Name, intArrTagClone.Name);
            Assert.AreNotSame(intArrTag.Value, intArrTagClone.Value);
            CollectionAssert.AreEqual(intArrTag.Value, intArrTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtIntArray((NbtIntArray)null));

            NbtList listTag = new NbtList("listTag", new NbtTag[] { new NbtByte(1) });
            NbtList listTagClone = (NbtList)listTag.Clone();
            Assert.AreNotSame(listTag, listTagClone);
            Assert.AreEqual(listTag.Name, listTagClone.Name);
            Assert.AreNotSame(listTag[0], listTagClone[0]);
            Assert.AreEqual(listTag[0].ByteValue, listTagClone[0].ByteValue);
            Assert.Throws<ArgumentNullException>(() => new NbtList((NbtList)null));

            NbtLong longTag = new NbtLong("longTag", 1);
            NbtLong longTagClone = (NbtLong)longTag.Clone();
            Assert.AreNotSame(longTag, longTagClone);
            Assert.AreEqual(longTag.Name, longTagClone.Name);
            Assert.AreEqual(longTag.Value, longTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtLong((NbtLong)null));

            NbtShort shortTag = new NbtShort("shortTag", 1);
            NbtShort shortTagClone = (NbtShort)shortTag.Clone();
            Assert.AreNotSame(shortTag, shortTagClone);
            Assert.AreEqual(shortTag.Name, shortTagClone.Name);
            Assert.AreEqual(shortTag.Value, shortTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtShort((NbtShort)null));

            NbtString stringTag = new NbtString("stringTag", "foo");
            NbtString stringTagClone = (NbtString)stringTag.Clone();
            Assert.AreNotSame(stringTag, stringTagClone);
            Assert.AreEqual(stringTag.Name, stringTagClone.Name);
            Assert.AreEqual(stringTag.Value, stringTagClone.Value);
            Assert.Throws<ArgumentNullException>(() => new NbtString((NbtString)null));
        }
Example #19
0
		public void Write_ByteArrayTag()
		{
			// Arrange
			MemoryStream stream = new MemoryStream();
			NbtWriter writer = new NbtWriter(stream);
			NbtByteArray tag = new NbtByteArray("asdf", new byte[] { 0x6A, 0x6B, 0x6C, 0x3B });
			byte[] expected = new byte[] { 0x07, 0x00, 0x04, 0x61, 0x73, 0x64, 0x66, 0x00, 0x00, 0x00, 0x04, 0x6A, 0x6B, 0x6C, 0x3B };

			// Act
			writer.Write(tag);
			byte[] result = stream.ToArray();

			// Assert
			CollectionAssert.AreEqual(expected, result);
		}
Example #20
0
		internal void Write(NbtByteArray tag, bool writeHeader)
		{
			Write(tag.Name, tag.Value, writeHeader);
		}
Example #21
0
		/// <summary>
		/// Writes out the specified tag.
		/// </summary>
		/// <param name="tag">The tag.</param>
		/// <exception cref="System.ArgumentNullException"><paramref name="tag"/> is <c>null</c>.</exception>
		/// <exception cref="System.ObjectDisposedException">The stream is closed.</exception>
		/// <exception cref="System.IO.IOException">An I/O error occured.</exception>
		public void Write(NbtByteArray tag)
		{
			if (tag == null)
				throw new ArgumentNullException("tag", "tag is null.");

			Write(tag, true);
		}
Example #22
0
        public void CopyConstructorTest()
        {
            NbtByte byteTag      = new NbtByte("byteTag", 1);
            NbtByte byteTagClone = (NbtByte)byteTag.Clone();

            Assert.AreNotSame(byteTag, byteTagClone);
            Assert.AreEqual(byteTag.Name, byteTagClone.Name);
            Assert.AreEqual(byteTag.Value, byteTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtByte((NbtByte)null));

            NbtByteArray byteArrTag      = new NbtByteArray("byteArrTag", new byte[] { 1, 2, 3, 4 });
            NbtByteArray byteArrTagClone = (NbtByteArray)byteArrTag.Clone();

            Assert.AreNotSame(byteArrTag, byteArrTagClone);
            Assert.AreEqual(byteArrTag.Name, byteArrTagClone.Name);
            Assert.AreNotSame(byteArrTag.Value, byteArrTagClone.Value);
            CollectionAssert.AreEqual(byteArrTag.Value, byteArrTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtByteArray((NbtByteArray)null));

            NbtCompound compTag      = new NbtCompound("compTag", new NbtTag[] { new NbtByte("innerTag", 1) });
            NbtCompound compTagClone = (NbtCompound)compTag.Clone();

            Assert.AreNotSame(compTag, compTagClone);
            Assert.AreEqual(compTag.Name, compTagClone.Name);
            Assert.AreNotSame(compTag["innerTag"], compTagClone["innerTag"]);
            Assert.AreEqual(compTag["innerTag"].Name, compTagClone["innerTag"].Name);
            Assert.AreEqual(compTag["innerTag"].ByteValue, compTagClone["innerTag"].ByteValue);
            Assert.Throws <ArgumentNullException>(() => new NbtCompound((NbtCompound)null));

            NbtDouble doubleTag      = new NbtDouble("doubleTag", 1);
            NbtDouble doubleTagClone = (NbtDouble)doubleTag.Clone();

            Assert.AreNotSame(doubleTag, doubleTagClone);
            Assert.AreEqual(doubleTag.Name, doubleTagClone.Name);
            Assert.AreEqual(doubleTag.Value, doubleTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtDouble((NbtDouble)null));

            NbtFloat floatTag      = new NbtFloat("floatTag", 1);
            NbtFloat floatTagClone = (NbtFloat)floatTag.Clone();

            Assert.AreNotSame(floatTag, floatTagClone);
            Assert.AreEqual(floatTag.Name, floatTagClone.Name);
            Assert.AreEqual(floatTag.Value, floatTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtFloat((NbtFloat)null));

            NbtInt intTag      = new NbtInt("intTag", 1);
            NbtInt intTagClone = (NbtInt)intTag.Clone();

            Assert.AreNotSame(intTag, intTagClone);
            Assert.AreEqual(intTag.Name, intTagClone.Name);
            Assert.AreEqual(intTag.Value, intTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtInt((NbtInt)null));

            NbtIntArray intArrTag      = new NbtIntArray("intArrTag", new[] { 1, 2, 3, 4 });
            NbtIntArray intArrTagClone = (NbtIntArray)intArrTag.Clone();

            Assert.AreNotSame(intArrTag, intArrTagClone);
            Assert.AreEqual(intArrTag.Name, intArrTagClone.Name);
            Assert.AreNotSame(intArrTag.Value, intArrTagClone.Value);
            CollectionAssert.AreEqual(intArrTag.Value, intArrTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtIntArray((NbtIntArray)null));

            NbtList listTag      = new NbtList("listTag", new NbtTag[] { new NbtByte(1) });
            NbtList listTagClone = (NbtList)listTag.Clone();

            Assert.AreNotSame(listTag, listTagClone);
            Assert.AreEqual(listTag.Name, listTagClone.Name);
            Assert.AreNotSame(listTag[0], listTagClone[0]);
            Assert.AreEqual(listTag[0].ByteValue, listTagClone[0].ByteValue);
            Assert.Throws <ArgumentNullException>(() => new NbtList((NbtList)null));

            NbtLong longTag      = new NbtLong("longTag", 1);
            NbtLong longTagClone = (NbtLong)longTag.Clone();

            Assert.AreNotSame(longTag, longTagClone);
            Assert.AreEqual(longTag.Name, longTagClone.Name);
            Assert.AreEqual(longTag.Value, longTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtLong((NbtLong)null));

            NbtShort shortTag      = new NbtShort("shortTag", 1);
            NbtShort shortTagClone = (NbtShort)shortTag.Clone();

            Assert.AreNotSame(shortTag, shortTagClone);
            Assert.AreEqual(shortTag.Name, shortTagClone.Name);
            Assert.AreEqual(shortTag.Value, shortTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtShort((NbtShort)null));

            NbtString stringTag      = new NbtString("stringTag", "foo");
            NbtString stringTagClone = (NbtString)stringTag.Clone();

            Assert.AreNotSame(stringTag, stringTagClone);
            Assert.AreEqual(stringTag.Name, stringTagClone.Name);
            Assert.AreEqual(stringTag.Value, stringTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtString((NbtString)null));
        }
 public InputByteArrayTagForm(NbtByteArray tag)
 {
     InitializeComponent();
     NBTTag = tag;
 }
Example #24
0
 public static string ToSnbt(this NbtByteArray tag, SnbtOptions options)
 {
     return(ListToString("" + BYTE_ARRAY_PREFIX + ARRAY_DELIMITER, x => ((sbyte)x).ToString() + (options.NumberSuffixes ? BYTE_SUFFIX.ToString() : String.Empty), tag.Value, options));
 }