public static void Square(bool s, int r, int lenght, Position pos, int blockID, TerrainRaycastResult?Point1, SubsystemTerrain subsystemTerrain)
 {
     Task.Run(() =>
     {
         int num1 = 0;
         for (int index1 = 0; index1 < lenght; ++index1)
         {
             for (int index2 = -r; index2 <= r; ++index2)
             {
                 for (int index3 = -r; index3 <= r; ++index3)
                 {
                     if (Math.Abs(index2) + Math.Abs(index3) <= r && (!s || Math.Abs(index2) + Math.Abs(index3) >= r))
                     {
                         int num2 = !true ? -index1 : index1;
                         if (pos == Position.flat)
                         {
                             subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + num2, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z + index3, blockID, true);
                         }
                         else if (pos == Position.X)
                         {
                             subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index2, Point1.Value.CellFace.Point.Y + num2, Point1.Value.CellFace.Point.Z + index3, blockID, true);
                         }
                         else
                         {
                             subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index2, Point1.Value.CellFace.Point.Y + index3, Point1.Value.CellFace.Point.Z + num2, blockID, true);
                         }
                         ++num1;
                     }
                 }
             }
         }
         // this.player.ComponentGui.DisplaySmallMessage(string.Format("操作成功,共生成{0}个方块", (object)num1), true, true);
     });
 }
 public static void Sphere(bool s, int r, int id, TerrainRaycastResult?Point1, SubsystemTerrain subsystemTerrain)
 {
     Task.Run(() =>
     {
         int num = 0;
         for (int index1 = -r; index1 <= 0; ++index1)
         {
             for (int index2 = -r; index2 <= 0; ++index2)
             {
                 for (int index3 = -r; index3 <= 0; ++index3)
                 {
                     if ((int)Math.Sqrt(index1 * index1 + index2 * index2 + index3 * index3) <= r && (!s || (int)Math.Sqrt((double)((index1 - 1) * (index1 - 1) + index2 * index2 + index3 * index3)) > r || ((int)Math.Sqrt((double)(index1 * index1 + (index2 - 1) * (index2 - 1) + index3 * index3)) > r || (int)Math.Sqrt((double)(index1 * index1 + index2 * index2 + (index3 - 1) * (index3 - 1))) > r)))
                     {
                         subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index1, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z + index3, id, true);
                         subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X - index1, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z + index3, id, true);
                         subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X - index1, Point1.Value.CellFace.Point.Y - index2, Point1.Value.CellFace.Point.Z + index3, id, true);
                         subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X - index1, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z - index3, id, true);
                         subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X - index1, Point1.Value.CellFace.Point.Y - index2, Point1.Value.CellFace.Point.Z - index3, id, true);
                         subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index1, Point1.Value.CellFace.Point.Y - index2, Point1.Value.CellFace.Point.Z + index3, id, true);
                         subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index1, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z - index3, id, true);
                         subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index1, Point1.Value.CellFace.Point.Y - index2, Point1.Value.CellFace.Point.Z - index3, id, true);
                         num += 8;
                     }
                 }
             }
         }
         //this.player.ComponentGui.DisplaySmallMessage(string.Format("操作成功,共生成{0}个方块", (object)num), true, true);
     });
 }
        public static void Paste_zone(Point3 Point3, SubsystemTerrain subsystemTerrain, ComponentPlayer player, string path)
        {
            FileStream fileStream = new FileStream(path, FileMode.Open);

            BinaryReader engineBinaryReader = new BinaryReader(fileStream);



            engineBinaryReader.BaseStream.Position = 7L;

            int num2 = engineBinaryReader.ReadInt32();

            try
            {
                for (var i = 0; i < num2; i++)
                {
                    var xPos = Point3.X + engineBinaryReader.ReadInt32();
                    var yPos = Point3.Y + engineBinaryReader.ReadInt32();
                    var zPos = Point3.Z + engineBinaryReader.ReadInt32();
                    var id   = engineBinaryReader.ReadInt32();

                    subsystemTerrain.ChangeCell(xPos, yPos, zPos, id);
                }
            }
            catch (Exception ex)
            {
                player.ComponentGui.DisplaySmallMessage(string.Format("Sucsses {0} place blocks", num2), true, true);
            }

            engineBinaryReader.Dispose();
            fileStream.Dispose();
        }
 public static void Mountain(Point3 Start, int Radius, int Size, SubsystemTerrain subsystemTerrain, int id, int id1, int id2, ComponentPlayer player)
 {
     Task.Run(() =>
     {
         Game.Random random = new Game.Random();
         double num1        = Math.PI / 2.0;
         float num2         = (float)Size + 0.8f;
         int num3           = 0;
         double num4        = 10.0;
         double num5        = 15.0;
         float num6         = random.UniformFloat((float)num4, (float)num5) + 10f;
         for (int index1 = -Radius; index1 < Radius; ++index1)
         {
             for (int index2 = -Radius; index2 < Radius; ++index2)
             {
                 double num7  = Math.Cos(num1 * (double)index1 / (double)Radius) * Math.Cos(num1 * (double)index2 / (double)Radius) * (double)num2;
                 double num8  = Math.Sin(num1 * (double)index1 * 1.39999997615814 / (double)Radius + 4.0) * Math.Cos(num1 * (double)index2 * 1.39999997615814 / (double)Radius + 7.0) * (double)num2 * 0.25;
                 double num9  = Math.Cos(num1 * (double)index1 * 1.39999997615814 * 2.0 / (double)Radius + 4.0 * (double)num6) * Math.Sin(num1 * (double)index2 * 1.39999997615814 * 2.0 / (double)Radius + 8.0 * (double)num6) * (double)num2 * 0.200000002980232;
                 double num10 = Math.Sin(num1 * (double)index1 * 1.39999997615814 * 4.0 / (double)Radius + 4.0 * (double)num6 * 1.5) * Math.Sin(num1 * (double)index2 * 1.39999997615814 * 4.0 / (double)Radius + 8.0 * (double)num6 * 1.5) * (double)num2 * 0.150000005960464;
                 double num11 = num8;
                 double num12 = num7 - num11 + num9 - num10;
                 if (num12 > 0.0)
                 {
                     for (int index3 = 0; (double)index3 <= num12; ++index3)
                     {
                         if (index3 > 3)
                         {
                             subsystemTerrain.ChangeCell(Start.X + index1, Start.Y + (int)num12 - index3, Start.Z + index2, id, true);
                             ++num3;
                         }
                         else if (index3 > 0)
                         {
                             subsystemTerrain.ChangeCell(Start.X + index1, Start.Y + (int)num12 - index3, Start.Z + index2, id1, true);
                             ++num3;
                         }
                         else if (index3 == 0)
                         {
                             subsystemTerrain.ChangeCell(Start.X + index1, Start.Y + (int)num12, Start.Z + index2, id2, true);
                             ++num3;
                         }
                     }
                 }
             }
         }
         player.ComponentGui.DisplaySmallMessage(string.Format("Sucsses {0} place blocks", num3), true, true);
     });
 }
        /*
         *
         * public static void lingZhui(bool s, int r, int blockID, TerrainRaycastResult? Point1, SubsystemTerrain subsystemTerrain)
         * {
         *
         *  Task.Run(() =>
         *  {
         *      int num = 0;
         *      for (int index1 = -r; index1 <= r; ++index1)
         *      {
         *          for (int index2 = -r; index2 <= r; ++index2)
         *          {
         *              for (int index3 = -r; index3 <= r; ++index3)
         *              {
         *                  if (Math.Abs(index1) + Math.Abs(index2) + Math.Abs(index3) <= r && (!s || Math.Abs(index1) + Math.Abs(index2) + Math.Abs(index3) >= r))
         *                  {
         *
         *                      subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index1, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z + index3, blockID, true);
         ++num;
         *
         *                  }
         *              }
         *          }
         *      }
         *      // this.player.ComponentGui.DisplaySmallMessage(string.Format("操作成功,共生成{0}个方块", (object)num), true, true);
         *  });
         * }
         */



        public static void CreativeMaze(Point3 Start, Point3 End, int BlockID, SubsystemTerrain subsystemTerrain, ComponentPlayer player)
        {
            if (Start.X < End.X)
            {
                int x = Start.X;
                Start.X = End.X;
                End.X   = x;
            }
            if (Start.Y < End.Y)
            {
                int y = Start.Y;
                Start.Y = End.Y;
                End.Y   = y;
            }
            if (Start.Z < End.Z)
            {
                int z = Start.Z;
                Start.Z = End.Z;
                End.Z   = z;
            }
            if (Start.Z - End.Z < 5 || Start.X - End.X < 5)
            {
                player.ComponentGui.DisplaySmallMessage("Too small", true, true);
            }
            else
            {
                Task.Run(() =>
                {
                    int num1          = 0;
                    int num2          = Start.X - End.X;
                    int num3          = Start.Z - End.Z;
                    bool[,] boolArray = new Maze(num2 / 2, num3 / 2).GetBoolArray();
                    for (int index1 = 0; index1 <= (num2 % 2 != 0 ? num2 - 1 : num2); ++index1)
                    {
                        for (int index2 = 0; index2 <= (num3 % 2 != 0 ? num3 - 1 : num3); ++index2)
                        {
                            if ((index1 != 1 || index2 != 0) && (index1 != (num2 % 2 != 0 ? num2 - 1 : num2) || index2 != (num3 % 2 != 0 ? num3 - 1 : num3) - 1) && boolArray[index1, index2])
                            {
                                for (int index3 = 0; index3 <= Start.Y - End.Y; ++index3)
                                {
                                    subsystemTerrain.ChangeCell(End.X + index1, End.Y + index3, End.Z + index2, BlockID, true);
                                    ++num1;
                                }
                            }
                        }
                    }
                    player.ComponentGui.DisplaySmallMessage(string.Format("Sucsses {0} place blocks", num1), true, true);
                });
            }
        }
        public static void LinePoint(Point3 v, Point3 v2, int id, SubsystemTerrain subsystemTerrain)
        {
            int lengin = Math.Max(Math.Max(Math.Abs(v.X - v2.X), Math.Abs(v.Y - v2.Y)), Math.Abs(v.Z - v2.Z));

            Task.Run((Action)(() =>
            {
                int num = 0;
                for (int index = 0; index <= lengin; ++index)
                {
                    int cellValueFast = subsystemTerrain.Terrain.GetCellValueFast(v.X + (int)Math.Round((double)index / (double)lengin * (double)(v2.X - v.X)), v.Y + (int)Math.Round((double)index / (double)lengin * (double)(v2.Y - v.Y)), v.Z + (int)Math.Round((double)index / (double)lengin * (double)(v2.Z - v.Z)));
                    if (cellValueFast != id && Terrain.ExtractContents(cellValueFast) != id)
                    {
                        subsystemTerrain.ChangeCell(v.X + (int)Math.Round((double)index / (double)lengin * (double)(v2.X - v.X)), v.Y + (int)Math.Round((double)index / (double)lengin * (double)(v2.Y - v.Y)), v.Z + (int)Math.Round((double)index / (double)lengin * (double)(v2.Z - v.Z)), id, true);
                        ++num;
                    }
                }
                // this.player.ComponentGui.DisplaySmallMessage(string.Format("操作成功,共生成{0}个方块", (object)num), true, true);
            }));
        }
        public static void Prism(bool s, int r, int blockID, TerrainRaycastResult?Point1, SubsystemTerrain subsystemTerrain)
        {
            int num = 0;

            for (int index1 = -r; index1 <= r; ++index1)
            {
                for (int index2 = -r; index2 <= r; ++index2)
                {
                    for (int index3 = -r; index3 <= r; ++index3)
                    {
                        if (Math.Abs(index1) + Math.Abs(index2) + Math.Abs(index3) <= r && (!s || Math.Abs(index1) + Math.Abs(index2) + Math.Abs(index3) >= r))
                        {
                            subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index1, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z + index3, blockID);
                            ++num;
                        }
                    }
                }
            }
            // m_componentPlayer.ComponentGui.DisplaySmallMessage(string.Format("8989789797", (object)num), true, true);
        }
 public static void Rectangle(int pos, int blockId, Point3 Start, Point3 End, ComponentPlayer player, SubsystemTerrain subsystemTerrain)
 {
     if (Start.X < End.X)
     {
         int x = Start.X;
         Start.X = End.X;
         End.X   = x;
     }
     if (Start.Y < End.Y)
     {
         int y = Start.Y;
         Start.Y = End.Y;
         End.Y   = y;
     }
     if (Start.Z < End.Z)
     {
         int z = Start.Z;
         Start.Z = End.Z;
         End.Z   = z;
     }
     Task.Run((Action)(() =>
     {
         int num = 0;
         for (int index1 = 0; index1 <= Start.X - End.X; ++index1)
         {
             for (int index2 = 0; index2 <= Start.Y - End.Y; ++index2)
             {
                 for (int index3 = 0; index3 <= Start.Z - End.Z; ++index3)
                 {
                     if ((pos != 1 || index1 <= 0 || (index1 >= Start.X - End.X || index2 <= 0) || (index2 >= Start.Y - End.Y || index3 <= 0 || index3 >= Start.Z - End.Z)) && (pos != 2 || (index1 < 0 || index1 > Start.X - End.X || (index2 <= 0 || index2 >= Start.Y - End.Y) || (index3 <= 0 || index3 >= Start.Z - End.Z)) && (index2 < 0 || index2 > Start.Y - End.Y || (index1 <= 0 || index1 >= Start.X - End.X) || (index3 <= 0 || index3 >= Start.Z - End.Z)) && (index3 < 0 || index3 > Start.Z - End.Z || (index2 <= 0 || index2 >= Start.Y - End.Y) || (index1 <= 0 || index1 >= Start.X - End.X))))
                     {
                         subsystemTerrain.ChangeCell(End.X + index1, End.Y + index2, End.Z + index3, blockId, true);
                         ++num;
                     }
                 }
             }
         }
         player.ComponentGui.DisplaySmallMessage(string.Format("Sucsses {0} place blocks", num), true, true);
     }));
 }
 public void SetCell(int x, int y, int z, int id)
 {
     m_subsystemTerrain.ChangeCell(x, y, z, id, true);
 }
        public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem)
        {
            if (cellFace.Y < 0 || cellFace.Y > 127 || worldItem.Velocity.Length() < 10f)
            {
                return;
            }
            int value = Terrain.ExtractContents(worldItem.Value);

            if (value == 102)
            {
                for (int i = -1; i < 2; i++)
                {
                    for (int j = -1; j < 2; j++)
                    {
                        int cellValueFast = SubsystemTerrain.Terrain.GetCellValueFast(cellFace.X + i, cellFace.Y, cellFace.Z + j);
                        if (Terrain.ExtractContents(cellValueFast) == 168)
                        {
                            SubsystemTerrain.ChangeCell(cellFace.X + i, cellFace.Y, cellFace.Z + j, 168 | SoilBlock.SetNitrogen(Terrain.ExtractData(cellValueFast), 3) << 14);
                            worldItem.ToRemove = true;
                        }
                    }
                }
            }
            else if (value == SeedsBlock.Index && SubsystemTerrain.Terrain.GetCellContentsFast(cellFace.X, cellFace.Y + 1, cellFace.Z) == 0)
            {
                value = 0;
                switch (worldItem.Value)
                {
                case 16557:
                    value = 20 | FlowerBlock.SetIsSmall(0, true) << 14;
                    break;

                case 173:
                    value = 19 | TallGrassBlock.SetIsSmall(0, true) << 14;
                    break;

                case 49325:
                    value = 25 | FlowerBlock.SetIsSmall(0, true) << 14;
                    break;

                case 32941:
                    value = 24 | FlowerBlock.SetIsSmall(0, true) << 14;
                    break;

                case 82093:
                    value = 174 | RyeBlock.SetSize(RyeBlock.SetIsWild(0, false), 0) << 14;
                    break;

                case 65709:
                    value = 174 | RyeBlock.SetSize(RyeBlock.SetIsWild(0, false), 0) << 14;
                    break;

                case 114861:
                    value = 131 | BasePumpkinBlock.SetSize(BasePumpkinBlock.SetIsDead(0, false), 0) << 14;
                    break;

                case 98477:
                    value = 204 | CottonBlock.SetSize(CottonBlock.SetIsWild(0, false), 0) << 14;
                    break;
                }
                if (value != 0)
                {
                    SubsystemTerrain.ChangeCell(cellFace.X, cellFace.Y + 1, cellFace.Z, value);
                    worldItem.ToRemove = true;
                }
            }
        }
        public static void Round(bool s, int radius, int lenght, int pos, int id, TerrainRaycastResult?Point1, SubsystemTerrain subsystemTerrain, ComponentPlayer player)
        {
            Task.Run(() =>
            {
                string s2 = Convert.ToString(pos);
                //int num1 = 0;
                for (int index1 = 0; index1 < lenght; ++index1)
                {
                    for (int index2 = -radius; index2 <= 0; ++index2)
                    {
                        for (int index3 = -radius; index3 <= 0; ++index3)
                        {
                            if ((int)Math.Sqrt((double)(index2 * index2 + index3 * index3)) <= radius && (!s || (int)Math.Sqrt((double)((index2 - 1) * (index2 - 1) + index3 * index3)) > radius || (int)Math.Sqrt((double)(index2 * index2 + (index3 - 1) * (index3 - 1))) > radius))
                            {
                                int num2 = !true ? -index1 : index1;
                                if (pos == 2)
                                {
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + num2, Point1.Value.CellFace.Point.Y - index2, Point1.Value.CellFace.Point.Z - index3, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + num2, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z - index3, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + num2, Point1.Value.CellFace.Point.Y - index2, Point1.Value.CellFace.Point.Z + index3, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + num2, Point1.Value.CellFace.Point.Y + index2, Point1.Value.CellFace.Point.Z + index3, id, true);
                                }
                                if (pos == 1)
                                {
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index2, Point1.Value.CellFace.Point.Y + num2, Point1.Value.CellFace.Point.Z + index3, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index2, Point1.Value.CellFace.Point.Y + num2, Point1.Value.CellFace.Point.Z - index3, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X - index2, Point1.Value.CellFace.Point.Y + num2, Point1.Value.CellFace.Point.Z + index3, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X - index2, Point1.Value.CellFace.Point.Y + num2, Point1.Value.CellFace.Point.Z - index3, id, true);
                                }
                                if (pos == 3)
                                {
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index2, Point1.Value.CellFace.Point.Y - index3, Point1.Value.CellFace.Point.Z + num2, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X + index2, Point1.Value.CellFace.Point.Y + index3, Point1.Value.CellFace.Point.Z + num2, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X - index2, Point1.Value.CellFace.Point.Y + index3, Point1.Value.CellFace.Point.Z + num2, id, true);
                                    subsystemTerrain.ChangeCell(Point1.Value.CellFace.Point.X - index2, Point1.Value.CellFace.Point.Y - index3, Point1.Value.CellFace.Point.Z + num2, id, true);
                                }

                                // num1 += 4;
                            }
                        }
                    }
                }
            });
        }
        // public static readonly string sdcard = "/sdcard/Survivalcraft/WorldEdit";

        // public readonly string oneKeyFile =
        // public readonly string CopyFile = string.Format("{0}/Cache/Cache.w", (object));



        public static void draw_img(bool mirror, int ofset_paletr, bool save_colors, bool use_castom_paletr, int deep_color, bool on_furn, int size, int furn_resol, bool pos, bool rotate, string pa, Point3 start, SubsystemTerrain subsystemTerrain, ComponentPlayer p)
        {
            Task.Run(() =>
            {
                try
                {
                    System.Drawing.Bitmap im = null;
                    try
                    {
                        im = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(pa);
                    }
                    catch (Exception ex)
                    {
                        p.ComponentGui.DisplaySmallMessage(string.Format("Error read image"), true, true);

                        return;
                    }



                    if (!on_furn)
                    {
                        furn_resol = 1;
                    }



                    if (!mirror)
                    {
                        im.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX);
                    }



                    if (pos)
                    {
                        im.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                    }



                    im = (new System.Drawing.Bitmap(im, new System.Drawing.Size(im.Width / size, im.Height / size)));



                    var num1 = 0;
                    for (var index = 0; index < 1024; ++index)
                    {
                        if (subsystemTerrain.SubsystemFurnitureBlockBehavior.GetDesign(index) != null)
                        {
                            ++num1;
                        }
                    }
                    num1  = 1024 - num1;
                    var a = (im.Width / furn_resol) * (im.Height / furn_resol);

                    if (on_furn && a > num1)
                    {
                        p.ComponentGui.DisplaySmallMessage(string.Format("Not enough furniture blocks (" + num1.ToString() + "/" + a.ToString() + ")"), true, true);

                        return;
                    }



                    Image img = new Image(im.Width, im.Height);

                    for (int x = 0; x < im.Width; x++)
                    {
                        for (int y = 0; y < im.Height; y++)
                        {
                            img.SetPixel(x, y, new Color(im.GetPixel(x, y).R, im.GetPixel(x, y).G, im.GetPixel(x, y).B, im.GetPixel(x, y).A));
                        }
                    }


                    if (use_castom_paletr)
                    {
                        top_colors(ofset_paletr, save_colors, deep_color, img, subsystemTerrain.SubsystemPalette);
                    }


                    List <int> fur_bl_img = new List <int>();
                    for (int x = 0; x < img.Width / furn_resol; x++)
                    {
                        for (int y = 0; y < img.Height / furn_resol; y++)
                        {
                            if (on_furn)
                            {
                                List <int> bl_img = new List <int>();
                                bool is_a_bl      = false;
                                for (int x1 = 0; x1 < furn_resol; x1++)
                                {
                                    for (int y1 = 0; y1 < furn_resol; y1++)
                                    {
                                        if (get_block_id(GetClosestColor(subsystemTerrain.SubsystemPalette.m_colors, img.GetPixel((x * furn_resol) + x1, (y * furn_resol) + y1)), subsystemTerrain.SubsystemPalette) != 0 && is_a_bl == false)
                                        {
                                            is_a_bl = true;
                                        }
                                        bl_img.Add(get_block_id(GetClosestColor(subsystemTerrain.SubsystemPalette.m_colors, img.GetPixel((x * furn_resol) + x1, (y * furn_resol) + y1)), subsystemTerrain.SubsystemPalette));
                                    }
                                }
                                if (is_a_bl)
                                {
                                    int img_id = create_dsg(rotate, pos, furn_resol, bl_img, subsystemTerrain, ("x " + x.ToString() + "  " + "y " + y.ToString()).ToString());
                                    if (pos)
                                    {
                                        if (rotate)
                                        {
                                            subsystemTerrain.ChangeCell(start.X, start.Y + x, start.Z + y, img_id);
                                        }
                                        else
                                        {
                                            subsystemTerrain.ChangeCell(start.X + y, start.Y + x, start.Z, img_id);
                                        }
                                    }
                                    else
                                    {
                                        subsystemTerrain.ChangeCell(start.X + y, start.Y, start.Z + x, img_id);
                                    }
                                }
                            }
                            else
                            {
                                int img_id = get_block_id(GetClosestColor(subsystemTerrain.SubsystemPalette.m_colors, img.GetPixel(x, y)), subsystemTerrain.SubsystemPalette);
                                if (pos)
                                {
                                    if (rotate)
                                    {
                                        subsystemTerrain.ChangeCell(start.X, start.Y + x, start.Z + y, img_id);
                                    }
                                    else
                                    {
                                        subsystemTerrain.ChangeCell(start.X + y, start.Y + x, start.Z, img_id);
                                    }
                                }
                                else
                                {
                                    subsystemTerrain.ChangeCell(start.X + y, start.Y, start.Z + x, img_id);
                                }
                            }
                        }
                    }

                    p.ComponentGui.DisplaySmallMessage(string.Format("Success " + a + " blocks"), true, true);

                    AnalyticsManager.LogEvent("WE image sucsees", new AnalyticsParameter("blocks", a.ToString()));
                }catch (Exception ex)
                {
                    p.ComponentGui.DisplaySmallMessage(string.Format("Failed cause: " + ex.Message), true, true);
                    AnalyticsManager.LogError("WE image fail", ex);
                }
            });
        }