Try using already placed beds first
This commit is contained in:
parent
0bdae1f775
commit
ef68956e63
38
blocks.py
38
blocks.py
|
@ -237,12 +237,31 @@ SAPLINGS = [
|
|||
'dark_oak_sapling',
|
||||
]
|
||||
|
||||
BEDS = [
|
||||
'white_bed',
|
||||
'orange_bed',
|
||||
'magenta_bed',
|
||||
'light_blue_bed',
|
||||
'yellow_bed',
|
||||
'lime_bed',
|
||||
'pink_bed',
|
||||
'gray_bed',
|
||||
'light_gray_bed',
|
||||
'cyan_bed',
|
||||
'purple_bed',
|
||||
'blue_bed',
|
||||
'brown_bed',
|
||||
'green_bed',
|
||||
'red_bed',
|
||||
'black_bed',
|
||||
]
|
||||
|
||||
INDEXED = [
|
||||
'chest',
|
||||
'trapped_chest',
|
||||
'emerald_block',
|
||||
'barrel',
|
||||
]
|
||||
] + BEDS
|
||||
|
||||
|
||||
NON_SOLID_IDS = set([SINGLE_SNOW])
|
||||
|
@ -310,16 +329,23 @@ for block_name in ['beetroots']:
|
|||
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
||||
BEETROOT_IDS.add(state['id'])
|
||||
|
||||
INDEXED_IDS = set()
|
||||
for block_name in INDEXED:
|
||||
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
||||
INDEXED_IDS.add(state['id'])
|
||||
|
||||
SAPLING_IDS = set()
|
||||
for block_name in SAPLINGS:
|
||||
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
||||
SAPLING_IDS.add(state['id'])
|
||||
|
||||
BED_IDS = set()
|
||||
for block_name in BEDS:
|
||||
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
||||
BED_IDS.add(state['id'])
|
||||
|
||||
|
||||
|
||||
INDEXED_IDS = set()
|
||||
for block_name in INDEXED:
|
||||
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
||||
INDEXED_IDS.add(state['id'])
|
||||
|
||||
MATURE_WHEAT_ID = max(WHEAT_IDS)
|
||||
MATURE_POTATO_ID = max(POTATO_IDS)
|
||||
MATURE_CARROT_ID = max(CARROT_IDS)
|
||||
|
|
57
jobs.py
57
jobs.py
|
@ -732,7 +732,51 @@ class SleepWithBedStates:
|
|||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
self.state = self.select_bed
|
||||
self.state = self.find_beds
|
||||
|
||||
def find_beds(self):
|
||||
print('Finding beds...')
|
||||
w = self.g.world
|
||||
p = utils.pint(self.g.pos)
|
||||
|
||||
self.beds = w.find_blocks_indexed(p, blocks.BED_IDS)
|
||||
print('Found:', self.beds)
|
||||
self.state = self.choose_bed
|
||||
|
||||
def choose_bed(self):
|
||||
print('Choosing a bed...')
|
||||
w = self.g.world
|
||||
p = utils.pint(self.g.pos)
|
||||
c = self.g.chunks
|
||||
|
||||
if not len(self.beds):
|
||||
print('No beds')
|
||||
self.state = self.select_bed
|
||||
return
|
||||
|
||||
bed = self.beds[0]
|
||||
|
||||
tmp = c.get_block_at(*bed)
|
||||
c.set_block_at(*bed, blocks.AIR)
|
||||
navpath = w.path_to_place(p, bed)
|
||||
c.set_block_at(*bed, tmp)
|
||||
|
||||
print('navpath:', navpath)
|
||||
|
||||
if navpath:
|
||||
self.g.path = navpath[:-1]
|
||||
self.opening = self.g.path[-1]
|
||||
self.area = bed
|
||||
self.state = self.going_to_bed
|
||||
return
|
||||
else:
|
||||
self.beds.pop(0)
|
||||
|
||||
def going_to_bed(self):
|
||||
if utils.pint(self.g.pos) == self.opening:
|
||||
self.my_bed = False
|
||||
self.g.look_at = self.area
|
||||
self.state = self.use_bed
|
||||
|
||||
def select_bed(self):
|
||||
if self.g.game.select_item(items.BED_IDS):
|
||||
|
@ -778,6 +822,7 @@ class SleepWithBedStates:
|
|||
|
||||
def place_bed(self):
|
||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||
self.my_bed = True
|
||||
self.state = self.use_bed
|
||||
|
||||
def use_bed(self):
|
||||
|
@ -803,8 +848,12 @@ class SleepWithBedStates:
|
|||
self.state = self.break_bed
|
||||
|
||||
def break_bed(self):
|
||||
self.g.game.break_block(self.area)
|
||||
self.state = self.collect_bed
|
||||
if self.my_bed:
|
||||
self.g.game.break_block(self.area)
|
||||
self.state = self.collect_bed
|
||||
else:
|
||||
self.state = self.cleanup
|
||||
|
||||
|
||||
def collect_bed(self):
|
||||
if not self.g.breaking:
|
||||
|
@ -833,6 +882,8 @@ class SleepWithBedStates:
|
|||
|
||||
self.silent = False
|
||||
|
||||
self.my_bed = False
|
||||
self.beds = []
|
||||
self.area = None
|
||||
self.opening = None
|
||||
self.bad_areas = []
|
||||
|
|
Loading…
Reference in New Issue
Block a user