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 -63
View File
@@ -12,7 +12,6 @@ from mosfet.protocol.managers import ChunkNotLoadedException
from mosfet import utils
from mosfet import path
from mosfet.jobs.work_boundary import WorkBoundaryReturnMixin
from mosfet.info import blocks
from mosfet.info import items
from mosfet.info import mobs
@@ -42,15 +41,7 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
position)
self._processed_chest_open_events.intersection_update(current_events)
def _chest_positions(self, chest):
finder = getattr(self.g.world, '_double_chest_positions', None)
if finder:
positions = finder(tuple(chest))
if positions:
return tuple(tuple(position) for position in positions)
return (tuple(chest),)
def _has_compatible_labeled_chest_near(self, bed, distance=16):
def _has_compatible_cache_chest_near(self, bed, distance=16):
world = self.g.get('world')
if world is None:
return False
@@ -69,6 +60,13 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
slot in keep_slots):
continue
return True
for chest in world.find_cache_chests(
bed, self.g.get('name', ''), distance):
positions = chest.get('positions') or (chest['position'],)
if min(utils.phyp(bed, position) for position in positions) > distance:
continue
if self._has_transferable_item(items.ITEM_NAMES):
return True
return False
def _find_throw_signs(self):
@@ -152,7 +150,7 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
print('No reachable throw opening for sign', sign['position'])
self.throw_sign = None
self.state = self.choose_trapped_chest
self.state = self.choose_cache_chest
def going_to_throw_sign(self):
if utils.pint(self.g.pos) == self.opening:
@@ -234,7 +232,7 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
'minimum', self.g.get('minimum_cache_slots', 27))
post_sleep_bed = self.g.pop('post_sleep_cache_bed', None)
if (not has_override and post_sleep_bed is not None and
self._has_compatible_labeled_chest_near(post_sleep_bed)):
self._has_compatible_cache_chest_near(post_sleep_bed)):
minimum = ceil(minimum / 2)
print('Lowering cache threshold after sleep near a compatible chest:',
minimum)
@@ -242,13 +240,13 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
if num_stacks == 0:
self.state = self.cleanup
elif num_stacks >= minimum:
self.state = self.find_trapped_chests
self.state = self.find_cache_targets
else:
print('Aborting caching, not full')
self.state = self.cleanup
def find_trapped_chests(self):
print('Finding labeled and trapped chests...')
def find_cache_targets(self):
print('Finding item-specific and general cache chests...')
w = self.g.world
p = utils.pint(self.g.pos)
@@ -256,10 +254,11 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
self.checked_throw_signs = set()
self.labeled_chests = w.find_labeled_chests(p, 105)
self.checked_labeled_chests = set()
self.trapped_chests = w.find_blocks_indexed(p, blocks.TRAPPED_CHEST_IDS)
print('Found {} labeled chests; found {} trapped chests: {}'.format(
len(self.labeled_chests), len(self.trapped_chests),
self.trapped_chests))
self.cache_chests = w.find_cache_chests(
p, self.g.get('name', ''), 105)
self.checked_cache_chests = set()
print('Found {} item-specific chests and {} general cache chests'.format(
len(self.labeled_chests), len(self.cache_chests)))
self.state = self.choose_throw_sign
def _opening_in_bad_region(self, world, opening):
@@ -276,8 +275,8 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
return True
return False
def choose_trapped_chest(self):
print('Choosing a labeled or trapped chest...')
def choose_cache_chest(self):
print('Choosing an item-specific or general cache chest...')
self.bad_openings = set()
w = self.g.world
p = utils.pint(self.g.pos)
@@ -310,61 +309,62 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
self.open_interaction = opening
self.g.path = navpath
self.g.look_at = None
self.state = self.going_to_trapped_chest
self.state = self.going_to_cache_chest
return
self.bad_openings.add(opening_position)
print('No path to labeled chest', self.area)
while (self.trapped_chests and
self._chest_positions(self.trapped_chests[0]) in
self.useless_chests):
self.trapped_chests.pop(0)
if not len(self.trapped_chests):
self.is_labeled_container = False
self.container_item_ids = None
if self.transferred_to_labeled_chest:
print('Already cached items in labeled chests; skipping new chest')
self.state = self.cleanup
return
print('No labeled or trapped chests')
self.state = self.select_chest
return
# General cache chests are a fallback, after all matching item-specific
# chests have been checked.
self.is_labeled_container = False
self.container_item_ids = None
chest = self.trapped_chests[0]
self.area = chest
self.current_container_key = self._chest_positions(chest)
for opening in w.find_cache_openings(chest, p):
opening_position = tuple(opening['position'])
if self._opening_in_bad_region(w, opening_position):
for container in self.cache_chests:
key = tuple(tuple(position) for position in
(container.get('positions') or
(container['position'],)))
if (key in self.checked_cache_chests or
key in self.useless_chests):
continue
self.checked_cache_chests.add(key)
if not self._has_transferable_item(items.ITEM_NAMES):
continue
navpath = w.path_to_place(p, opening_position)
if (navpath and
self._accept_cache_trip(p, opening_position, navpath)):
print('navpath to trapped chest:', navpath)
self.opening = opening_position
self.open_interaction = opening
self.g.path = navpath
self.g.look_at = None
self.state = self.going_to_trapped_chest
return
self.bad_openings.add(opening_position)
self.trapped_chests.pop(0)
time.sleep(0.1)
chest = container['position']
self.area = chest
self.current_container_key = key
for opening in w.find_cache_openings(chest, p):
opening_position = tuple(opening['position'])
if self._opening_in_bad_region(w, opening_position):
continue
navpath = w.path_to_place(p, opening_position)
if (navpath and
self._accept_cache_trip(p, opening_position, navpath)):
print('Going to general cache chest:', chest)
self.opening = opening_position
self.open_interaction = opening
self.g.path = navpath
self.g.look_at = None
self.state = self.going_to_cache_chest
return
self.bad_openings.add(opening_position)
print('No path to general cache chest:', chest)
def going_to_trapped_chest(self):
if self.transferred_to_labeled_chest:
print('Already cached items in item-specific chests; skipping new chest')
self.state = self.cleanup
return
print('No item-specific or general cache chests')
self.state = self.select_chest
def going_to_cache_chest(self):
if utils.pint(self.g.pos) == self.opening:
self.g.look_at = self.open_interaction['look_at']
self.wait_time = 0.5
self.state = self.turn_to_trapped_chest
self.state = self.turn_to_cache_chest
else:
self.g.look_at = None
def turn_to_trapped_chest(self):
def turn_to_cache_chest(self):
self.g.look_at = self.open_interaction['look_at']
self.wait_time -= utils.TICK
if self.wait_time <= 0:
@@ -629,7 +629,7 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
if self.is_labeled_container:
self.is_labeled_container = False
self.container_item_ids = None
self.state = self.choose_trapped_chest
self.state = self.choose_cache_chest
else:
self.state = self.cleanup
@@ -660,6 +660,8 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
self.labeled_chests = []
self.checked_labeled_chests = set()
self.cache_chests = []
self.checked_cache_chests = set()
self.useless_chests = set()
self._processed_chest_open_events = {
self._chest_event_key(event)
@@ -672,7 +674,6 @@ class CacheItemsStates(WorkBoundaryReturnMixin):
self.area = None
self.opening = None
self.open_interaction = None
self.trapped_chests = []
self.bad_areas = []
self.wait_time = 0
self.throw_signs = []