Detect being forced to wake up

This commit is contained in:
Tanner Collin 2021-04-25 00:59:43 +00:00
parent d69f9cf09e
commit 650398255b
2 changed files with 5 additions and 2 deletions

View File

@ -206,8 +206,8 @@ def tick(global_state):
packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=g.pitch, yaw=g.yaw, on_ground=(not in_air)) packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=g.pitch, yaw=g.yaw, on_ground=(not in_air))
g.connection.write_packet(packet) g.connection.write_packet(packet)
g.game.tick()
g.job.tick() g.job.tick()
g.game.tick() # order important for correction_count
def init(global_state): def init(global_state):

View File

@ -164,13 +164,16 @@ class SleepWithBedStates:
def sleep_bed(self): def sleep_bed(self):
w = self.g.world w = self.g.world
p = utils.pint(self.g.pos) p = utils.pint(self.g.pos)
threats = w.find_threats(p, 10) threats = w.find_threats(p, 10)
if threats: if threats:
print('Waking up due to threats:') print('Waking up due to threats:')
print(threats) print(threats)
self.g.game.leave_bed() self.g.game.leave_bed()
self.state = self.cleanup self.state = self.cleanup
elif self.g.correction_count:
print('Forcefully woke up')
self.state = self.collect_bed
elif self.g.time < 100: elif self.g.time < 100:
print('Woke up time') print('Woke up time')
self.state = self.break_bed self.state = self.break_bed