Recover from occupied bed race
This commit is contained in:
@@ -32,6 +32,7 @@ class SleepWithBedStates:
|
||||
self.waiting_for_time_update = False
|
||||
|
||||
current_time = self.g.get('time')
|
||||
self.sleep_attempt_started_at = current_time
|
||||
if current_time is None or current_time < 12000:
|
||||
print('Aborting sleep, not night')
|
||||
self.state = self.cleanup
|
||||
@@ -268,7 +269,22 @@ class SleepWithBedStates:
|
||||
print('Waiting for world time update before using bed')
|
||||
self.waiting_for_time_update = True
|
||||
return
|
||||
if (self.area is not None and
|
||||
w.block_at(*self.area) not in blocks.BED_IDS):
|
||||
print('Bed disappeared before use:', self.area)
|
||||
self.state = self.choose_bed
|
||||
return
|
||||
if self.area is not None and w.check_bed_occupied(self.area):
|
||||
print('Bed became occupied before use:', self.area)
|
||||
self.state = self.choose_bed
|
||||
return
|
||||
if current_time < 12550:
|
||||
if (self.sleep_attempt_started_at is not None and
|
||||
self.sleep_attempt_started_at >= 12000 and
|
||||
current_time < 12000):
|
||||
print('Night ended before bed use; resuming the job')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
if not getattr(self, 'waiting_for_night', False):
|
||||
print('Bed reached; waiting until sleep time (time={})'.format(
|
||||
current_time))
|
||||
@@ -277,16 +293,6 @@ class SleepWithBedStates:
|
||||
self.waiting_for_night = False
|
||||
self.waiting_for_time_update = False
|
||||
|
||||
if w.block_at(*self.area) not in blocks.BED_IDS:
|
||||
print('Bed disappeared before use:', self.area)
|
||||
self.my_bed = False
|
||||
self.state = self.cleanup
|
||||
return
|
||||
if w.check_bed_occupied(self.area):
|
||||
print('Bed occupied, aborting.')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
print('Using bed')
|
||||
# Beds are only 9/16 block tall. Aim inside their collision shape;
|
||||
# the near-top cursor used for placing a new block misses them.
|
||||
@@ -404,6 +410,7 @@ class SleepWithBedStates:
|
||||
self.force_new_bed = False
|
||||
self.sleep_confirmed = False
|
||||
self.sleep_deadline = 0
|
||||
self.sleep_attempt_started_at = None
|
||||
|
||||
def run(self):
|
||||
self.state()
|
||||
|
||||
Reference in New Issue
Block a user