示例#1
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = points[0];

            vicMazeGen.cMaze maze     = new vicMazeGen.cMaze();
            string[]         rawLines = main.GetMessage(originalchatline).Split(' ');
            if (rawLines.Length < 4)            //Not enough arguements given
            {
                main.SendMessagePacket("Not enough arguements. (" + (rawLines.Length - 2) + " given, 2 expected.)");
                main.SetDrawerToNull();
                return;
            }
            int mazeX; int mazeY; byte smoothness;  int seed;

            //Required paramters - Fail if these are not found.
            if (!Int32.TryParse(rawLines[2], out mazeX) || !Int32.TryParse(rawLines[3], out mazeY))
            {
                main.SendMessagePacket("Given maze size was in the incorrect format.");
                main.SetDrawerToNull();
                return;
            }             //todo catch divide by zero exceptions.
            //Optional paramters - Otherwise use random numbers.
            if (rawLines.Length > 4 && Byte.TryParse(rawLines[4], out smoothness))
            {
            }
            else
            {
                smoothness = (byte)(new Random().Next(0, 30));
            }
            if (rawLines.Length > 5 && Int32.TryParse(rawLines[5], out seed))
            {
            }
            else
            {
                seed = (new Random().Next(0, Int32.MaxValue));
            }                                                                   //I think it can go larger. Random can't though.
            //Actually generate.
            maze.GenerateMaze(mazeX / 2, mazeY / 2, smoothness, seed);
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            IEnumerator <Vector3I> coordEnumerator = maze.BlockEnumerator(points[0], mazeX, mazeY);

            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true)
                {
                    return;
                }
                Thread.Sleep(sleeptime);
                Coords = coordEnumerator.Current;
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
示例#2
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I firstPoint = points[0];
            Bitmap   myBitmap   = null;

            string[] full = main.GetMessage(originalchatline).Trim().Split(new char[] { ' ' }, 3);
            try { myBitmap = new Bitmap(full[2]); } catch { return; }             //Invalid file, stop drawing.
            myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            byte direction = GetDirection(points);

            if (direction == 4)
            {
                return;
            }

            Block[] refCols = GetReferenceColours();
            Block   currentBlock;

            double[] distance = new double[refCols.Length];
            int      position;

            for (int curwidth = 0; curwidth < myBitmap.Width; curwidth++)
            {
                for (int curheight = 0; curheight < myBitmap.Height; curheight++)
                {
                    currentBlock.Z = (firstPoint.Z + curheight);
                    if (direction == 0)
                    {
                        currentBlock.X = (firstPoint.X + curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if (direction == 1)
                    {
                        currentBlock.X = (firstPoint.X - curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if (direction == 2)
                    {
                        currentBlock.Y = (firstPoint.Y + curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    else
                    {
                        currentBlock.Y = (firstPoint.Y - curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    currentBlock.col = myBitmap.GetPixel(curwidth, curheight);

                    for (int j = 0; j < distance.Length; j++)                        //Calculate distances between the colors in the image and the set reference colors, and store them.
                    {
                        distance[j] = Math.Sqrt(Math.Pow((currentBlock.col.R - refCols[j].col.R), 2) +
                                                Math.Pow((currentBlock.col.B - refCols[j].col.B), 2) +
                                                Math.Pow((currentBlock.col.G - refCols[j].col.G), 2));
                    }
                    position = 0;
                    double minimum = distance[0];
                    for (int h = 1; h < distance.Length; h++)                        //Find the smallest distance in the array of distances.
                    {
                        if (distance[h] < minimum)
                        {
                            minimum  = distance[h];
                            position = h;
                        }
                    }
                    currentBlock.blockType = refCols[position].blockType; //Set the block we found closest to the image to the block we are placing.
                    if (position <= 20)                                   //Back colour blocks
                    {
                        if (direction == 0)
                        {
                            currentBlock.Y += 1;
                        }
                        else if (direction == 1)
                        {
                            currentBlock.Y -= 1;
                        }
                        else if (direction == 2)
                        {
                            currentBlock.X -= 1;
                        }
                        else if (direction == 3)
                        {
                            currentBlock.X += 1;
                        }
                    }                     //Otherwise, draw them in the front row.
                    if (currentBlock.col.A < 20)
                    {
                        currentBlock.blockType = 0;                                                //Transparent pixels.
                    }
                    if (Aborted == true)
                    {
                        return;
                    }
                    Thread.Sleep(sleeptime);
                    main.SendPositionPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z);
                    main.SendBlockPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z, 1, currentBlock.blockType);
                }
            }
            myBitmap.Dispose();
            main.SetDrawerToNull();
        }
示例#3
0
        private void AddPlugins(ClassicBot bot)
        {
            #region Plugins

            CommandDelegate PositionCommand = delegate(string Line)
            {
                bot.SendMessagePacket(String.Format("Positon in world is at {0},{1},{2}.", bot.X, bot.Y, bot.Z));
            };
            bot.RegisteredCommands.Add("position", PositionCommand);

            CommandDelegate AddOpCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                bot.AddOperator(full[1]);
                bot.SendMessagePacket("Allowed user: "******"allow", AddOpCommand);

            CommandDelegate RemoveOpCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 1);
                bot.RemoveOperator(full[1]);
                bot.SendMessagePacket("Disallowed user: "******"disallow", RemoveOpCommand);

            CommandDelegate SayCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                bot.SendMessagePacket(full[1]);
            };
            bot.RegisteredCommands.Add("say", SayCommand);

            CommandDelegate PlayersCommand = delegate(string Line)
            {
                List <string> Names = new List <string>();
                foreach (Player player in bot.Players.Values)
                {
                    Names.Add(player.Name);
                }
                string output = String.Join(",", Names.ToArray());
                bot.SendLongChat("Players in current world: " + output);
            };
            bot.RegisteredCommands.Add("players", PlayersCommand);

            CommandDelegate MoveCommand = delegate(string Line)
            {
                string[] full   = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                string[] coords = full[1].Split(new char[] { ',' }, 3);
                bot.SendPositionPacket(Int16.Parse(coords[0]), Int16.Parse(coords[1]), Int16.Parse(coords[2]));
            };
            bot.RegisteredCommands.Add("move", MoveCommand);

            CommandDelegate PlaceCommand = delegate(string Line)
            {
                string[] full   = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                string[] coords = full[1].Split(new char[] { ',' }, 3);
                bot.SendBlockPacket(Int16.Parse(coords[0]), Int16.Parse(coords[1]), Int16.Parse(coords[2]), 1, 29);
            };
            bot.RegisteredCommands.Add("place", PlaceCommand);

            CommandDelegate HasPaidCommand = delegate(string Line)
            {
                string[] LineSplit = Extensions.StripColors(Line).Split(' ');
                try
                {
                    bool      b;
                    WebClient c        = new WebClient();
                    string    response = c.DownloadString("https://minecraft.net/haspaid.jsp?user="******"minecraft.net returned: " + (int)response.StatusCode + " " + response.StatusCode.ToString());
                        }
                    }
                    else
                    {
                        bot.SendMessagePacket("Unhandled error occured: " + ex.Status.ToString());
                    }
                }
            };
            bot.RegisteredCommands.Add("haspaid", HasPaidCommand);

            CommandDelegate FollowCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                personfollowed = full[1];
                bot.SendMessagePacket("Following user " + full[1]);
            };
            bot.RegisteredCommands.Add("follow", FollowCommand);

            CommandDelegate CuboidCommand = delegate(string Line)
            {
                Cuboid cuboid = new Cuboid();
                bot.SetDrawer(Line, cuboid, 2);
            };
            bot.RegisteredCommands.Add("cuboid", CuboidCommand);

            CommandDelegate PyramidCommand = delegate(string Line)
            {
                Pyramid pyramid = new Pyramid();
                bot.SetDrawer(Line, pyramid, 2);
            };
            bot.RegisteredCommands.Add("pyramid", PyramidCommand);

            CommandDelegate AbortCommand = delegate(string Line)
            {
                bot.CancelDrawer();
                personfollowed = String.Empty;
            };
            bot.RegisteredCommands.Add("abort", AbortCommand);

            CommandDelegate SpeedCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                bot.CuboidSleepTime = 1000 / Int32.Parse(full[1]);
            };
            bot.RegisteredCommands.Add("speed", SpeedCommand);

            CommandDelegate EllipsoidCommand = delegate(string Line)
            {
                Ellipsoid ellipsoid = new Ellipsoid();
                bot.SetDrawer(Line, ellipsoid, 2);
            };
            bot.RegisteredCommands.Add("ellipsoid", EllipsoidCommand);

            CommandDelegate CuboidHCommand = delegate(string Line)
            {
                CuboidHollow cuboidh = new CuboidHollow();
                bot.SetDrawer(Line, cuboidh, 2);
            };
            bot.RegisteredCommands.Add("cuboidh", CuboidHCommand);

            CommandDelegate CuboidWCommand = delegate(string Line)
            {
                CuboidWireframe cuboidw = new CuboidWireframe();
                bot.SetDrawer(Line, cuboidw, 2);
            };
            bot.RegisteredCommands.Add("cuboidw", CuboidWCommand);

            CommandDelegate LineCommand = delegate(string Line)
            {
                Line line = new Line();
                bot.SetDrawer(Line, line, 2);
            };
            bot.RegisteredCommands.Add("line", LineCommand);
            #endregion
        }
