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.info import blocks from mosfet.info import items from mosfet.info import mcdata from mosfet.info import mobs class ClearLeavesStates: def idle(self): return None def init(self): if not self.g.chopped_tree: print('Didnt chop tree, clearing leaves') self.state = self.cleanup return sapling_type = self.g.chopped_tree + '_sapling' sapling_item = items.get_id(sapling_type) num_saplings = self.g.game.count_items([sapling_item]) print('Have', num_saplings, sapling_type, 'in inventory') if num_saplings > 8: print('Have enough saplings, aborting clearing leaves') self.state = self.cleanup return self.state = self.select_log print('Clearing leaves...') def select_log(self): # select a log to avoid using tools self.g.game.select_item(items.LOG_IDS) self.state = self.find_leaves def find_leaves(self): w = self.g.world p = utils.pint(self.g.pos) pos = utils.padd(p, path.BLOCK_ABOVE) for l in w.find_leaves(pos, blocks.BREAK_DISTANCE): self.leaves.append(l) self.state = self.break_leaves def break_leaves(self): if not self.g.breaking: if self.leaves: leaf = self.leaves.pop(0) self.g.look_at = leaf self.g.game.break_block(leaf) print('Breaking leaf', leaf) else: self.wait_time = 1 self.state = self.wait def wait(self): # wait for the items to drop 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.leaves = [] self.wait_time = 0 def run(self): self.state()