Fix AutoCraft bugs

Fix recipe parse error
Fix crashes on crafting failure
This commit is contained in:
ReinforceZwei 2020-08-11 15:34:07 +08:00 committed by ORelio
parent d33677a245
commit aeac56890b

View file

@ -28,6 +28,7 @@ namespace MinecraftClient.ChatBots
private string timeoutAction = "unspecified"; private string timeoutAction = "unspecified";
private string configPath = @"autocraft\config.ini"; private string configPath = @"autocraft\config.ini";
private string lastRecipe = ""; // Used in parsing recipe config
private Dictionary<string, Recipe> recipes = new Dictionary<string, Recipe>(); private Dictionary<string, Recipe> recipes = new Dictionary<string, Recipe>();
@ -332,7 +333,7 @@ namespace MinecraftClient.ChatBots
string value = line.Substring(key.Length + 1); string value = line.Substring(key.Length + 1);
switch (section) switch (section)
{ {
case "recipe": parseRecipe(key, value, lastRecipe); break; case "recipe": parseRecipe(key, value); break;
case "autocraft": parseMain(key, value); break; case "autocraft": parseMain(key, value); break;
} }
} }
@ -383,7 +384,7 @@ namespace MinecraftClient.ChatBots
} }
} }
private void parseRecipe(string key, string value, string lastRecipe) private void parseRecipe(string key, string value)
{ {
if (key.StartsWith("slot")) if (key.StartsWith("slot"))
{ {
@ -408,10 +409,21 @@ namespace MinecraftClient.ChatBots
} }
return; return;
} }
else
{
throw new Exception("Invalid item name in recipe " + lastRecipe + " at " + key);
} }
} }
else
{
throw new Exception("Missing recipe name while parsing a recipe");
}
}
else
{
throw new Exception("Invalid slot field in recipe: " + key); throw new Exception("Invalid slot field in recipe: " + key);
} }
}
else else
{ {
switch (key) switch (key)
@ -664,6 +676,11 @@ namespace MinecraftClient.ChatBots
{ {
if (craftingFailed) if (craftingFailed)
{ {
if (actionSteps[index - 1].ActionType == ActionType.LeftClick && actionSteps[index - 1].ItemType != ItemType.Air)
{
// Inform user the missing meterial name
ConsoleIO.WriteLogLine("Missing material: " + actionSteps[index - 1].ItemType.ToString());
}
if (abortOnFailure) if (abortOnFailure)
{ {
StopCrafting(); StopCrafting();
@ -677,11 +694,6 @@ namespace MinecraftClient.ChatBots
index--; index--;
ConsoleIO.WriteLogLine("Crafting failed! Waiting for more materials"); ConsoleIO.WriteLogLine("Crafting failed! Waiting for more materials");
} }
if (actionSteps[index - 1].ActionType == ActionType.LeftClick && actionSteps[index - 1].ItemType != ItemType.Air)
{
// Inform user the missing meterial name
ConsoleIO.WriteLogLine("Missing material: " + actionSteps[index - 1].ItemType.ToString());
}
} }
} }