Cache items into trapped chests

This commit is contained in:
2020-12-01 00:48:02 +00:00
parent efcefc8192
commit eabb0a04d1
5 changed files with 93 additions and 16 deletions
+55 -10
View File
@@ -388,11 +388,19 @@ class SleepWithBedStates:
def init(self):
if self.g.time >= 12000:
self.state = self.find_bed_spot
self.state = self.select_bed
else:
print('Aborting sleep, not night')
self.state = self.cleanup
def select_bed(self):
if self.g.game.select_item(items.BED_IDS):
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
self.state = self.find_bed_spot
else:
print('No bed, aborting.')
self.state = self.cleanup
def find_bed_spot(self):
print('Finding a bed spot...')
w = self.g.world
@@ -426,15 +434,7 @@ class SleepWithBedStates:
def going_to_area(self):
if utils.pint(self.g.pos) == self.opening:
self.g.look_at = self.area
self.state = self.select_bed
def select_bed(self):
if self.g.game.select_item(items.BED_IDS):
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
self.state = self.place_bed
else:
print('No bed, aborting.')
self.state = self.cleanup
def place_bed(self):
self.g.game.place_block(self.area, BlockFace.TOP)
@@ -504,11 +504,55 @@ class CacheItemsStates:
num_stacks = len([x for x in self.g.inv.values() if x.present])
print('Inventory amount:', num_stacks)
if num_stacks >= 27:
self.state = self.find_cache_spot
self.state = self.find_trapped_chests
else:
print('Aborting caching, not full')
self.state = self.cleanup
def find_trapped_chests(self):
print('Finding trapped chests...')
w = self.g.world
p = utils.pint(self.g.pos)
self.trapped_chests = w.find_blocks_indexed(p, blocks.TRAPPED_CHEST_IDS, 100)
print('Found:', self.trapped_chests)
self.state = self.choose_trapped_chest
def choose_trapped_chest(self):
print('Choosing a trapped chest...')
w = self.g.world
p = utils.pint(self.g.pos)
c = self.g.chunks
if not len(self.trapped_chests):
print('No trapped chests')
self.state = self.find_cache_spot
return
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)
print('navpath:', navpath)
if navpath:
self.g.path = navpath[:-1]
self.opening = self.g.path[-1]
self.area = chest
self.state = self.going_to_trapped_chest
return
else:
self.trapped_chests.pop(0)
def going_to_trapped_chest(self):
if utils.pint(self.g.pos) == self.opening:
self.g.look_at = self.area
self.state = self.open_chest
def find_cache_spot(self):
print('Finding a chest spot...')
w = self.g.world
@@ -644,6 +688,7 @@ class CacheItemsStates:
self.area = None
self.opening = None
self.trapped_chests = []
self.bad_areas = []
self.wait_time = 0