Add function for faking blocks while pathing

This commit is contained in:
Tanner Collin 2021-04-25 21:25:15 +00:00
parent e588c8fa1a
commit 7caa51f011
6 changed files with 34 additions and 29 deletions

View File

@ -36,7 +36,7 @@ class Commands:
elif text == 'You are no longer AFK.': elif text == 'You are no longer AFK.':
self.g.afk = False self.g.afk = False
match1 = re.match(r'<?(\w+)> (.*)', text) match1 = re.match(r'.*<(\w+)> (.*)', text)
match2 = re.match(r'\[(\w+) -> me] (.*)', text) match2 = re.match(r'\[(\w+) -> me] (.*)', text)
if match1: if match1:
sender, text = match1.groups() sender, text = match1.groups()

View File

@ -54,11 +54,7 @@ class CacheItemsStates:
chest = self.trapped_chests[0] chest = self.trapped_chests[0]
tmp = c.get_block_at(*chest) navpath = w.path_to_place_faked(p, chest)
c.set_block_at(*chest, blocks.AIR)
navpath = w.path_to_place(p, chest)
c.set_block_at(*chest, tmp)
print('navpath:', navpath) print('navpath:', navpath)
if navpath: if navpath:

View File

@ -81,10 +81,8 @@ class GatherSandStates:
p = utils.pint(self.g.pos) p = utils.pint(self.g.pos)
c = self.g.chunks c = self.g.chunks
tmp = c.get_block_at(*self.sand) navpath = w.path_to_place_faked(p, self.sand)
c.set_block_at(*self.sand, blocks.AIR) print('navpath:', navpath)
navpath = w.path_to_place(p, self.sand)
c.set_block_at(*self.sand, tmp)
if navpath: if navpath:
self.g.path = navpath[:-1] self.g.path = navpath[:-1]

View File

@ -61,7 +61,7 @@ class GrabSuppliesStates:
w = self.g.world w = self.g.world
p = utils.pint(self.g.pos) 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) print('Found:', self.barrels)
self.state = self.choose_barrel self.state = self.choose_barrel
@ -73,6 +73,7 @@ class GrabSuppliesStates:
if barrel in self.bad_barrels: if barrel in self.bad_barrels:
continue continue
print('Chose:', barrel)
self.barrel = barrel self.barrel = barrel
self.state = self.path_to_barrel self.state = self.path_to_barrel
return return
@ -86,26 +87,20 @@ class GrabSuppliesStates:
p = utils.pint(self.g.pos) p = utils.pint(self.g.pos)
c = self.g.chunks c = self.g.chunks
barrel = self.barrel navpath = w.path_to_place_faked(p, 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)
print('navpath:', navpath) print('navpath:', navpath)
if navpath: if navpath:
self.g.path = navpath[:-1] self.g.path = navpath[:-1]
self.opening = self.g.path[-1] self.opening = self.g.path[-1]
self.checked_barrels.append(barrel) self.checked_barrels.append(self.barrel)
self.area = barrel self.area = self.barrel
self.state = self.going_to_barrel self.state = self.going_to_barrel
self.checked_supplies = [] self.checked_supplies = []
return return
else: else:
print('No path, blacklisting barrel') print('No path, blacklisting barrel')
self.bad_barrels.append(barrel) self.bad_barrels.append(self.barrel)
self.state = self.choose_barrel self.state = self.choose_barrel
def going_to_barrel(self): def going_to_barrel(self):

View File

@ -67,11 +67,7 @@ class SleepWithBedStates:
bed = self.beds[0] bed = self.beds[0]
print('Chose:', bed) print('Chose:', bed)
tmp = c.get_block_at(*bed) navpath = w.path_to_place_faked(p, bed)
c.set_block_at(*bed, blocks.AIR)
navpath = w.path_to_place(p, bed)
c.set_block_at(*bed, tmp)
print('navpath:', navpath) print('navpath:', navpath)
if navpath: if navpath:
@ -171,12 +167,12 @@ class SleepWithBedStates:
print(threats) print(threats)
self.g.game.leave_bed() self.g.game.leave_bed()
self.state = self.cleanup self.state = self.cleanup
elif self.g.correction_count:
print('Forcefully woke up')
self.state = self.collect_bed
elif self.g.time < 100: elif self.g.time < 100:
print('Woke up time') print('Woke up time')
self.state = self.break_bed self.state = self.break_bed
elif self.g.correction_count:
print('Woke up by movement')
self.state = self.break_bed
def break_bed(self): def break_bed(self):
if self.my_bed: if self.my_bed:

View File

@ -141,6 +141,26 @@ class World:
except path.AStarTimeout: except path.AStarTimeout:
return None 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): def find_bed_areas(self, center, distance):
bed_clearance = 9 # 5x5 area bed_clearance = 9 # 5x5 area
clear_distance = 2 clear_distance = 2