Allow refuge maintenance without resuming jobs

This commit is contained in:
Tanner committed 2026-11-14 18:14:54 +00:00
1 parent 9513dd3671
commit 4cd90a5d65
3 files changed
+128 -13

No files matched your search

+38 -8
View File
@@ -89,7 +89,19 @@ class SleepWithBedStates(WorkBoundaryReturnMixin):
w = self.g.world
p = utils.pint(self.g.pos)
if self.force_new_bed:
refuge_sign = getattr(self, 'refuge_sign', None)
if refuge_sign is not None:
# Refuge maintenance may use existing beds near the sign only;
# never roam farther or place a bed while waiting for threats.
center = tuple(refuge_sign['position'])
indexed = w.find_blocks_indexed(center, blocks.BED_IDS, 5)
nearby = list(w.find_blocks_3d(
center, blocks.BED_IDS, distance=5, y_limit=5))
result = list(dict.fromkeys(nearby + indexed))
result = [bed for bed in result
if utils.phyp(center, bed) <= 5]
result.sort(key=lambda bed: utils.phyp(p, bed))
elif self.force_new_bed:
result = []
print('Skipping existing beds; placing a new bed as requested')
else:
@@ -104,9 +116,13 @@ class SleepWithBedStates(WorkBoundaryReturnMixin):
print('Found beds by local scan; chunk index had none')
result = list(dict.fromkeys(self._bed_foot(bed) for bed in result))
if refuge_sign is not None:
center = tuple(refuge_sign['position'])
result = [bed for bed in result
if utils.phyp(center, bed) <= 5]
self.beds = []
for bed in result:
if bed in self.bad_beds:
if refuge_sign is None and bed in self.bad_beds:
continue
if w.check_bed_occupied(bed):
@@ -128,8 +144,11 @@ class SleepWithBedStates(WorkBoundaryReturnMixin):
navpath = w.path_to_place_faked(p, bed)
print('navpath:', navpath)
if navpath is None:
self.bad_beds.append(bed)
print('Cant get to bed, blacklisting')
if getattr(self, 'refuge_sign', None) is None:
self.bad_beds.append(bed)
print('Cant get to bed, blacklisting')
else:
print('Cant reach refuge bed this attempt; skipping')
continue
self.area = bed
@@ -142,6 +161,11 @@ class SleepWithBedStates(WorkBoundaryReturnMixin):
self.state = self.going_to_bed
return
if getattr(self, 'refuge_sign', None) is not None:
print('No existing bed within 5 blocks of refuge sign; not placing one')
self.state = self.cleanup
return
print('No reachable beds; trying to place one')
self.state = self.select_bed
@@ -160,7 +184,8 @@ class SleepWithBedStates(WorkBoundaryReturnMixin):
elif time.monotonic() >= self.opening_deadline:
print('Could not reach bed opening', self.opening,
'; trying another bed')
self.bad_beds.append(self.area)
if getattr(self, 'refuge_sign', None) is None:
self.bad_beds.append(self.area)
self.g.look_at = None
self.state = self.choose_bed
else:
@@ -359,8 +384,11 @@ class SleepWithBedStates(WorkBoundaryReturnMixin):
self.sleep_retry_at = time.monotonic() + 1.5
elif (not self.sleep_confirmed and
time.monotonic() >= self.sleep_deadline):
print('Bed use was not confirmed; blacklisting', self.area)
self.bad_beds.append(self.area)
if getattr(self, 'refuge_sign', None) is None:
print('Bed use was not confirmed; blacklisting', self.area)
self.bad_beds.append(self.area)
else:
print('Bed use was not confirmed; will retry later', self.area)
self.state = self.cleanup
def break_bed(self):
@@ -397,7 +425,8 @@ class SleepWithBedStates(WorkBoundaryReturnMixin):
self.g.world.block_at(*self.area) in blocks.BED_IDS):
self.state = self.break_bed
return
if self._maybe_return_to_work_boundary(self.cleanup):
if (getattr(self, 'refuge_sign', None) is None and
self._maybe_return_to_work_boundary(self.cleanup)):
return
self.g.look_at = None
self.g.path = []
@@ -440,6 +469,7 @@ class SleepWithBedStates(WorkBoundaryReturnMixin):
self.work_policies = []
self.sleep_deadline = 0
self.sleep_attempt_started_at = None
self.refuge_sign = None
def run(self):
self._track_work_boundary_position()