Exemplo n.º 1
0
        private static List <Palette> ParsePalettes(NbtCompoundTag nbt)
        {
            nbt.TryGetValue("Palette", out var paletteValue);
            var palette = (NbtCompoundTag)paletteValue;

            List <Palette> palettes = new List <Palette>();

            foreach (var item in palette)
            {
                var name = item.Key;
                Dictionary <string, string> properties = new Dictionary <string, string>();
                var propertyPosition = item.Key.IndexOf("[");
                if (propertyPosition != -1)
                {
                    name = item.Key.Substring(0, propertyPosition);
                    var propertyString = item.Key.Substring(propertyPosition + 1);
                    propertyString = propertyString.Remove(propertyString.Length - 1, 1);
                    var propertiesArray = propertyString.Split(',');

                    foreach (var property in propertiesArray)
                    {
                        var pair = property.Split('=');

                        properties.Add(pair[0], pair[1]);
                    }
                }

                var intValue = int.Parse(item.Value.ToString());
                palettes.Add(new Palette {
                    MinecraftId = name, Properties = properties, SchemBlockId = intValue
                });
            }

            return(palettes);
        }
Exemplo n.º 2
0
        public static bool TryParse(ref byte[] buffer, out NbtCompoundTag result)
        {
            var    parser    = new NbtParser();
            Stream nbtStream = new MemoryStream(buffer);

            if (buffer[0] == 0)
            {
                buffer = buffer[1..];
Exemplo n.º 3
0
        private static Schematic ConvertNBTToSchematic(NbtCompoundTag nbt)
        {
            var palettes  = ParsePalettes(nbt);
            var blockData = ParseBlockData(nbt);

            return(new Schematic {
                Palette = palettes, BlockData = blockData
            });
        }
Exemplo n.º 4
0
        public void TestNbtCompoundTag()
        {
            NbtCompoundTag nbt = (NbtCompoundTag)NbtJsonParser.Parse("{string1:test,string2:\"test\",byte:1b,int:2}");

            Assert.That(nbt.GetString("string1").Value, Is.EqualTo("test"));
            Assert.That(nbt.GetString("string2").Value, Is.EqualTo("test"));
            Assert.That(nbt.GetByte("byte").Value, Is.EqualTo((byte)1));
            Assert.That(nbt.GetInt("int").Value, Is.EqualTo(2));
        }
Exemplo n.º 5
0
        private static List <int> ParseBlockData(NbtCompoundTag nbt)
        {
            nbt.TryGetValue("BlockData", out var blockDataValue);
            var blockDataNBT   = (NbtByteArrayTag)blockDataValue;
            var blockDataBytes = blockDataNBT.Payload;

            var blockData = ParseBlockDataVarInts(blockDataBytes);

            return(blockData.ToList());
        }
Exemplo n.º 6
0
        public void TestCompoundTag()
        {
            var tag = new NbtCompoundTag
            {
                { "hi world", new NbtString("hello world") },
                { "int", new NbtNumber <int>(10) },
                { "byte", new NbtNumber <byte>(1) }
            };

            string compiled = tag.ToString();

            Assert.That(compiled, Is.EqualTo("{\"hi world\":\"hello world\",int:10,byte:1b}"));
        }