示例#4
0
        public static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Welcome to LibClassicBot beta.");
            Console.WriteLine("Below is a list of commands and how to use them");
            Console.WriteLine(".position - Announces the position of the bot in the map.");
            Console.WriteLine(".allow <user> - Adds a user to a list of allowed operators.");
            Console.WriteLine(".disallow <user> - Removes a user from the list of allowed operators.");
            Console.WriteLine(".say <message> - Makes the bot send the specified message.");
            Console.WriteLine(".players - Lists the visibile players to the bot in the current map.");
            Console.WriteLine(".move <x,y,z> - Moves the bot to the specified coordinates.");
            Console.WriteLine(".place <x,y,z> - Attempts to place a block at the specified coordinates.");
            Console.WriteLine(".haspaid <username> - Announces if a user has paid or not.");
            Console.WriteLine(".cuboid <blocktype> - Cuboids between two points.");
            Console.WriteLine(".cuboidh <blocktype> - Draws a hollow cuboid between two points.");
            Console.WriteLine(".cuboidw <blocktype> - Draws a wireframe between two points.");
            Console.WriteLine(".ellipsoid <blocktype> - Draws an ellipsoid between two points.");
            Console.WriteLine(".pyramid <blocktype> - Draws an upwards pyramid between two points.");
            Console.WriteLine(".follow <username> - Follows player. (Case sensitive)");
            Console.WriteLine(".speed <number> - The number of blocks to place per second.");
            Console.WriteLine(".abort - Stops the currently running draw operation.");
            Console.WriteLine(".drawimg 0 <filename> - Attempts to draw the specified image.");
            Console.ResetColor();

            Console.WriteLine("Enter the username to be used by the bot: (Minecraft account)");
            string username = Console.ReadLine();

            Console.WriteLine("Enter the password to be used by the bot: (Minecraft account)");
            string password = Console.ReadLine();

            Console.WriteLine("Enter the address of the server to connect to: ");
            string hash = Console.ReadLine();

            if (!hash.StartsWith("http"))
            {
                if (hash.StartsWith("minecraft"))
                {
                    hash = "http://" + hash;
                }
                else
                {
                    hash = "http://minecraft.net/classic/play/" + hash;
                }
            }

            ClassicBot    Bot1   = new ClassicBot(username, password, hash);
            ConsoleLogger logger = new ConsoleLogger();

            Bot1.RegisterLogger(logger);
            FileLogger file = new FileLogger();

            Bot1.RegisterLogger(file);
            Bot1.Events.ChatMessage          += Bot1_ChatMessage;
            Bot1.Events.PlayerMoved          += Bot1_PlayerMoved;
            Bot1.Events.RemoteSessionStarted += RemoteSessionStarted;
            Bot1.Events.RemoteUserLoggedIn   += RemoteUserLoggedIn;
            Bot1.Events.RemoteSessionEnded   += RemoteSessionEnded;
                        #if !MONO
            Bot1.Events.MapLoaded     += Bot1_MapLoaded;
            Bot1.Events.ConfigLoading += delegate { Console.WriteLine("Loading"); };
                        #endif

            #region Plugins
            CommandDelegate MazeCommand = delegate(string Line)
            {
                Maze maze = new Maze();
                maze.originalchatline = Line;
                Bot1.SetDrawer(Line, maze, 2);
            };
            Bot1.RegisteredCommands.Add("maze", MazeCommand);

            CommandDelegate DrawCommand = delegate(string Line)
            {
                DrawImage img = new DrawImage();
                img.originalchatline = Line;
                Bot1.SetDrawer(Line, img, 2);
            };
            Bot1.RegisteredCommands.Add("drawimg", DrawCommand);

            CommandDelegate PositionCommand = delegate(string Line)
            {
                Bot1.SendMessagePacket(String.Format("Positon in world is at {0},{1},{2}.", Bot1.X, Bot1.Y, Bot1.Z));
            };
            Bot1.RegisteredCommands.Add("position", PositionCommand);

            CommandDelegate AddOpCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.AddOperator(full[1]);
                Bot1.SendMessagePacket("Allowed user: "******"allow", AddOpCommand);

            CommandDelegate RemoveOpCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.RemoveOperator(full[1]);
                Bot1.SendMessagePacket("Disallowed user: "******"disallow", RemoveOpCommand);

            CommandDelegate ListOpsCommand = delegate(string Line)
            {
                string[] names = Bot1.Users.ToArray();
                Bot1.SendLongChat(String.Join(", ", names));
            };
            Bot1.RegisteredCommands.Add("ops", ListOpsCommand);

            CommandDelegate SayCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.SendMessagePacket(full[1]);
            };
            Bot1.RegisteredCommands.Add("say", SayCommand);

            CommandDelegate PlayersCommand = delegate(string Line)
            {
                List <string> Names = new List <string>();
                foreach (Player player in Bot1.Players.Values)
                {
                    Names.Add(player.Name);
                }
                string output = String.Join(",", Names.ToArray());
                Bot1.SendLongChat("Players in current world: " + output);
            };
            Bot1.RegisteredCommands.Add("players", PlayersCommand);

            CommandDelegate MoveCommand = delegate(string Line)
            {
                string[] full   = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                string[] coords = full[1].Split(new char[] { ',' }, 3);
                Bot1.SendPositionPacket(Int16.Parse(coords[0]), Int16.Parse(coords[1]), Int16.Parse(coords[2]));
            };
            Bot1.RegisteredCommands.Add("move", MoveCommand);

            CommandDelegate PlaceCommand = delegate(string Line)
            {
                string[] full   = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                string[] coords = full[1].Split(new char[] { ',' }, 4);
                Bot1.SendBlockPacket(Int16.Parse(coords[0]), Int16.Parse(coords[1]), Int16.Parse(coords[2]), 1, Byte.Parse(coords[3]));
            };
            Bot1.RegisteredCommands.Add("place", PlaceCommand);

            CommandDelegate HasPaidCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                try
                {
                    bool      paid;
                    WebClient client   = new WebClient();
                    string    response = client.DownloadString("https://minecraft.net/haspaid.jsp?user="******"minecraft.net returned: " + (int)response.StatusCode + " " + response.StatusCode.ToString());
                        }
                    }
                    else
                    {
                        Bot1.SendMessagePacket("Unhandled error occured: " + ex.Status.ToString());
                    }
                }
            };
            Bot1.RegisteredCommands.Add("haspaid", HasPaidCommand);

            CommandDelegate FollowCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                personfollowed = full[1];
                Bot1.SendMessagePacket("Following user " + full[1]);
            };
            Bot1.RegisteredCommands.Add("follow", FollowCommand);

            CommandDelegate CuboidCommand = delegate(string Line)
            {
                Cuboid cuboid = new Cuboid();
                Bot1.SetDrawer(Line, cuboid, 2);
            };
            Bot1.RegisteredCommands.Add("cuboid", CuboidCommand);

            CommandDelegate PyramidCommand = delegate(string Line)
            {
                Pyramid pyramid = new Pyramid();
                Bot1.SetDrawer(Line, pyramid, 2);
            };
            Bot1.RegisteredCommands.Add("pyramid", PyramidCommand);

            CommandDelegate AbortCommand = delegate(string Line)
            {
                Bot1.CancelDrawer();
                personfollowed = String.Empty;
            };
            Bot1.RegisteredCommands.Add("abort", AbortCommand);

            CommandDelegate SpeedCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.CuboidSleepTime = 1000 / Int32.Parse(full[1]);
            };
            Bot1.RegisteredCommands.Add("speed", SpeedCommand);

            CommandDelegate EllipsoidCommand = delegate(string Line)
            {
                Ellipsoid ellipsoid = new Ellipsoid();
                Bot1.SetDrawer(Line, ellipsoid, 2);
            };
            Bot1.RegisteredCommands.Add("ellipsoid", EllipsoidCommand);

            CommandDelegate CuboidHCommand = delegate(string Line)
            {
                CuboidHollow cuboidh = new CuboidHollow();
                Bot1.SetDrawer(Line, cuboidh, 2);
            };
            Bot1.RegisteredCommands.Add("cuboidh", CuboidHCommand);

            CommandDelegate CuboidWCommand = delegate(string Line)
            {
                CuboidWireframe cuboidw = new CuboidWireframe();
                Bot1.SetDrawer(Line, cuboidw, 2);
            };
            Bot1.RegisteredCommands.Add("cuboidw", CuboidWCommand);

            CommandDelegate LineCommand = delegate(string Line)
            {
                Line line = new Line();
                Bot1.SetDrawer(Line, line, 2);
            };
            Bot1.RegisteredCommands.Add("line", LineCommand);

            CommandDelegate IgnoreCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.IgnoredUserList.Add(full[1]);
                Bot1.SendMessagePacket("Ignored user: "******"ignore", IgnoreCommand);

            CommandDelegate UnIgnoreCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.IgnoredUserList.Remove(full[1]);
                Bot1.SendMessagePacket("Unignored user: "******"unignore", UnIgnoreCommand);

            /*CommandDelegate TestPosCommand = delegate(string Line)
             * { //Ain't no way to stop it. Uncomment with severe caution.
             *      new System.Threading.Thread(
             *              delegate() {
             *                      Random rnd = new Random();
             *                      while(true){
             *
             *                              int rndval1 = rnd.Next(0, 360);
             *                              byte newpitch = Extensions.DegreesToYaw(rndval1);
             *                              int rndval2 = rnd.Next(0, 360);
             *                              byte newyaw = Extensions.DegreesToYaw(rndval2);
             *                              Bot1.SendPositionPacket(Bot1.X, Bot1.Y, Bot1.Z, newyaw, newpitch);
             *                              System.Threading.Thread.Sleep(10);
             *                      }
             *              }).Start();
             * };
             * Bot1.RegisteredCommands.Add("testpos", TestPosCommand);*/
            #endregion

            StaticBot1 = Bot1;
            Bot1.Start(false);

