mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add a proof of concept working demo
This commit is contained in:
parent
f8111d6b3b
commit
a51368a859
3 changed files with 84 additions and 0 deletions
81
MinecraftClient/ChatBots/AutoCarft.cs
Normal file
81
MinecraftClient/ChatBots/AutoCarft.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MinecraftClient.Inventory;
|
||||
|
||||
namespace MinecraftClient.ChatBots
|
||||
{
|
||||
class AutoCarft : ChatBot
|
||||
{
|
||||
private bool waitingForResult = false;
|
||||
private int inventoryInUse;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
RegisterChatBotCommand("craft", "craft", CraftCommand);
|
||||
}
|
||||
|
||||
public string CraftCommand(string command, string[] args)
|
||||
{
|
||||
Dictionary<int, ItemType> recipe = new Dictionary<int, ItemType>
|
||||
{
|
||||
{ 1, ItemType.Stone }
|
||||
};
|
||||
var inventory = GetInventories()[0];
|
||||
int slotToPut = -2;
|
||||
int slotToTake = -2;
|
||||
inventoryInUse = 0;
|
||||
foreach (KeyValuePair<int, ItemType> slot in recipe)
|
||||
{
|
||||
slotToPut = slot.Key + 1;
|
||||
// Find material in our inventory
|
||||
foreach (KeyValuePair<int, Item> item in inventory.Items)
|
||||
{
|
||||
if (slot.Value == item.Value.Type)
|
||||
{
|
||||
slotToTake = item.Key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (slotToTake != -2)
|
||||
{
|
||||
// move found material to correct crafting slot
|
||||
WindowAction(0, slotToTake, WindowActionType.LeftClick);
|
||||
WindowAction(0, slotToPut, WindowActionType.LeftClick);
|
||||
}
|
||||
}
|
||||
if (slotToPut != -2 && slotToTake != -2)
|
||||
{
|
||||
waitingForResult = true;
|
||||
// Now wait for server to update the slot 0, craft result
|
||||
return "Waiting for result";
|
||||
}
|
||||
else return "Failed before waiting for result";
|
||||
}
|
||||
|
||||
public override void OnInventoryUpdate(int inventoryId)
|
||||
{
|
||||
ConsoleIO.WriteLine("Inventory " + inventoryId + " is being updated");
|
||||
if (waitingForResult && inventoryInUse == inventoryId)
|
||||
{
|
||||
var inventory = GetInventories()[inventoryId];
|
||||
if (inventory.Items.ContainsKey(0))
|
||||
{
|
||||
// slot 0 have item, click on it
|
||||
WindowAction(0, 0, WindowActionType.LeftClick);
|
||||
// Now wait for server to update our inventory
|
||||
ConsoleIO.WriteLine("Crafting success");
|
||||
}
|
||||
else if (inventory.Items.ContainsKey(-1))
|
||||
{
|
||||
// Server have updated our cursor to the item we want to take out from craft result
|
||||
// Now put the item back to our inventory
|
||||
WindowAction(0, 37, WindowActionType.LeftClick);
|
||||
ConsoleIO.WriteLine("Moved crafted item to inventory");
|
||||
waitingForResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -176,6 +176,8 @@ namespace MinecraftClient
|
|||
if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); }
|
||||
if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); }
|
||||
|
||||
BotLoad(new AutoCarft());
|
||||
|
||||
//Add your ChatBot here by uncommenting and adapting
|
||||
//BotLoad(new ChatBots.YourBot());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@
|
|||
<Compile Include="ChatBots\Alerts.cs" />
|
||||
<Compile Include="ChatBots\AntiAFK.cs" />
|
||||
<Compile Include="ChatBots\AutoAttack.cs" />
|
||||
<Compile Include="ChatBots\AutoCarft.cs" />
|
||||
<Compile Include="ChatBots\AutoEat.cs" />
|
||||
<Compile Include="ChatBots\AutoFishing.cs" />
|
||||
<Compile Include="ChatBots\AutoRespond.cs" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue