Add signed general cache destinations

This commit is contained in:
Tanner committed 2026-11-14 23:12:50 +00:00
1 parent 11c1bad0c4
commit 86fbf911a5
7 files changed
+305 -114

No files matched your search

+64 -22
View File
@@ -140,7 +140,8 @@ class World:
tokens[1] != 'throw'):
continue
item_name = '_'.join(tokens[2:])
item_ids = items.storage_item_ids_for_label(item_name)
item_label = ' '.join(tokens[2:])
item_ids = items.storage_item_ids_for_label(item_label)
if not item_ids:
item_ids = items.get_set({item_name})
if not item_ids:
@@ -272,13 +273,35 @@ class World:
return tuple(sorted((tuple(chest), partner)))
return (tuple(chest),)
def _chests_associated_with_sign(self, sign):
sign_pos = tuple(sign['position'])
side_offsets = (
(1, 0, 0), (-1, 0, 0), (0, 0, 1), (0, 0, -1),
)
top_offsets = ((0, 0, 0), (0, -1, 0))
adjacent = {
utils.padd(sign_pos, offset)
for offset in side_offsets
if self.block_at(*utils.padd(sign_pos, offset)) in blocks.CHEST_IDS
}
if not adjacent:
adjacent = {
utils.padd(sign_pos, offset)
for offset in top_offsets
if self.block_at(*utils.padd(sign_pos, offset)) in blocks.CHEST_IDS
}
if not adjacent:
nearby = self.find_blocks_indexed(
sign_pos, blocks.CHEST_IDS, 2)
if nearby:
nearest = min(utils.phyp(sign_pos, chest) for chest in nearby)
adjacent = {chest for chest in nearby
if utils.phyp(sign_pos, chest) == nearest}
return adjacent
def find_labeled_chests(self, center, distance=105):
"""Find single/double chests assigned item categories by nearby signs."""
grouped = {}
sign_offsets = (
(0, 0, 0), (0, -1, 0),
(1, 0, 0), (-1, 0, 0), (0, 0, 1), (0, 0, -1),
)
for sign in self.find_signs(center, distance):
categories = set()
labels = set()
@@ -290,22 +313,9 @@ class World:
if not categories:
continue
sign_pos = sign['position']
adjacent = {
utils.padd(sign_pos, offset)
for offset in sign_offsets
if self.block_at(*utils.padd(sign_pos, offset)) in blocks.CHEST_IDS
}
if not adjacent:
nearby = self.find_blocks_indexed(
sign_pos, blocks.CHEST_IDS, 2)
if nearby:
nearest = min(utils.phyp(sign_pos, chest)
for chest in nearby)
adjacent = {chest for chest in nearby
if utils.phyp(sign_pos, chest) == nearest}
for chest in adjacent:
# Side-mounted signs take priority over signs on top when chests
# occupy both positions beside the sign.
for chest in self._chests_associated_with_sign(sign):
positions = self._double_chest_positions(chest)
record = grouped.setdefault(positions, {
'position': tuple(chest),
@@ -316,7 +326,39 @@ class World:
})
record['item_ids'].update(categories)
record['labels'].update(labels)
record['sign_positions'].add(sign_pos)
record['sign_positions'].add(tuple(sign['position']))
result = list(grouped.values())
result.sort(key=lambda chest: utils.phyp(center, chest['position']))
return result
def find_cache_chests(self, center, bot_name, distance=105):
"""Find bot/group-addressed general cache chests from signs."""
bot_name = str(bot_name).casefold()
group_name = (bot_name[:-1] if len(bot_name) > 1 and
bot_name[-1] in '123' else None)
addresses = {bot_name}
if group_name:
addresses.add(group_name)
grouped = {}
for sign in self.find_signs(center, distance):
text = ' '.join(line for line in sign['lines'] if line.strip())
tokens = re.findall(r'[a-z0-9_]+', text.casefold())
if (len(tokens) < 2 or tokens[0] not in addresses or
'cache' not in tokens[1:]):
continue
for chest in self._chests_associated_with_sign(sign):
positions = self._double_chest_positions(chest)
record = grouped.setdefault(positions, {
'position': tuple(chest),
'positions': positions,
'labels': set(),
'sign_positions': set(),
})
record['labels'].add('cache')
record['sign_positions'].add(tuple(sign['position']))
result = list(grouped.values())
result.sort(key=lambda chest: utils.phyp(center, chest['position']))