From 4f83e43a6839c73998fd3b2cdb36b51d747040a8 Mon Sep 17 00:00:00 2001 From: Milutinke Date: Wed, 12 Oct 2022 13:45:12 +0200 Subject: [PATCH] Added detection when items run out. --- MinecraftClient/ChatBots/Farmer.cs | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/MinecraftClient/ChatBots/Farmer.cs b/MinecraftClient/ChatBots/Farmer.cs index 89163ec8..0892b855 100644 --- a/MinecraftClient/ChatBots/Farmer.cs +++ b/MinecraftClient/ChatBots/Farmer.cs @@ -261,10 +261,23 @@ namespace MinecraftClient.ChatBots continue; } + int i = 0; foreach (Location location in farmlandToPlantOn) { 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; // TODO: Figure out why this is not working. @@ -292,6 +305,8 @@ namespace MinecraftClient.ChatBots Thread.Sleep(300); } else LogDebug("Can't move to: " + location2); + + i++; } LogDebug("Finished planting crops!"); @@ -376,10 +391,23 @@ namespace MinecraftClient.ChatBots continue; } + int i2 = 0; foreach (Location location in cropsToBonemeal) { 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)) { // Stop if we do not have any more bonemeal left @@ -402,6 +430,8 @@ namespace MinecraftClient.ChatBots Thread.Sleep(100); } + + i2++; } LogDebug("Finished bonemealing crops!"); @@ -782,6 +812,10 @@ namespace MinecraftClient.ChatBots return false; } + private bool HasItemOfTypeInInventory(ItemType itemType) + { + return GetPlayerInventory().SearchItem(itemType).Length > 0; + } private void LogDebug(object text) { if (debugEnabled)