import re import time import importlib import random from itertools import count from math import hypot, floor from minecraft.networking.types import BlockFace from protocol.managers import ChunkNotLoadedException import utils import path import blocks import items import mcdata import mobs 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()