From 4d2d358175f3650f378eec943246ee3eb151647d Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 7 May 2021 04:02:26 +0000 Subject: [PATCH] Use block state id to check bed occupancy --- mosfet/info/blocks.py | 5 +++++ mosfet/jobs/sleep_with_bed.py | 10 +++++++++- mosfet/world.py | 14 +++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/mosfet/info/blocks.py b/mosfet/info/blocks.py index a9b3ff9..8028480 100644 --- a/mosfet/info/blocks.py +++ b/mosfet/info/blocks.py @@ -15,6 +15,11 @@ for name, data in JSON_BLOCKS.items(): for state in data['states']: BLOCKS[state['id']] = name.replace('minecraft:', '') +PROPS = {} +for name, data in JSON_BLOCKS.items(): + for state in data['states']: + PROPS[state['id']] = state.get('properties', {}) + BREAK_DISTANCE = 6 AIR = 0 diff --git a/mosfet/jobs/sleep_with_bed.py b/mosfet/jobs/sleep_with_bed.py index 3674872..8d4437d 100644 --- a/mosfet/jobs/sleep_with_bed.py +++ b/mosfet/jobs/sleep_with_bed.py @@ -139,7 +139,15 @@ class SleepWithBedStates: print('Placing bed') self.g.game.place_block(self.area, BlockFace.TOP) self.my_bed = True - self.state = self.use_bed + self.wait_time = 0.5 + self.state = self.wait_use + + def wait_use(self): + # wait to use the bed + if self.wait_time > 0: + self.wait_time -= utils.TICK + else: + self.state = self.use_bed def use_bed(self): w = self.g.world diff --git a/mosfet/world.py b/mosfet/world.py index 21e9529..1198940 100644 --- a/mosfet/world.py +++ b/mosfet/world.py @@ -280,13 +280,13 @@ class World: 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 + bid = self.g.chunks.get_block_at(*bed) + if blocks.PROPS[bid]['occupied'] == 'true': + print('Checking bed occupancy:', bed, '-> occupied') + return True + else: + print('Checking bed occupancy:', bed, '-> free') + return False def find_cache_openings(self, area): return self.find_bed_openings(area)