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.':
self.g.afk = False
match1 = re.match(r'<?(\w+)> (.*)', text)
match1 = re.match(r'.*<(\w+)> (.*)', text)
match2 = re.match(r'\[(\w+) -> me] (.*)', text)
if match1:
sender, text = match1.groups()

View File

@ -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:

View File

@ -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]

View File

@ -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):

View File

@ -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:

View File

@ -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