From ef68956e63fffc3e396947d0102363ed148a2534 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 23 Mar 2021 21:40:36 +0000 Subject: [PATCH] Try using already placed beds first --- blocks.py | 38 +++++++++++++++++++++++++++++++------ jobs.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/blocks.py b/blocks.py index b413a92..9d788ff 100644 --- a/blocks.py +++ b/blocks.py @@ -237,12 +237,31 @@ SAPLINGS = [ 'dark_oak_sapling', ] +BEDS = [ + 'white_bed', + 'orange_bed', + 'magenta_bed', + 'light_blue_bed', + 'yellow_bed', + 'lime_bed', + 'pink_bed', + 'gray_bed', + 'light_gray_bed', + 'cyan_bed', + 'purple_bed', + 'blue_bed', + 'brown_bed', + 'green_bed', + 'red_bed', + 'black_bed', +] + INDEXED = [ 'chest', 'trapped_chest', 'emerald_block', 'barrel', -] +] + BEDS NON_SOLID_IDS = set([SINGLE_SNOW]) @@ -310,16 +329,23 @@ for block_name in ['beetroots']: for state in JSON_BLOCKS['minecraft:' + block_name]['states']: BEETROOT_IDS.add(state['id']) -INDEXED_IDS = set() -for block_name in INDEXED: - for state in JSON_BLOCKS['minecraft:' + block_name]['states']: - INDEXED_IDS.add(state['id']) - SAPLING_IDS = set() for block_name in SAPLINGS: for state in JSON_BLOCKS['minecraft:' + block_name]['states']: SAPLING_IDS.add(state['id']) +BED_IDS = set() +for block_name in BEDS: + for state in JSON_BLOCKS['minecraft:' + block_name]['states']: + BED_IDS.add(state['id']) + + + +INDEXED_IDS = set() +for block_name in INDEXED: + for state in JSON_BLOCKS['minecraft:' + block_name]['states']: + INDEXED_IDS.add(state['id']) + MATURE_WHEAT_ID = max(WHEAT_IDS) MATURE_POTATO_ID = max(POTATO_IDS) MATURE_CARROT_ID = max(CARROT_IDS) diff --git a/jobs.py b/jobs.py index 6f7bfb4..848c9d3 100644 --- a/jobs.py +++ b/jobs.py @@ -732,7 +732,51 @@ class SleepWithBedStates: self.state = self.cleanup return - self.state = self.select_bed + self.state = self.find_beds + + def find_beds(self): + print('Finding beds...') + w = self.g.world + p = utils.pint(self.g.pos) + + self.beds = w.find_blocks_indexed(p, blocks.BED_IDS) + print('Found:', self.beds) + self.state = self.choose_bed + + def choose_bed(self): + print('Choosing a bed...') + w = self.g.world + p = utils.pint(self.g.pos) + c = self.g.chunks + + if not len(self.beds): + print('No beds') + self.state = self.select_bed + return + + bed = self.beds[0] + + tmp = c.get_block_at(*bed) + c.set_block_at(*bed, blocks.AIR) + navpath = w.path_to_place(p, bed) + c.set_block_at(*bed, tmp) + + print('navpath:', navpath) + + if navpath: + self.g.path = navpath[:-1] + self.opening = self.g.path[-1] + self.area = bed + self.state = self.going_to_bed + return + else: + self.beds.pop(0) + + def going_to_bed(self): + if utils.pint(self.g.pos) == self.opening: + self.my_bed = False + self.g.look_at = self.area + self.state = self.use_bed def select_bed(self): if self.g.game.select_item(items.BED_IDS): @@ -778,6 +822,7 @@ class SleepWithBedStates: def place_bed(self): self.g.game.place_block(self.area, BlockFace.TOP) + self.my_bed = True self.state = self.use_bed def use_bed(self): @@ -803,8 +848,12 @@ class SleepWithBedStates: self.state = self.break_bed def break_bed(self): - self.g.game.break_block(self.area) - self.state = self.collect_bed + if self.my_bed: + self.g.game.break_block(self.area) + self.state = self.collect_bed + else: + self.state = self.cleanup + def collect_bed(self): if not self.g.breaking: @@ -833,6 +882,8 @@ class SleepWithBedStates: self.silent = False + self.my_bed = False + self.beds = [] self.area = None self.opening = None self.bad_areas = []