minecraft-bot/mosfet/jobs/eat_food.py

73 lines
1.6 KiB
Python
Raw Normal View History

2021-04-19 01:34:54 +00:00
import re
import time
import importlib
import random
from itertools import count
from math import floor
2021-04-19 01:34:54 +00:00
from minecraft.networking.types import BlockFace
2021-04-22 00:46:54 +00:00
from mosfet.protocol.managers import ChunkNotLoadedException
2021-04-19 01:34:54 +00:00
2021-04-22 00:46:54 +00:00
from mosfet import utils
from mosfet import path
from mosfet.info import blocks
from mosfet.info import items
from mosfet.info import mcdata
from mosfet.info import mobs
2021-04-19 01:34:54 +00:00
class EatFoodStates:
def idle(self):
return None
def init(self):
if self.g.food < 12:
print('Hungry, eating')
self.state = self.select_food
return
if self.g.health < 20 and self.g.food < 18:
print('Low health, eating')
self.state = self.select_food
return
print('Don\'t need to eat, aborting')
self.state = self.cleanup
def select_food(self):
if self.g.game.select_item(items.FOOD_IDS):
self.state = self.eat_food
else:
print('No food, aborting')
self.state = self.cleanup
def eat_food(self):
self.g.game.use_item(0)
print('Eating food')
self.wait_time = 3
self.state = self.wait
def wait(self):
if self.wait_time > 0:
self.wait_time -= utils.TICK
else:
self.state = self.cleanup
def cleanup(self):
self.state = self.done
def done(self):
# never gets ran, placeholder
return None
def __init__(self, global_state):
self.g = global_state
self.state = self.idle
self.wait_time = 0
def run(self):
self.state()