From 0acb17e105a175f7a613f9365bb7b78e2bbbbc38 Mon Sep 17 00:00:00 2001 From: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com> Date: Mon, 13 Apr 2020 22:21:01 +0800 Subject: [PATCH] Make AutoEat not to use Threading --- MinecraftClient/ChatBots/AutoEat.cs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/MinecraftClient/ChatBots/AutoEat.cs b/MinecraftClient/ChatBots/AutoEat.cs index 0da8e024..7597ab90 100644 --- a/MinecraftClient/ChatBots/AutoEat.cs +++ b/MinecraftClient/ChatBots/AutoEat.cs @@ -3,8 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading; -using System.Threading.Tasks; namespace MinecraftClient.ChatBots { @@ -13,12 +11,27 @@ namespace MinecraftClient.ChatBots byte LastSlot = 0; public static bool Eating = false; private int HungerThreshold = 6; + private int DelayCounter = 0; public AutoEat(int Threshold) { HungerThreshold = Threshold; } + public override void Update() + { + if (DelayCounter > 0) + { + DelayCounter--; + if (DelayCounter == 0) + { + Eating = FindFoodAndEat(); + if (!Eating) + ChangeSlot(LastSlot); + } + } + } + public override void OnHealthUpdate(float health, int food) { if (((food <= HungerThreshold) || (food < 20 && health < 20)) && !Eating) @@ -30,13 +43,8 @@ namespace MinecraftClient.ChatBots // keep eating until full if (food < 20 && Eating) { - Task.Factory.StartNew(delegate - { - Thread.Sleep(200); - Eating = FindFoodAndEat(); - if (!Eating) - ChangeSlot(LastSlot); - }); + // delay 300ms + DelayCounter = 3; } if (food >= 20 && Eating) {