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); }
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); }
public override string Run(McTcpClient handler, string command, Dictionary <string, object> localVars) { if (handler.GetInventoryEnabled()) { string[] args = getArgs(command); if (args.Length >= 1) { try { int inventoryId; if (args[0].ToLower() == "player") { // player inventory is always ID 0 inventoryId = 0; } else if (args[0].ToLower() == "container") { List <int> availableIds = handler.GetInventories().Keys.ToList(); availableIds.Remove(0); // remove player inventory ID from list if (availableIds.Count == 1) { inventoryId = availableIds[0]; // one container, use it } else { return("Cannot find container, please retry with explicit ID"); } } else { inventoryId = int.Parse(args[0]); } string action = args.Length > 1 ? args[1].ToLower() : "list"; switch (action) { case "close": if (handler.CloseInventory(inventoryId)) { return("Closing Inventoy #" + inventoryId); } else { return("Failed to close Inventory #" + inventoryId); } case "list": Container inventory = handler.GetInventory(inventoryId); if (inventory == null) { return("Inventory #" + inventoryId + " do not exist"); } List <string> response = new List <string>(); response.Add("Inventory #" + inventoryId + " - " + inventory.Title + "§8"); foreach (KeyValuePair <int, Item> item in inventory.Items) { string displayName = item.Value.DisplayName; if (String.IsNullOrEmpty(displayName)) { response.Add(String.Format(" #{0}: {1} x{2}", item.Key, item.Value.Type, item.Value.Count)); } else { response.Add(String.Format(" #{0}: {1} x{2} - {3}§8", item.Key, item.Value.Type, item.Value.Count, displayName)); } } if (inventoryId == 0) { response.Add("Your selected hotbar is " + (handler.GetCurrentSlot() + 1)); } return(String.Join("\n", response.ToArray())); case "click": if (args.Length == 3) { int slot = int.Parse(args[2]); handler.ClickWindowSlot(inventoryId, slot); return("Clicking slot " + slot + " in window #" + inventoryId); } else { return(CMDDesc); } default: return(CMDDesc); } } catch (FormatException) { return(CMDDesc); } } else { Dictionary <int, Container> inventories = handler.GetInventories(); List <string> response = new List <string>(); response.Add("Inventories:"); foreach (var inventory in inventories) { response.Add(String.Format(" #{0}: {1}", inventory.Key, inventory.Value.Title + "§8")); } response.Add(CMDDesc); return(String.Join("\n", response)); } } else { return("Please enable inventoryhandling in config to use this command."); } }
public override string Run(McTcpClient handler, string command, Dictionary <string, object> localVars) { if (handler.GetInventoryEnabled()) { string[] args = getArgs(command); if (args.Length >= 1) { try { int inventoryId = int.Parse(args[0]); string action = args.Length > 1 ? args[1].ToLower() : "list"; switch (action) { case "close": if (handler.CloseInventory(inventoryId)) { return("Closing Inventoy #" + inventoryId); } else { return("Failed to close Inventory #" + inventoryId); } case "list": Container inventory = handler.GetInventory(inventoryId); if (inventory == null) { return("Inventory #" + inventoryId + " do not exist"); } List <string> response = new List <string>(); response.Add("Inventory #" + inventoryId + " - " + inventory.Title + "§8"); foreach (KeyValuePair <int, Item> item in inventory.Items) { string displayName = item.Value.DisplayName; if (String.IsNullOrEmpty(displayName)) { response.Add(String.Format(" #{0}: {1} x{2}", item.Key, item.Value.Type, item.Value.Count)); } else { response.Add(String.Format(" #{0}: {1} x{2} - {3}§8", item.Key, item.Value.Type, item.Value.Count, displayName)); } } if (inventoryId == 0) { response.Add("Your selected hotbar is " + (handler.GetCurrentSlot() + 1)); } return(String.Join("\n", response.ToArray())); case "click": if (args.Length == 3) { int slot = int.Parse(args[2]); handler.ClickWindowSlot(inventoryId, slot, 0, 0); return("Clicking slot " + slot + " in window #" + inventoryId); } else if (args.Length == 5) { int slot = int.Parse(args[2]); int button = int.Parse(args[3]); int mode = int.Parse(args[4]); handler.ClickWindowSlot(inventoryId, slot, button, mode); return("Clicking slot " + slot + " in window #" + inventoryId + " use button " + button + " at mode " + mode); } else { return(CMDDesc); } default: return(CMDDesc); } } catch (FormatException) { return(CMDDesc); } } else { Dictionary <int, Container> inventories = handler.GetInventories(); List <string> response = new List <string>(); response.Add("Inventories:"); foreach (var inventory in inventories) { response.Add(String.Format(" #{0}: {1}", inventory.Key, inventory.Value.Title + "§8")); } response.Add(CMDDesc); return(String.Join("\n", response)); } } else { return("Please enable inventoryhandling in config to use this command."); } }