コード例 #1
0
        public static SchematicBlock[,,] GetBlocks(RawSchematic rawSchematic)
        {
            //Sorted by height (bottom to top) then length then width -- the index of the block at X,Y,Z is (Y×length + Z)×width + X.
            SchematicBlock[,,] blocks = new SchematicBlock[rawSchematic.XMax, rawSchematic.YMax, rawSchematic.ZMax];
            for (int Y = 0; Y < rawSchematic.YMax; Y++)
            {
                for (int Z = 0; Z < rawSchematic.ZMax; Z++)
                {
                    for (int X = 0; X < rawSchematic.XMax; X++)
                    {
                        int            index = (Y * rawSchematic.ZMax + Z) * rawSchematic.XMax + X;
                        SchematicBlock block = new SchematicBlock();
                        block.BlockID = ((int)rawSchematic.Blocks[index]).ToString();
                        block.Data    = rawSchematic.Data[index];
                        block.X       = X;
                        block.Y       = Y;
                        block.Z       = Z;

                        if (string.IsNullOrEmpty(block.BlockID))
                        {
                            block.BlockID = "0";
                        }

                        blocks[X, Y, Z] = block;
                    }
                }
            }
            return(blocks);
        }
コード例 #2
0
        public static SchematicBlock[,,] GetCSBlocks(RawSchematic raw, NbtTag csBlockTag, SchematicBlock[,,] list)
        {
            NbtList csBlocks = csBlockTag as NbtList;

            if (csBlocks != null)
            {
                foreach (NbtCompound compTag in csBlocks)
                {
                    NbtTag         xTag  = compTag["x"];
                    NbtTag         yTag  = compTag["y"];
                    NbtTag         zTag  = compTag["z"];
                    NbtTag         idTag = compTag["id"];
                    SchematicBlock block = new SchematicBlock()
                    {
                        X       = xTag.IntValue,
                        Y       = yTag.IntValue,
                        Z       = zTag.IntValue,
                        BlockID = idTag.StringValue,
                        CSBlock = true
                    };

                    if (string.IsNullOrEmpty(block.BlockID))
                    {
                        block.BlockID = "0";
                    }

                    list[xTag.IntValue, yTag.IntValue, zTag.IntValue] = block;
                }
            }

            for (int Y = 0; Y <= raw.YMax; Y++)
            {
                for (int Z = 0; Z <= raw.ZMax; Z++)
                {
                    for (int X = 0; X <= raw.XMax; X++)
                    {
                        if (list[X, Y, Z] == null)
                        {
                            list[X, Y, Z] = new SchematicBlock()
                            {
                                X       = X,
                                Y       = Y,
                                Z       = Z,
                                BlockID = ColonyBuiltIn.ItemTypes.AIR,
                                CSBlock = true
                            }
                        }
                        ;
                    }
                }
            }

            return(list);
        }
コード例 #3
0
        public static Schematic LoadSchematic(NbtFile nbtFile, Vector3Int startPos)
        {
            RawSchematic raw = LoadRaw(nbtFile);

            SchematicBlock[,,] blocks = default(SchematicBlock[, , ]);

            if (raw.CSBlocks != null && raw.CSBlocks.Length > 0)
            {
                blocks = raw.CSBlocks;
            }
            else
            {
                blocks = GetBlocks(raw);
            }

            string    name      = Path.GetFileNameWithoutExtension(nbtFile.FileName);
            Schematic schematic = new Schematic(name, raw.XMax, raw.YMax, raw.ZMax, blocks, startPos);

            return(schematic);
        }
コード例 #4
0
        public static RawSchematic LoadRaw(NbtFile nbtFile)
        {
            RawSchematic raw     = new RawSchematic();
            var          rootTag = nbtFile.RootTag;

            foreach (NbtTag tag in rootTag.Tags)
            {
                switch (tag.Name)
                {
                case "Width":     //Short
                    if (rootTag.Contains("CSBlocks"))
                    {
                        raw.XMax = tag.IntValue + 1;
                    }
                    else
                    {
                        raw.XMax = tag.IntValue;
                    }
                    break;

                case "Height":     //Short
                    if (rootTag.Contains("CSBlocks"))
                    {
                        raw.YMax = tag.IntValue + 1;
                    }
                    else
                    {
                        raw.YMax = tag.IntValue;
                    }
                    break;

                case "Length":     //Short
                    if (rootTag.Contains("CSBlocks"))
                    {
                        raw.ZMax = tag.IntValue + 1;
                    }
                    else
                    {
                        raw.ZMax = tag.IntValue;
                    }
                    break;

                case "Materials":     //String
                    raw.Materials = tag.StringValue;
                    break;

                case "Blocks":     //ByteArray
                    raw.Blocks = tag.ByteArrayValue;
                    break;

                case "Data":     //ByteArray
                    raw.Data = tag.ByteArrayValue;
                    break;

                case "Entities": //List
                    break;       //Ignore

                case "Icon":     //Compound
                    break;       //Ignore

                case "CSBlocks":
                    raw.CSBlocks = GetCSBlocks(raw, tag, new SchematicBlock[raw.XMax + 1, raw.YMax + 1, raw.ZMax + 1]);
                    break;

                case "SchematicaMapping": //Compound
                    tag.ToString();
                    break;                //Ignore

                default:
                    break;
                }
            }
            return(raw);
        }