Add sign-labeled chest storage

This commit is contained in:
Tanner
2026-11-07 16:35:57 +00:00
parent ab8f59a89b
commit 43b37b76f6
7 changed files with 401 additions and 66 deletions
+47 -51
View File
@@ -30,7 +30,7 @@ class GrabSuppliesStates:
def init(self):
print('Started grab supplies states')
self.checked_barrels = []
self.checked_supply_chests = set()
used_slots = self.g.game.count_inventory_slots()
print('used:', used_slots, 'total:', self.g.maximum_supply_slots)
@@ -41,6 +41,7 @@ class GrabSuppliesStates:
self.checked_ground_items = set()
self.checked_ground_groups = set()
self.checked_supply_chests = set()
self.ground_stack_counts = {}
self.ground_entity_id = None
self.ground_position = None
@@ -78,8 +79,8 @@ class GrabSuppliesStates:
self.ground_position = None
def check_supplies(self):
# Search every configured item group on the ground before going to a
# barrel; a missing bed must not hide a nearby chest or food drop.
# Search every configured item group on the ground before looking in
# labeled chests; a missing bed must not hide a nearby chest or food drop.
missing = []
for item_ids, limits in self.supplies.items():
minimum, maximum = limits
@@ -110,9 +111,9 @@ class GrabSuppliesStates:
if missing:
self.target_items, self.target_minimum, self.target_maximum_stacks = missing[0]
print('No more ground drops; checking barrels for',
print('No more ground drops; checking supply-labeled chests for',
self.target_items)
self.state = self.find_barrels
self.state = self.find_supply_chests
return
print('Aborting, dont need any supplies')
@@ -122,7 +123,11 @@ class GrabSuppliesStates:
stack_count = self.ground_stack_counts.get(self.target_items, 0)
if self.target_maximum_stacks and stack_count >= self.target_maximum_stacks:
self.checked_ground_groups.add(self.target_items)
self.state = self.check_supplies
if (self.g.game.count_items(self.target_items) <
self.target_minimum):
self.state = self.find_supply_chests
else:
self.state = self.check_supplies
return
print('Looking for supplies on the ground...')
@@ -199,60 +204,52 @@ class GrabSuppliesStates:
self.ground_position = None
self.state = self.find_ground_items
def find_barrels(self):
print('Finding barrels...')
w = self.g.world
def find_supply_chests(self):
print('Finding chests labeled for this bot\'s supplies...')
p = utils.pint(self.g.pos)
self.supply_chests = self.g.world.find_supply_chests(
p, self.g.name, 80)
print('Found:', len(self.supply_chests), 'supply-labeled chests')
self.state = self.choose_supply_chest
self.barrels = w.find_blocks_indexed(p, blocks.BARREL_IDS, 80)
print('Found:', self.barrels)
self.state = self.choose_barrel
def choose_barrel(self):
print('Choosing a barrel...')
for barrel in self.barrels:
if barrel in self.checked_barrels:
def choose_supply_chest(self):
print('Choosing a supply-labeled chest...')
for container in self.supply_chests:
key = container['positions']
if key in self.checked_supply_chests:
continue
if barrel in self.bad_barrels:
continue
print('Chose:', barrel)
self.barrel = barrel
self.state = self.path_to_barrel
self.checked_supply_chests.add(key)
self.chest = container['position']
self.area = self.chest
print('Chose supply chest:', self.chest)
self.state = self.path_to_supply_chest
return
print('No barrels')
print('No more supply-labeled chests')
self.state = self.cleanup
def path_to_barrel(self):
print('Finding path to barrel')
w = self.g.world
def path_to_supply_chest(self):
print('Finding path to supply chest')
p = utils.pint(self.g.pos)
c = self.g.chunks
navpath = w.path_to_place_faked(p, self.barrel)
navpath = self.g.world.path_to_place_faked(p, self.chest)
print('navpath:', navpath)
if navpath:
self.g.path = navpath[:-1]
self.opening = self.g.path[-1]
self.checked_barrels.append(self.barrel)
self.area = self.barrel
self.state = self.going_to_barrel
self.state = self.going_to_supply_chest
self.checked_supplies = []
return
else:
print('Barrel is unreachable; ending supply task')
self.bad_barrels.append(self.barrel)
self.state = self.cleanup
print('Supply chest is unreachable; trying another labeled chest')
self.state = self.choose_supply_chest
def going_to_barrel(self):
def going_to_supply_chest(self):
if utils.pint(self.g.pos) == self.opening:
self.g.look_at = self.area
self.state = self.open_barrel
self.state = self.open_supply_chest
def open_barrel(self):
print('Opening barrel')
def open_supply_chest(self):
print('Opening supply chest')
self.g.game.open_container(self.area)
self.wait_time = 1
self.state = self.wait
@@ -288,8 +285,8 @@ class GrabSuppliesStates:
self.state = self.grab_items
return
print('Aborting, dont need any more supplies')
self.state = self.close_barrel
print('No matching items in this supply chest')
self.state = self.close_supply_chest
def grab_items(self):
if self.g.item_lock: return
@@ -299,7 +296,7 @@ class GrabSuppliesStates:
print('Didnt get a window, aborting')
self.state = self.cleanup
return
if w.get('container_slots', 0) != 27:
if w.get('container_slots', 0) not in (27, 54):
print('Got wrong container size, aborting')
self.state = self.cleanup
return
@@ -338,11 +335,11 @@ class GrabSuppliesStates:
self.wait_time = 0.25
self.state = self.wait
def close_barrel(self):
print('Closing barrel')
def close_supply_chest(self):
print('Closing supply chest')
self.g.game.close_window()
self.g.look_at = None
self.state = self.choose_barrel
self.state = self.choose_supply_chest
def cleanup(self):
self.state = self.done
@@ -356,10 +353,9 @@ class GrabSuppliesStates:
self.state = self.idle
self.supplies = self.default_supplies()
self.barrels = []
self.checked_barrels = []
self.bad_barrels = []
self.barrel = None
self.supply_chests = []
self.checked_supply_chests = set()
self.supply_chest = None
self.checked_supplies = []
self.target_items = None
self.maximum_stacks = 0