private void MoveTo(McTcpClient handler, Location goal)
 {
     if (!handler.GetWorld().GetBlock(goal + new Location(0, -1, 0)).Type.IsSolid())
     {
         handler.PlaceBlock(1, goal + new Location(0, -1, 0));
         Thread.Sleep(100);
     }
     if (handler.GetWorld().GetBlock(goal + new Location(0, 1, 0)).Type.IsSolid())
     {
         BreakBlock(handler, goal + new Location(0, 1, 0));
         Thread.Sleep(100);
     }
     goal += new Location(0.5, 0, 0.5);
     handler.UpdateLocation(goal, goal + new Location(0, 1, 0));
     handler.handler.SendLocationUpdate(goal, true, handler.yaw, handler.pitch);
 }
 private bool BreakBlock(McTcpClient handler, Location goal)
 {
     if (!handler.GetWorld().GetBlock(goal).Type.IsSolid())
     {
         return(false);
     }
     handler.DiggingBlock(0, goal);
     return(true);
 }
예제 #3
0
파일: Move.cs 프로젝트: gdianaty/MinechatPC
 public override string Run(McTcpClient handler, string command)
 {
     if (Settings.TerrainAndMovements)
     {
         string[] args = getArgs(command);
         if (args.Length == 1)
         {
             string dirStr = getArg(command).Trim().ToLower();
             Direction direction;
             switch (dirStr)
             {
                 case "up": direction = Direction.Up; break;
                 case "down": direction = Direction.Down; break;
                 case "east": direction = Direction.East; break;
                 case "west": direction = Direction.West; break;
                 case "north": direction = Direction.North; break;
                 case "south": direction = Direction.South; break;
                 case "get": return handler.GetCurrentLocation().ToString();
                 default: return "Unknown direction '" + dirStr + "'.";
             }
             if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
             {
                 handler.MoveTo(Movement.Move(handler.GetCurrentLocation(), direction));
                 return "Moving " + dirStr + '.';
             }
             else return "Cannot move in that direction.";
         }
         else if (args.Length == 3)
         {
             try
             {
                 int x = int.Parse(args[0]);
                 int y = int.Parse(args[1]);
                 int z = int.Parse(args[2]);
                 Location goal = new Location(x, y, z);
                 if (handler.MoveTo(goal))
                     return "Walking to " + goal;
                 return "Failed to compute path to " + goal;
             }
             catch (FormatException) { return CMDDesc; }
         }
         else return CMDDesc;
     }
     else return "Please enable terrainandmovements in config to use this command.";
 }
예제 #4
0
 public override string Run(McTcpClient handler, string command, Dictionary <string, object> localVars)
 {
     string[] args = getArgs(command);
     if (args.Length == 3 || args.Length == 4)
     {
         try
         {
             //hotbar 0-8
             int hotbar;
             int x, y, z;
             if (args.Length == 4)
             {
                 hotbar = int.Parse(args[0]);
                 x      = int.Parse(args[1]);
                 y      = int.Parse(args[2]);
                 z      = int.Parse(args[3]);
             }
             else
             {
                 hotbar = 8;
                 x      = int.Parse(args[0]);
                 y      = int.Parse(args[1]);
                 z      = int.Parse(args[2]);
             }
             Location goal = new Location(x, y, z);
             if (!handler.GetWorld().GetBlock(goal).Type.IsLiquid())
             {
                 return("Can't bucket solid block or air");
             }
             if (FindBucketAndUse(handler, hotbar, goal))
             {
                 return("Use bucket at " + goal);
             }
             return("Failed to use bucket at " + goal);
         }
         catch (FormatException) { return(CMDDesc); }
     }
     else
     {
         return(CMDDesc);
     }
 }
