Allow sleeping during thunderstorms

This commit is contained in:
Tanner committed 2026-11-10 15:46:13 +00:00
1 parent 95e6d5e275
commit 36dfa312ad
2 files changed
+33 -3

No files matched your search

+7 -3
View File
@@ -20,6 +20,9 @@ class SleepWithBedStates:
def idle(self): def idle(self):
return None return None
def _is_thunderstorm(self):
return self.g.get('weather') == 'thunderstorm'
def init(self): def init(self):
self.sleep_confirmed = False self.sleep_confirmed = False
self.my_bed = False self.my_bed = False
@@ -37,8 +40,9 @@ class SleepWithBedStates:
current_time = self.g.get('time') current_time = self.g.get('time')
self.sleep_attempt_started_at = current_time self.sleep_attempt_started_at = current_time
if current_time is None or current_time < 12000: if ((current_time is None or current_time < 12000) and
print('Aborting sleep, not night') not self._is_thunderstorm()):
print('Aborting sleep, not night or thunderstorm')
self.state = self.cleanup self.state = self.cleanup
return return
@@ -289,7 +293,7 @@ class SleepWithBedStates:
print('Bed became occupied before use:', self.area) print('Bed became occupied before use:', self.area)
self.state = self.choose_bed self.state = self.choose_bed
return return
if current_time < 12550: if current_time < 12550 and not self._is_thunderstorm():
if (self.sleep_attempt_started_at is not None and if (self.sleep_attempt_started_at is not None and
self.sleep_attempt_started_at >= 12000 and self.sleep_attempt_started_at >= 12000 and
current_time < 12000): current_time < 12000):
+26
View File
@@ -407,6 +407,32 @@ class TestSleepWithBed(unittest.TestCase):
state.init() state.init()
self.assertEqual(state.state, state.cleanup) self.assertEqual(state.state, state.cleanup)
def test_daytime_thunderstorm_allows_sleep_attempt(self):
state = SleepWithBedStates(Munch(
time=1000, weather='thunderstorm', dimension='overworld'))
state.init()
self.assertEqual(state.state, state.find_beds)
def test_thunderstorm_allows_bed_use_during_daytime(self):
bed_id = next(iter(blocks.BED_IDS))
game = FakeGame()
state = SleepWithBedStates(Munch(
time=12400, weather='clear', dimension='overworld',
world=FakeWorld(block=bed_id), game=game, path=[], look_at=None))
state.init()
state.area = (0, 64, 0)
state.state = state.use_bed
state.silent = True
state.g.time = 1000
state.g.weather = 'thunderstorm'
state.use_bed()
self.assertEqual(state.state, state.sleep_bed)
self.assertEqual(len(game.placements), 1)
def test_placing_bed_uses_support_block_face_top(self): def test_placing_bed_uses_support_block_face_top(self):
game = FakeGame() game = FakeGame()
state = SleepWithBedStates(Munch( state = SleepWithBedStates(Munch(