import re import time import importlib import random from itertools import count from math import hypot, floor from minecraft.networking.types import BlockFace from mosfet.protocol.managers import ChunkNotLoadedException from mosfet import utils from mosfet import path from mosfet import blocks from mosfet import items from mosfet import mcdata from mosfet import mobs class GatherWartStates: def idle(self): return None def init(self): self.state = self.find_new_wart def find_new_wart(self): print('Finding new wart...') w = self.g.world p = utils.pint(self.g.pos) mature_wart = max(blocks.NETHERWART_IDS) for wart in w.find_blocks_3d(p, [mature_wart], 50, 20, True): if wart not in self.bad_warts: break else: # for print('No good warts left, aborting.') self.state = self.cleanup return print('Found wart:', wart) self.wart = wart self.state = self.nav_to_wart def nav_to_wart(self): w = self.g.world p = utils.pint(self.g.pos) navpath = w.path_to_place(p, self.wart) if navpath: print('Going to wart', self.crop) self.g.path = navpath self.g.look_at = utils.padd(self.wart, path.BLOCK_BELOW) self.state = self.going_to_wart else: print('Cant get to it, blacklisting') self.bad_warts.append(wart) self.wait_time = 0.5 self.state = self.wait_to_restart def wait_to_restart(self): # prevent timeouts if self.wait_time > 0: self.wait_time -= utils.TICK else: self.state = self.find_new_wart def going_to_wart(self): if utils.pint(self.g.pos) == self.wart: print('At the wart') self.state = self.break_wart def break_wart(self): self.g.game.break_block(self.wart) self.wait_time = 0.5 self.state = self.wait def wait(self): # wait for the item if self.wait_time > 0: self.wait_time -= utils.TICK else: self.state = self.select_wart def select_wart(self): p = utils.pint(self.g.pos) if self.g.game.select_item([items.NETHERWART_ID]): self.state = self.wait_select self.wait_time = 0.5 else: print('Aborting planting, no wart') self.state = self.cleanup def wait_select(self): # wait a bit to select if self.wait_time > 0: self.wait_time -= utils.TICK else: self.state = self.place_wart def place_wart(self): p = utils.pint(self.g.pos) self.g.game.place_block(p, BlockFace.TOP) print('Placed wart') self.state = self.wait_place self.wait_time = 0.5 def wait_place(self): # wait a bit for chunk data to update if self.wait_time > 0: self.wait_time -= utils.TICK else: self.state = self.cleanup def cleanup(self): self.g.look_at = None 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.wart = None self.bad_warts = [] self.wait_time = 0 def run(self): self.state()