예제 #1
0
        // get the next long array, prefixed by array length (signed int, 4 bytes)
        public static NbtLongArray ParseNbtLongArray(NbtByteReader reader, bool parseName = true)
        {
            NbtLongArray longArray = new NbtLongArray(parseName ? ParseString(reader) : "");

            int arrayLength = reader.ReadInt();

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

            return(longArray);
        }
예제 #2
0
        public void LongArrayIndexerTest()
        {
            var longArray = new NbtLongArray("Test");

            CollectionAssert.AreEqual(new long[0], longArray.Value);
            longArray.Value = new[] {
                1,
                Int64.MaxValue,
                Int64.MinValue
            };
            Assert.AreEqual(1, longArray[0]);
            Assert.AreEqual(Int64.MaxValue, longArray[1]);
            Assert.AreEqual(Int64.MinValue, longArray[2]);
            longArray[0] = 4;
            Assert.AreEqual(4, longArray[0]);
        }
예제 #3
0
        public void NbtLongArrayTest()
        {
            object dummy;

            long[] longs = { 1111, 2222, 3333, 4444, 5555 };
            NbtTag test  = new NbtLongArray(longs);

            Assert.Throws <InvalidCastException>(() => dummy = 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);
            CollectionAssert.AreEqual(longs, test.LongArrayValue);
            Assert.IsTrue(test.HasValue);
        }
        public void Write(NetBinaryWriter writer)
        {
            writer.Write(Chunk.X);
            writer.Write(Chunk.Z);
            writer.Write(FullChunk);
            writer.WriteVar(IncludedSectionsMask);

            var motionBlocking = new NbtLongArray(36);

            writer.Write(motionBlocking.AsCompound((Utf8String)"Heightmaps", (Utf8String)"MOTION_BLOCKING"));

            if (FullChunk)
            {
                Span <int> biomes = stackalloc int[1024];
                biomes.Fill(1); // 1=plains (defined in ServerMain)

                // TODO: optimize by creating WriteVar for Span
                writer.WriteVar(biomes.Length);
                writer.WriteVar(biomes);
            }

            int sectionDataLength = GetChunkSectionDataLength(Chunk);

            writer.WriteVar(sectionDataLength);
            WriteChunk(writer, Chunk);

            // If you don't support block entities yet, use 0
            // If you need to implement it by sending block entities later with the update block entity packet,
            // do it that way and send 0 as well.  (Note that 1.10.1 (not 1.10 or 1.10.2) will not accept that)
            writer.WriteVar(0);

            //WriteVarInt(data, chunk.BlockEntities.Length);
            //foreach (CompoundTag tag in chunk.BlockEntities)
            //{
            //    WriteCompoundTag(data, tag);
            //}
        }
예제 #5
0
 public static string ToSnbt(this NbtLongArray tag, SnbtOptions options)
 {
     return(ListToString("" + LONG_ARRAY_PREFIX + ARRAY_DELIMITER, x => x.ToString() + (options.NumberSuffixes ? LONG_SUFFIX.ToString() : String.Empty), tag.Value, options));
 }
예제 #6
0
 public LongArrayByteProvider(NbtLongArray tag) : base(tag)
 {
 }
예제 #7
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));

            NbtLongArray longArrTag      = new NbtLongArray("longArrTag", new long[] { 1, 2, 3, 4 });
            NbtLongArray longArrTagClone = (NbtLongArray)longArrTag.Clone();

            Assert.AreNotSame(longArrTag, longArrTagClone);
            Assert.AreEqual(longArrTag.Name, longArrTagClone.Name);
            Assert.AreNotSame(longArrTag.Value, longArrTagClone.Value);
            CollectionAssert.AreEqual(longArrTag.Value, longArrTagClone.Value);
            Assert.Throws <ArgumentNullException>(() => new NbtLongArray((NbtLongArray)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));
        }