Added detection when items run out.

This commit is contained in:
Milutinke 2022-10-12 13:45:12 +02:00
parent 6524fe1734
commit 4f83e43a68

View file

@ -261,10 +261,23 @@ namespace MinecraftClient.ChatBots
continue; continue;
} }
int i = 0;
foreach (Location location in farmlandToPlantOn) foreach (Location location in farmlandToPlantOn)
{ {
if (!running) break; if (!running) break;
// Check only every second iteration, minor optimization xD
if (i % 2 == 0)
{
if (!HasItemOfTypeInInventory(cropTypeToPlant))
{
LogDebug("Ran out of seeds, looking for crops to break...");
state = State.SearchingForCropsToBreak;
Thread.Sleep(Config.Delay_Between_Tasks * 1000);
continue;
}
}
double yValue = Math.Floor(location.Y) + 1; double yValue = Math.Floor(location.Y) + 1;
// TODO: Figure out why this is not working. // TODO: Figure out why this is not working.
@ -292,6 +305,8 @@ namespace MinecraftClient.ChatBots
Thread.Sleep(300); Thread.Sleep(300);
} }
else LogDebug("Can't move to: " + location2); else LogDebug("Can't move to: " + location2);
i++;
} }
LogDebug("Finished planting crops!"); LogDebug("Finished planting crops!");
@ -376,10 +391,23 @@ namespace MinecraftClient.ChatBots
continue; continue;
} }
int i2 = 0;
foreach (Location location in cropsToBonemeal) foreach (Location location in cropsToBonemeal)
{ {
if (!running) break; if (!running) break;
// Check only every second iteration, minor optimization xD
if (i2 % 2 == 0)
{
if (!HasItemOfTypeInInventory(ItemType.BoneMeal))
{
LogDebug("Ran out of Bone Meal, looking for farmland to plant on...");
state = State.SearchingForFarmlandToPlant;
Thread.Sleep(Config.Delay_Between_Tasks * 1000);
continue;
}
}
if (WaitForMoveToLocation(location)) if (WaitForMoveToLocation(location))
{ {
// Stop if we do not have any more bonemeal left // Stop if we do not have any more bonemeal left
@ -402,6 +430,8 @@ namespace MinecraftClient.ChatBots
Thread.Sleep(100); Thread.Sleep(100);
} }
i2++;
} }
LogDebug("Finished bonemealing crops!"); LogDebug("Finished bonemealing crops!");
@ -782,6 +812,10 @@ namespace MinecraftClient.ChatBots
return false; return false;
} }
private bool HasItemOfTypeInInventory(ItemType itemType)
{
return GetPlayerInventory().SearchItem(itemType).Length > 0;
}
private void LogDebug(object text) private void LogDebug(object text)
{ {
if (debugEnabled) if (debugEnabled)