From 7caa51f011fad4cb19140c8a26bb3f3fe069d811 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 25 Apr 2021 21:25:15 +0000 Subject: [PATCH] Add function for faking blocks while pathing --- mosfet/commands.py | 2 +- mosfet/jobs/cache_items.py | 6 +----- mosfet/jobs/gather_sand.py | 6 ++---- mosfet/jobs/grab_supplies.py | 17 ++++++----------- mosfet/jobs/sleep_with_bed.py | 12 ++++-------- mosfet/world.py | 20 ++++++++++++++++++++ 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/mosfet/commands.py b/mosfet/commands.py index c65e6fe..72e8a23 100644 --- a/mosfet/commands.py +++ b/mosfet/commands.py @@ -36,7 +36,7 @@ class Commands: elif text == 'You are no longer AFK.': self.g.afk = False - match1 = re.match(r' (.*)', text) + match1 = re.match(r'.*<(\w+)> (.*)', text) match2 = re.match(r'\[(\w+) -> me] (.*)', text) if match1: sender, text = match1.groups() diff --git a/mosfet/jobs/cache_items.py b/mosfet/jobs/cache_items.py index 18a29c3..b613197 100644 --- a/mosfet/jobs/cache_items.py +++ b/mosfet/jobs/cache_items.py @@ -54,11 +54,7 @@ class CacheItemsStates: chest = self.trapped_chests[0] - tmp = c.get_block_at(*chest) - c.set_block_at(*chest, blocks.AIR) - navpath = w.path_to_place(p, chest) - c.set_block_at(*chest, tmp) - + navpath = w.path_to_place_faked(p, chest) print('navpath:', navpath) if navpath: diff --git a/mosfet/jobs/gather_sand.py b/mosfet/jobs/gather_sand.py index 7059822..38830ba 100644 --- a/mosfet/jobs/gather_sand.py +++ b/mosfet/jobs/gather_sand.py @@ -81,10 +81,8 @@ class GatherSandStates: p = utils.pint(self.g.pos) c = self.g.chunks - tmp = c.get_block_at(*self.sand) - c.set_block_at(*self.sand, blocks.AIR) - navpath = w.path_to_place(p, self.sand) - c.set_block_at(*self.sand, tmp) + navpath = w.path_to_place_faked(p, self.sand) + print('navpath:', navpath) if navpath: self.g.path = navpath[:-1] diff --git a/mosfet/jobs/grab_supplies.py b/mosfet/jobs/grab_supplies.py index b3bec35..d168cc0 100644 --- a/mosfet/jobs/grab_supplies.py +++ b/mosfet/jobs/grab_supplies.py @@ -61,7 +61,7 @@ class GrabSuppliesStates: w = self.g.world p = utils.pint(self.g.pos) - self.barrels = w.find_blocks_indexed(p, blocks.BARREL_IDS) + self.barrels = w.find_blocks_indexed(p, blocks.BARREL_IDS, 80) print('Found:', self.barrels) self.state = self.choose_barrel @@ -73,6 +73,7 @@ class GrabSuppliesStates: if barrel in self.bad_barrels: continue + print('Chose:', barrel) self.barrel = barrel self.state = self.path_to_barrel return @@ -86,26 +87,20 @@ class GrabSuppliesStates: p = utils.pint(self.g.pos) c = self.g.chunks - barrel = self.barrel - - tmp = c.get_block_at(*barrel) - c.set_block_at(*barrel, blocks.AIR) - navpath = w.path_to_place(p, barrel) - c.set_block_at(*barrel, tmp) - + navpath = w.path_to_place_faked(p, self.barrel) print('navpath:', navpath) if navpath: self.g.path = navpath[:-1] self.opening = self.g.path[-1] - self.checked_barrels.append(barrel) - self.area = barrel + self.checked_barrels.append(self.barrel) + self.area = self.barrel self.state = self.going_to_barrel self.checked_supplies = [] return else: print('No path, blacklisting barrel') - self.bad_barrels.append(barrel) + self.bad_barrels.append(self.barrel) self.state = self.choose_barrel def going_to_barrel(self): diff --git a/mosfet/jobs/sleep_with_bed.py b/mosfet/jobs/sleep_with_bed.py index 9b2ebbe..4116702 100644 --- a/mosfet/jobs/sleep_with_bed.py +++ b/mosfet/jobs/sleep_with_bed.py @@ -67,11 +67,7 @@ class SleepWithBedStates: bed = self.beds[0] print('Chose:', bed) - 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) - + navpath = w.path_to_place_faked(p, bed) print('navpath:', navpath) if navpath: @@ -171,12 +167,12 @@ class SleepWithBedStates: print(threats) self.g.game.leave_bed() self.state = self.cleanup - elif self.g.correction_count: - print('Forcefully woke up') - self.state = self.collect_bed elif self.g.time < 100: print('Woke up time') self.state = self.break_bed + elif self.g.correction_count: + print('Woke up by movement') + self.state = self.break_bed def break_bed(self): if self.my_bed: diff --git a/mosfet/world.py b/mosfet/world.py index 550fe51..cda9646 100644 --- a/mosfet/world.py +++ b/mosfet/world.py @@ -141,6 +141,26 @@ class World: except path.AStarTimeout: return None + def path_to_place_faked(self, start, place): + # same as above, but adds a fake block below and air before pathfinding + # so that the pathfinder can actually make it to the block + c = self.g.chunks + above = utils.padd(place, path.BLOCK_ABOVE) + below = utils.padd(place, path.BLOCK_BELOW) + + tmp = c.get_block_at(*place) + tmp2 = c.get_block_at(*above) + tmp3 = c.get_block_at(*below) + c.set_block_at(*place, blocks.AIR) + c.set_block_at(*above, blocks.AIR) + c.set_block_at(*below, blocks.STONE) + navpath = self.path_to_place(start, place) + c.set_block_at(*place, tmp) + c.set_block_at(*above, tmp2) + c.set_block_at(*below, tmp3) + + return navpath + def find_bed_areas(self, center, distance): bed_clearance = 9 # 5x5 area clear_distance = 2