예제 #5
0
        public override string Run(string command, string[] args, string argStr)
        {
            McTcpClient handler = tcpClientRetriever.GetTcpClient();

            if (args.Length == 1)
            {
                if (argStr == "get")
                {
                    return(handler.player.GetCurrentLocation().ToString());
                }

                Direction direction = DirectionMethods.FromString(argStr);

                if (Movement.CanMove(handler.GetWorld(), handler.player.GetCurrentLocation(), direction))
                {
                    //handler.player.MoveTo(Movement.Move(handler.player.GetCurrentLocation(), direction));
                    return("Moving " + argStr + '.');
                }
                else
                {
                    return("Cannot move in that direction.");
                }
            }
            else if (args.Length == 3)
            {
                try
                {
                    int      x    = int.Parse(args[0]);
                    int      y    = int.Parse(args[1]);
                    int      z    = int.Parse(args[2]);
                    Location goal = new Location(x, y, z);
                    //if (handler.player.MoveTo(goal))
                    //return "Walking to " + goal;
                    return("Failed to compute path to " + goal);
                }
                catch (FormatException) { return(CMDDesc); }
            }
            else
            {
                return(CMDDesc);
            }
        }
        private bool FindBucketAndUse(McTcpClient handler, int hotbar, Location block)
        {
            if (!handler.GetWorld().GetBlock(block).Type.IsLiquid())
            {
                return(false);
            }
            ConsoleIO.WriteLine("use bucket at " + block.ToString());
            Container container   = handler.GetPlayerInventory();
            Container inventory   = new Container(container.ID, container.Type, container.Title, container.Items);
            bool      found       = false;
            byte      CurrentSlot = handler.GetCurrentSlot();

            if (inventory.Items.ContainsKey(CurrentSlot + 36) && inventory.Items[CurrentSlot + 36].Type == ItemType.Bucket)
            {
                found = true;
            }
            else
            {
                Thread.Sleep(100);
                for (int i = 36; i <= 44; i++)
                {
                    if (!inventory.Items.ContainsKey(i))
                    {
                        continue;
                    }
                    if (inventory.Items[i].Type == ItemType.Bucket)
                    {
                        int slot = i - 36;
                        handler.ChangeSlot((short)slot);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    for (int i = 9; i <= 35; i++)
                    {
                        if (!inventory.Items.ContainsKey(i))
                        {
                            continue;
                        }
                        if (inventory.Items[i].Type == ItemType.Bucket)
                        {
                            handler.ClickWindowSlot(0, i, hotbar, 2);
                            handler.ChangeSlot((short)hotbar);
                            found = true;
                            break;
                        }
                    }
                }
            }
            if (found)
            {
                handler.UpdateLocation(handler.GetCurrentLocation(), block);
                Thread.Sleep(200);
                handler.UseItemOnHand();
                Thread.Sleep(500);
                if (handler.GetWorld().GetBlock(block).Type.IsLiquid())
                {
                    for (int i = 36; i <= 44; i++)
                    {
                        if (!inventory.Items.ContainsKey(i))
                        {
                            continue;
                        }
                        if (inventory.Items[i].Type == ItemType.Bucket)
                        {
                            int slot = i - 36;
                            handler.ChangeSlot((short)slot);
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        Thread.Sleep(200);
                        handler.UseItemOnHand();
                        Thread.Sleep(200);
                    }
                    if (handler.GetWorld().GetBlock(block).Type.IsLiquid())
                    {
                        handler.PlaceBlock(1, block);
                        ConsoleIO.WriteLine("fail to use bucket, place block instead");
                        Thread.Sleep(100);
                    }
                }
                handler.ChangeSlot(CurrentSlot);
            }
            return(found);
        }
예제 #7
0
        public override string Run(McTcpClient handler, string command, Dictionary <string, object> localVars)
        {
            string[] args   = getArgs(command);
            string   argStr = getArg(command).Trim().ToLower();

            if (argStr == "on")
            {
                handler.SetTerrainEnabled(true);
                return("Enabling Terrain and Movements on next server login, respawn or world change.");
            }
            else if (argStr == "off")
            {
                handler.SetTerrainEnabled(false);
                return("Disabling Terrain and Movements.");
            }
            else if (handler.GetTerrainEnabled())
            {
                if (args.Length == 1)
                {
                    Direction direction;
                    switch (argStr)
                    {
                    case "up": direction = Direction.Up; break;

                    case "down": direction = Direction.Down; break;

                    case "east": direction = Direction.East; break;

                    case "west": direction = Direction.West; break;

                    case "north": direction = Direction.North; break;

                    case "south": direction = Direction.South; break;

                    case "get": return(handler.GetCurrentLocation().ToString());

                    default: return("Unknown direction '" + argStr + "'.");
                    }
                    if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
                    {
                        handler.MoveTo(Movement.Move(handler.GetCurrentLocation(), direction));
                        return("Moving " + argStr + '.');
                    }
                    else
                    {
                        return("Cannot move in that direction.");
                    }
                }
                else if (args.Length == 3)
                {
                    try
                    {
                        int      x    = int.Parse(args[0]);
                        int      y    = int.Parse(args[1]);
                        int      z    = int.Parse(args[2]);
                        Location goal = new Location(x, y, z);
                        if (handler.MoveTo(goal))
                        {
                            return("Walking to " + goal);
                        }
                        return("Failed to compute path to " + goal);
                    }
                    catch (FormatException) { return(CMDDesc); }
                }
                else
                {
                    return(CMDDesc);
                }
            }
            else
            {
                return("Please enable terrainandmovements to use this command.");
            }
        }
예제 #8
0
파일: Move.cs 프로젝트: savioacp/HtBot
        public override string Run(McTcpClient handler, string command)
        {
            if (Settings.TerrainAndMovements)
            {
                string[] args = getArgs(command);
                if (args.Length == 1)
                {
                    string    dirStr = getArg(command).Trim().ToLower();
                    Direction direction;
                    switch (dirStr)
                    {
                    case "up": direction = Direction.Up; break;

                    case "down": direction = Direction.Down; break;

                    case "east": direction = Direction.East; break;

                    case "west": direction = Direction.West; break;

                    case "north": direction = Direction.North; break;

                    case "south": direction = Direction.South; break;

                    case "get": return(handler.GetCurrentLocation().ToString());

                    default: return("Unknown direction '" + dirStr + "'.");
                    }
                    if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
                    {
                        handler.MoveTo(Movement.Move(handler.GetCurrentLocation(), direction));
                        return("Moving " + dirStr + '.');
                    }
                    else
                    {
                        return("Cannot move in that direction.");
                    }
                }
                else if (args.Length == 3)
                {
                    try
                    {
                        int      x    = int.Parse(args[0]);
                        int      y    = int.Parse(args[1]);
                        int      z    = int.Parse(args[2]);
                        Location goal = new Location(x, y, z);
                        if (handler.MoveTo(goal))
                        {
                            return("Walking to " + goal);
                        }
                        return("Failed to compute path to " + goal);
                    }
                    catch (FormatException) { return(CMDDesc); }
                }
                else
                {
                    return(CMDDesc);
                }
            }
            else
            {
                return("Please enable terrainandmovements in config to use this command.");
            }
        }