Improve AutoEat

This commit is contained in:
ReinforceZwei 2020-04-11 13:28:17 +08:00 committed by ORelio
parent 959b62f35f
commit e9d91ce572
2 changed files with 14 additions and 14 deletions

View file

@ -9,7 +9,6 @@ namespace MinecraftClient.ChatBots
class AutoEat : ChatBot
{
byte LastSlot = 0;
byte CurrentSlot;
public static bool Eating = false;
private int HungerThreshold = 6;
@ -20,15 +19,11 @@ namespace MinecraftClient.ChatBots
public override void OnHealthUpdate(float health, int food)
{
if (food <= HungerThreshold || (food < 20 && health < 20))
if ((food <= HungerThreshold) || (food < 20 && health < 20) || (food < 20 && Eating))
{
Eating = true;
FindFoodAndEat();
}
// keep eating until full
if (food < 20 && Eating)
{
FindFoodAndEat();
Eating = FindFoodAndEat();
if (!Eating)
ChangeSlot(LastSlot);
}
if (food >= 20 && Eating)
{
@ -37,10 +32,6 @@ namespace MinecraftClient.ChatBots
}
}
public override void OnHeldItemChange(byte slot)
{
CurrentSlot = slot;
}
/// <summary>
/// Try to find food in the hotbar and eat it
/// </summary>
@ -49,7 +40,11 @@ namespace MinecraftClient.ChatBots
{
Container inventory = GetPlayerInventory();
bool found = false;
LastSlot = CurrentSlot;
byte CurrentSlot = GetCurrentSlot();
if (!Eating)
{
LastSlot = CurrentSlot;
}
if (inventory.Items.ContainsKey(CurrentSlot + 36) && inventory.Items[CurrentSlot + 36].Type.IsFood())
{
// no need to change slot