Exemplo n.º 1
0
        private static void Schematic2BlockCollection(string file)
        {
            #region Initialization
            var nbt = new NbtFile();
            nbt.LoadFromFile(file);
            var root = nbt.RootTag; //Read File

            bcl = new BlockCollection();
            bcl.SetWidth(root.Get <NbtShort>("Width").ShortValue); //Get Width
            bcl.SetHeight(root.Get <NbtShort>("Height").ShortValue);
            bcl.SetLength(root.Get <NbtShort>("Length").ShortValue);

            bcl.Comments = "Created by S2J";                               //Set Comment
            var blocks = root.Get <NbtByteArray>("Blocks").ByteArrayValue; //Initialize Blocks
            var datas  = root.Get <NbtByteArray>("Data").ByteArrayValue;   //Initialize Datas

            bcl.level = new BlockCollection.Block[bcl.GetWidth(), bcl.GetHeight(), bcl.GetLength()];
            #endregion
            var obj = new object();

            Current.WriteLine(Environment.NewLine + "- Reading Schematic:");
            Current.SetProgressBar();
            int current = 0;
            int total   = bcl.GetWidth();

            #region Read Schematic
            Parallel.For(0, bcl.GetWidth(), x =>
            {
                for (int y = 0; y < bcl.GetHeight(); y++)
                {
                    for (int z = 0; z < bcl.GetLength(); z++)
                    {
                        var block = new BlockCollection.Block();
                        var index = y * bcl.GetWidth() * bcl.GetLength() + z * bcl.GetWidth() + x;
                        if (blocks[index] != 0)
                        {
                            var blockInfo = res.GetBlockInfo(blocks[index].ToString(), datas[index].ToString(), version);
                            if (blockInfo != null)
                            {
                                block.SetCoordinate(x, y, z);
                                block.SetInfo(blockInfo);
                                bcl.blocks.Add(block);
                                bcl.level[x, y, z] = block;
                            }
                        }
                    }
                }
                lock (obj) //Update Progress
                {
                    current++;
                    Current.DrawProgressBar(current * 100 / total);
                }
            });
            #endregion
        }
Exemplo n.º 2
0
        private static void NBT2BlockCollection(string file)
        {
            #region Initialization
            var nbt = new NbtFile();
            nbt.LoadFromFile(file);
            var root = nbt.RootTag; //Read File

            bcl = new BlockCollection();
            bcl.SetWidth(root.Get <NbtList>("size")[0].IntValue); //Get Width
            bcl.SetHeight(root.Get <NbtList>("size")[1].IntValue);
            bcl.SetLength(root.Get <NbtList>("size")[2].IntValue);

            bcl.Comments = "Created by S2J"; //Set Comment

            var p        = root.Get <NbtList>("palette");
            var palettes = new List <NbtCompound>();
            foreach (NbtCompound _p in p)
            {
                palettes.Add(_p);
            }
            var blocks = root.Get <NbtList>("blocks");

            bcl.level = new BlockCollection.Block[bcl.GetWidth(), bcl.GetHeight(), bcl.GetLength()];
            #endregion

            Current.WriteLine(Environment.NewLine + "- Reading NBT:");
            Current.SetProgressBar();
            int current = 0;
            int total   = bcl.GetWidth() * bcl.GetHeight() * bcl.GetLength();

            #region Read NBT
            foreach (NbtCompound b in blocks)
            {
                var index = b.Get <NbtInt>("state").IntValue;
                var _p    = b.Get <NbtList>("pos");
                var pos   = new Vector3()
                {
                    X = _p[0].IntValue, Y = _p[1].IntValue, Z = _p[2].IntValue
                };
                var state = palettes[index];
                if (state != null && state.Get <NbtString>("Name") != null)
                {
                    var block = new BlockCollection.Block();
                    #region Id & Data
                    var id    = state.Get <NbtString>("Name").StringValue;
                    var datas = new List <string>();
                    if (state.Get <NbtCompound>("Properties") != null)
                    {
                        foreach (var _s in state.Get <NbtCompound>("Properties"))
                        {
                            datas.Add(_s.Name + ":" + _s.StringValue);
                        }
                    }
                    var data = string.Join(",", datas.ToArray());
                    #endregion
                    //MessageBox.Show(id + " " + data);
                    if (id != "minecraft:air" && id != "minecraft:void_air" && id != "minecraft:cave_air")
                    {
                        var blockInfo = res.GetBlockInfo(id, data, version);
                        if (blockInfo != null)
                        {
                            block.SetCoordinate((int)pos.X, (int)pos.Y, (int)pos.Z);
                            block.SetInfo(blockInfo);
                            bcl.blocks.Add(block);
                            bcl.level[(int)pos.X, (int)pos.Y, (int)pos.Z] = block;
                        }
                    }
                }

                //Update Progress
                current++;
                Current.DrawProgressBar(current * 100 / total);
            }
            #endregion
        }