Esempio n. 1
0
        public bool FindBucketAndUse(McTcpClient handler, int hotbar, Location block)
        {
            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
            {
                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;
                    }
                }
                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);
                handler.UseItemOnHand();
                Thread.Sleep(100);
                handler.ChangeSlot((short)CurrentSlot);
            }
            return(found);
        }
Esempio n. 2
0
 public override string Run(McTcpClient handler, string command, Dictionary <string, object> localVars)
 {
     if (!handler.GetInventoryEnabled())
     {
         return("Please enable InventoryHandling in the config file first.");
     }
     if (hasArg(command))
     {
         short slot;
         try
         {
             slot = Convert.ToInt16(getArg(command));
         }
         catch (FormatException)
         {
             return("Could not change slot: Not a Number");
         }
         if (slot >= 1 && slot <= 9)
         {
             if (handler.ChangeSlot(slot -= 1))
             {
                 return("Changed to slot " + (slot += 1));
             }
             else
             {
                 return("Could not change slot");
             }
         }
     }
     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);
        }