diff --git a/game.py b/game.py index 7a93f1b..90cdad4 100644 --- a/game.py +++ b/game.py @@ -37,6 +37,8 @@ import mcdata importlib.reload(mcdata) import mobs importlib.reload(mobs) +import bot +importlib.reload(bot) class MCWorld: def __init__(self, global_state): @@ -651,9 +653,7 @@ class Game: reply += ', I need a bed' if command == 'stop': - self.g.job.stop() - self.g.path = [] - self.g.look_at = None + bot.init(self.g) reply = 'ok' if command == 'drop': @@ -739,6 +739,9 @@ class Game: print(len(navpath)) print(navpath) print(round(time.time() - start, 3), 'seconds') + if self.g.job: + self.g.job.stop() + self.g.look_at = None reply = 'ok' else: reply = 'no path' diff --git a/items.py b/items.py index f0b18ef..d0e4a42 100644 --- a/items.py +++ b/items.py @@ -56,13 +56,13 @@ ITEM_NAMES = {} for item_name, item in ITEMS.items(): ITEM_NAMES[ITEMS[item_name]['protocol_id']] = item_name.replace('minecraft:', '') -CHEST_ID = set([ITEMS['minecraft:chest']['protocol_id']]) +def get_id(name): + return ITEMS['minecraft:' + name]['protocol_id'] -GAPPLE_ID = set([ITEMS['minecraft:enchanted_golden_apple']['protocol_id']]) +CHEST_ID = get_id('chest') +GAPPLE_ID = get_id('enchanted_golden_apple') +SAND_ID = get_id('sand') +NETHERWART_ID = get_id('nether_wart') -SAND_ID = set([ITEMS['minecraft:sand']['protocol_id']]) - -NETHERWART_ID = set([ITEMS['minecraft:nether_wart']['protocol_id']]) - -NEEDED_ITEMS = BED_IDS | CHEST_ID -WANTED_ITEMS = SAPLING_IDS | NETHERWART_ID +NEEDED_ITEMS = BED_IDS | set([CHEST_ID]) +WANTED_ITEMS = SAPLING_IDS | set([NETHERWART_ID]) diff --git a/jobs.py b/jobs.py index 46ac76e..aff68e9 100644 --- a/jobs.py +++ b/jobs.py @@ -259,6 +259,9 @@ class GatherWoodStates: return self.tree = tree + self.type = blocks.BLOCKS[w.block_at(*tree)].replace('_log', '') + print('Type:', self.type) + self.state = self.find_openings def find_openings(self): @@ -360,7 +363,7 @@ class GatherWoodStates: if self.wait_time > 0: self.wait_time -= utils.TICK else: - self.g.chopped_tree = True + self.g.chopped_tree = self.type self.good_trees.append(self.tree) self.state = self.check_pos @@ -386,6 +389,7 @@ class GatherWoodStates: self.state = self.idle self.tree = None + self.type = None self.openings = [] self.bad_trees = [] self.good_trees = [] @@ -766,7 +770,7 @@ class CacheItemsStates: def select_chest(self): - if self.g.game.select_item(items.CHEST_ID): + if self.g.game.select_item([items.CHEST_ID]): self.state = self.find_cache_spot else: print('No chest, aborting') @@ -931,13 +935,15 @@ class PlantTreeStates: def select_sapling(self): p = utils.pint(self.g.pos) + sapling_type = self.g.chopped_tree + '_sapling' + sapling_item = items.get_id(sapling_type) - if self.g.game.select_random_item(items.SAPLING_IDS): + if self.g.game.select_item([sapling_item]): self.g.look_at = utils.padd(p, path.BLOCK_BELOW) self.state = self.wait_select self.wait_time = 1 else: - print('Aborting planting, no saplings') + print('Aborting planting, no', sapling_type) self.state = self.cleanup def wait_select(self): @@ -1005,14 +1011,19 @@ class ClearLeavesStates: return None def init(self): - num_saplings = self.g.game.count_items(items.SAPLING_IDS) - print('Have', num_saplings, 'saplings in inventory') - if num_saplings < 8: - self.state = self.find_leaves - print('Clearing leaves...') - else: - print('Aborting clearing leaves') - self.state = self.cleanup + if self.g.chopped_tree: + 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('Aborting clearing leaves') + self.state = self.cleanup + return + + self.state = self.find_leaves + print('Clearing leaves...') def find_leaves(self): w = self.g.world