Make AutoEat not to use Threading

This commit is contained in:
ReinforceZwei 2020-04-13 22:21:01 +08:00 committed by ORelio
parent 3e76baeeb1
commit 0acb17e105

View file

@ -3,8 +3,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MinecraftClient.ChatBots namespace MinecraftClient.ChatBots
{ {
@ -13,12 +11,27 @@ namespace MinecraftClient.ChatBots
byte LastSlot = 0; byte LastSlot = 0;
public static bool Eating = false; public static bool Eating = false;
private int HungerThreshold = 6; private int HungerThreshold = 6;
private int DelayCounter = 0;
public AutoEat(int Threshold) public AutoEat(int Threshold)
{ {
HungerThreshold = 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) public override void OnHealthUpdate(float health, int food)
{ {
if (((food <= HungerThreshold) || (food < 20 && health < 20)) && !Eating) if (((food <= HungerThreshold) || (food < 20 && health < 20)) && !Eating)
@ -30,13 +43,8 @@ namespace MinecraftClient.ChatBots
// keep eating until full // keep eating until full
if (food < 20 && Eating) if (food < 20 && Eating)
{ {
Task.Factory.StartNew(delegate // delay 300ms
{ DelayCounter = 3;
Thread.Sleep(200);
Eating = FindFoodAndEat();
if (!Eating)
ChangeSlot(LastSlot);
});
} }
if (food >= 20 && Eating) if (food >= 20 && Eating)
{ {