Don't sleep in occupied beds
This commit is contained in:
parent
8b85de2b2a
commit
d69f9cf09e
|
@ -42,8 +42,13 @@ class SleepWithBedStates:
|
|||
|
||||
self.beds = []
|
||||
for bed in result:
|
||||
if bed not in self.bad_beds:
|
||||
self.beds.append(bed)
|
||||
if bed in self.bad_beds:
|
||||
continue
|
||||
|
||||
if w.check_bed_occupied(bed):
|
||||
continue
|
||||
|
||||
self.beds.append(bed)
|
||||
|
||||
print('Found:', self.beds)
|
||||
self.state = self.choose_bed
|
||||
|
@ -84,6 +89,7 @@ class SleepWithBedStates:
|
|||
|
||||
def going_to_bed(self):
|
||||
if utils.pint(self.g.pos) == self.opening:
|
||||
print('At existing bed')
|
||||
self.my_bed = False
|
||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||
self.state = self.use_bed
|
||||
|
@ -128,32 +134,43 @@ class SleepWithBedStates:
|
|||
|
||||
def going_to_area(self):
|
||||
if utils.pint(self.g.pos) == self.opening:
|
||||
print('At bed area')
|
||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||
self.state = self.place_bed
|
||||
|
||||
def place_bed(self):
|
||||
print('Placing bed')
|
||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||
self.my_bed = True
|
||||
self.state = self.use_bed
|
||||
|
||||
def use_bed(self):
|
||||
if self.g.time > 12550:
|
||||
print('Sleeping')
|
||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||
if not self.silent:
|
||||
self.g.chat.send('zzz')
|
||||
self.state = self.sleep_bed
|
||||
w = self.g.world
|
||||
|
||||
if self.g.time < 12550:
|
||||
return
|
||||
|
||||
if w.check_bed_occupied(self.area):
|
||||
print('Bed occupied, aborting.')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
print('Using bed')
|
||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||
if not self.silent:
|
||||
self.g.chat.send('zzz')
|
||||
self.state = self.sleep_bed
|
||||
|
||||
def sleep_bed(self):
|
||||
w = self.g.world
|
||||
p = utils.pint(self.g.pos)
|
||||
|
||||
threats = w.find_threats(p, 30)
|
||||
threats = w.find_threats(p, 10)
|
||||
if threats:
|
||||
print('Waking up due to threats:')
|
||||
print(threats)
|
||||
self.g.game.leave_bed()
|
||||
self.state = self.break_bed
|
||||
self.state = self.cleanup
|
||||
elif self.g.time < 100:
|
||||
print('Woke up time')
|
||||
self.state = self.break_bed
|
||||
|
@ -165,7 +182,6 @@ class SleepWithBedStates:
|
|||
else:
|
||||
self.state = self.cleanup
|
||||
|
||||
|
||||
def collect_bed(self):
|
||||
if not self.g.breaking:
|
||||
self.g.path = [utils.padd(self.area, utils.spiral(n)) for n in range(9)]
|
||||
|
|
|
@ -259,6 +259,16 @@ class World:
|
|||
result.append(utils.padd(area, direction))
|
||||
return result
|
||||
|
||||
def check_bed_occupied(self, bed):
|
||||
# returns true if the bed is occupied by a player
|
||||
print('Checking bed occupancy:', bed)
|
||||
for player in self.g.players.values():
|
||||
ppos = utils.pint((player.x, player.y, player.z))
|
||||
if utils.phyp(bed, ppos) <= 1 and player.y - int(player.y) == 0.6875:
|
||||
print('Bed is occupied by:', player, self.g.player_names[player.player_uuid])
|
||||
return True
|
||||
return False
|
||||
|
||||
def find_cache_openings(self, area):
|
||||
return self.find_bed_openings(area)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user