Allow sleeping during thunderstorms
This commit is contained in:
1 parent
95e6d5e275
commit
36dfa312ad
2 files changed
+33
-3
No files matched your search
@@ -20,6 +20,9 @@ class SleepWithBedStates:
|
||||
def idle(self):
|
||||
return None
|
||||
|
||||
def _is_thunderstorm(self):
|
||||
return self.g.get('weather') == 'thunderstorm'
|
||||
|
||||
def init(self):
|
||||
self.sleep_confirmed = False
|
||||
self.my_bed = False
|
||||
@@ -37,8 +40,9 @@ class SleepWithBedStates:
|
||||
|
||||
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')
|
||||
if ((current_time is None or current_time < 12000) and
|
||||
not self._is_thunderstorm()):
|
||||
print('Aborting sleep, not night or thunderstorm')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
@@ -289,7 +293,7 @@ class SleepWithBedStates:
|
||||
print('Bed became occupied before use:', self.area)
|
||||
self.state = self.choose_bed
|
||||
return
|
||||
if current_time < 12550:
|
||||
if current_time < 12550 and not self._is_thunderstorm():
|
||||
if (self.sleep_attempt_started_at is not None and
|
||||
self.sleep_attempt_started_at >= 12000 and
|
||||
current_time < 12000):
|
||||
|
||||
@@ -407,6 +407,32 @@ class TestSleepWithBed(unittest.TestCase):
|
||||
state.init()
|
||||
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):
|
||||
game = FakeGame()
|
||||
state = SleepWithBedStates(Munch(
|
||||
|
||||
Reference in new issue
Block a user