Move beside planted sapling
This commit is contained in:
parent
ee2a1958f9
commit
bd8f8a0d55
75
jobs.py
75
jobs.py
|
@ -433,7 +433,7 @@ class SleepWithBedStates:
|
||||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||||
self.state = self.place_bed
|
self.state = self.place_bed
|
||||||
else:
|
else:
|
||||||
self.g.chat.send('I need a bed')
|
print('No bed, aborting.')
|
||||||
self.state = self.cleanup
|
self.state = self.cleanup
|
||||||
|
|
||||||
def place_bed(self):
|
def place_bed(self):
|
||||||
|
@ -549,7 +549,7 @@ class CacheItemsStates:
|
||||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||||
self.state = self.place_chest
|
self.state = self.place_chest
|
||||||
else:
|
else:
|
||||||
self.g.chat.send('I need a chest')
|
print('No chest, aborting')
|
||||||
self.state = self.cleanup
|
self.state = self.cleanup
|
||||||
|
|
||||||
def place_chest(self):
|
def place_chest(self):
|
||||||
|
@ -616,6 +616,7 @@ class CacheItemsStates:
|
||||||
def close_chest(self):
|
def close_chest(self):
|
||||||
print('closing chest')
|
print('closing chest')
|
||||||
self.g.game.close_window()
|
self.g.game.close_window()
|
||||||
|
if not self.silent:
|
||||||
self.g.chat.send('cache at ' + str(self.area)[1:-1])
|
self.g.chat.send('cache at ' + str(self.area)[1:-1])
|
||||||
self.state = self.cleanup
|
self.state = self.cleanup
|
||||||
|
|
||||||
|
@ -631,6 +632,8 @@ class CacheItemsStates:
|
||||||
self.g = global_state
|
self.g = global_state
|
||||||
self.state = self.idle
|
self.state = self.idle
|
||||||
|
|
||||||
|
self.silent = False
|
||||||
|
|
||||||
# keep all needed items
|
# keep all needed items
|
||||||
self.needed_items = items.NEEDED_ITEMS
|
self.needed_items = items.NEEDED_ITEMS
|
||||||
# keep one stack of wanted items
|
# keep one stack of wanted items
|
||||||
|
@ -691,47 +694,35 @@ class PlantTreeStates:
|
||||||
p = utils.pint(self.g.pos)
|
p = utils.pint(self.g.pos)
|
||||||
self.g.game.place_block(p, BlockFace.TOP)
|
self.g.game.place_block(p, BlockFace.TOP)
|
||||||
print('Placed sapling')
|
print('Placed sapling')
|
||||||
|
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 find_open_spot(self):
|
||||||
|
w = self.g.world
|
||||||
|
p = utils.pint(self.g.pos)
|
||||||
|
|
||||||
|
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.state = self.cleanup
|
||||||
# self.state = self.wait_place
|
|
||||||
# self.wait_time = 1
|
|
||||||
|
|
||||||
#def wait_place(self):
|
def going_to_area(self):
|
||||||
# # wait a bit for chunk data to update
|
if utils.pint(self.g.pos) == self.area:
|
||||||
# if self.wait_time > 0:
|
self.state = self.cleanup
|
||||||
# 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)
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# 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 cleanup(self):
|
def cleanup(self):
|
||||||
self.g.look_at = None
|
self.g.look_at = None
|
||||||
|
@ -747,7 +738,6 @@ class PlantTreeStates:
|
||||||
|
|
||||||
self.wait_time = 0
|
self.wait_time = 0
|
||||||
self.area = None
|
self.area = None
|
||||||
self.bad_areas = []
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.state()
|
self.state()
|
||||||
|
@ -960,6 +950,7 @@ class JobStates:
|
||||||
|
|
||||||
def farm_wood(self):
|
def farm_wood(self):
|
||||||
self.sleep_with_bed_states.silent = True
|
self.sleep_with_bed_states.silent = True
|
||||||
|
self.cache_items_states.silent = True
|
||||||
|
|
||||||
s1 = self.gather_wood_states
|
s1 = self.gather_wood_states
|
||||||
s2 = self.plant_tree_states
|
s2 = self.plant_tree_states
|
||||||
|
|
Loading…
Reference in New Issue
Block a user