loop:
            {
                string response = Console.ReadLine();
                Bot1.SendMessagePacket(response);
                goto loop;
            }
        }
示例#5
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I firstPoint = points[0];
            Bitmap myBitmap = null;
            string[] full = main.GetMessage(originalchatline).Trim().Split(new char[] {' '}, 3);
            try { myBitmap = new Bitmap(full[2]); } catch { return; } //Invalid file, stop drawing.
            myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            byte direction = GetDirection(points);
            if (direction == 4) return;

            Block[] refCols = GetReferenceColours();
            Block currentBlock;
            double[] distance = new double[refCols.Length];
            int position;
            for ( int curwidth = 0; curwidth < myBitmap.Width; curwidth++ ) {
                for ( int curheight = 0; curheight < myBitmap.Height; curheight++ ) {

                    currentBlock.Z = (firstPoint.Z + curheight);
                    if(direction == 0) {
                        currentBlock.X = (firstPoint.X + curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if ( direction == 1 ) {
                        currentBlock.X = (firstPoint.X - curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if(direction == 2) {
                        currentBlock.Y = (firstPoint.Y + curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    else {
                        currentBlock.Y = (firstPoint.Y - curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    currentBlock.col = myBitmap.GetPixel(curwidth, curheight);

                    for ( int j = 0; j < distance.Length; j++ ) {//Calculate distances between the colors in the image and the set reference colors, and store them.
                        distance[j] = Math.Sqrt(Math.Pow((currentBlock.col.R - refCols[j].col.R ), 2) +
                                                Math.Pow(( currentBlock.col.B - refCols[j].col.B ), 2) +
                                                Math.Pow(( currentBlock.col.G - refCols[j].col.G ), 2 ));
                    }
                    position = 0;
                    double minimum = distance[0];
                    for ( int h = 1; h < distance.Length; h++ ) {//Find the smallest distance in the array of distances.
                        if ( distance[h] < minimum ) {
                            minimum = distance[h];
                            position = h;
                        }
                    }
                    currentBlock.blockType = refCols[position].blockType;//Set the block we found closest to the image to the block we are placing.
                    if ( position <= 20 ) {//Back colour blocks
                        if ( direction == 0 ) { currentBlock.Y += 1; }
                        else if (direction == 1) { currentBlock.Y -= 1;  }
                        else if ( direction == 2 ) { currentBlock.X -=1; }
                        else if ( direction == 3 ) { currentBlock.X +=1; }
                    } //Otherwise, draw them in the front row.
                    if ( currentBlock.col.A < 20 ) currentBlock.blockType = 0; //Transparent pixels.
                    if (Aborted == true) {
                        return;
                    }
                    Thread.Sleep(sleeptime);
                    main.SendPositionPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z);
                    main.SendBlockPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z, 1, currentBlock.blockType);
                }
            }
            myBitmap.Dispose();
            main.SetDrawerToNull();
        }