Move beside planted sapling

This commit is contained in:
Tanner Collin 2020-10-23 17:45:35 -06:00
parent ee2a1958f9
commit bd8f8a0d55

73
jobs.py
View File

@ -433,7 +433,7 @@ class SleepWithBedStates:
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
self.state = self.place_bed
else:
self.g.chat.send('I need a bed')
print('No bed, aborting.')
self.state = self.cleanup
def place_bed(self):
@ -549,7 +549,7 @@ class CacheItemsStates:
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
self.state = self.place_chest
else:
self.g.chat.send('I need a chest')
print('No chest, aborting')
self.state = self.cleanup
def place_chest(self):
@ -616,7 +616,8 @@ class CacheItemsStates:
def close_chest(self):
print('closing chest')
self.g.game.close_window()
self.g.chat.send('cache at ' + str(self.area)[1:-1])
if not self.silent:
self.g.chat.send('cache at ' + str(self.area)[1:-1])
self.state = self.cleanup
def cleanup(self):
@ -631,6 +632,8 @@ class CacheItemsStates:
self.g = global_state
self.state = self.idle
self.silent = False
# keep all needed items
self.needed_items = items.NEEDED_ITEMS
# keep one stack of wanted items
@ -691,47 +694,35 @@ class PlantTreeStates:
p = utils.pint(self.g.pos)
self.g.game.place_block(p, BlockFace.TOP)
print('Placed sapling')
self.state = self.cleanup
# self.state = self.wait_place
# self.wait_time = 1
self.state = self.wait_place
self.wait_time = 1
#def wait_place(self):
# # wait a bit for chunk data to update
# if self.wait_time > 0:
# self.wait_time -= utils.TICK
# else:
# self.state = self.find_open_spot
def wait_place(self):
# wait a bit for chunk data to update
if self.wait_time > 0:
self.wait_time -= utils.TICK
else:
self.state = self.find_open_spot
#def find_open_spot(self):
# print('Finding an open spot to stand...')
# w = self.g.world
# p = utils.pint(self.g.pos)
def find_open_spot(self):
w = self.g.world
p = utils.pint(self.g.pos)
# for area in w.find_cache_areas(p, 20):
# print('Found area:', area)
# if area not in self.bad_areas:
# break
# else: # for
# print('Unable to find area')
# self.state = self.cleanup
# return
for opening in w.find_tree_openings(p):
print('trying sapling opening', opening)
navpath = w.path_to_place(p, opening)
if navpath:
self.g.path = navpath
self.area = opening
self.state = self.going_to_area
return
else: # for
print('cant escape sapling')
self.state = self.cleanup
# self.area = area
# navpath = w.path_to_place(p, self.area)
# if not navpath:
# print('Unable to get to open area', self.area)
# self.bad_areas.append(self.area)
# self.state = self.cleanup
# return
# self.g.path = navpath
# self.state = self.going_to_area
# print('Going to area', self.area)
#def going_to_area(self):
# if utils.pint(self.g.pos) == self.area:
# self.state = self.cleanup
def going_to_area(self):
if utils.pint(self.g.pos) == self.area:
self.state = self.cleanup
def cleanup(self):
self.g.look_at = None
@ -747,7 +738,6 @@ class PlantTreeStates:
self.wait_time = 0
self.area = None
self.bad_areas = []
def run(self):
self.state()
@ -960,6 +950,7 @@ class JobStates:
def farm_wood(self):
self.sleep_with_bed_states.silent = True
self.cache_items_states.silent = True
s1 = self.gather_wood_states
s2 = self.plant_tree_states