Don't sleep near monsters

This commit is contained in:
Tanner Collin 2020-12-12 21:11:00 +00:00
parent 86846a5c02
commit af88f68e66
3 changed files with 11 additions and 4 deletions

2
bot.py
View File

@ -173,7 +173,7 @@ def tick(global_state):
g.pitch += utils.cap(target_pitch_d, 10) g.pitch += utils.cap(target_pitch_d, 10)
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, force=True) g.connection.write_packet(packet)
g.game.tick() g.game.tick()
g.job.tick() g.job.tick()

10
game.py
View File

@ -150,7 +150,7 @@ class MCWorld:
bed_clearance = 25 # 5x5 area bed_clearance = 25 # 5x5 area
clear_distance = 3 clear_distance = 3
for a in self.find_blocks_3d(center, [0], distance, 10): for a in self.find_blocks_3d(center, [0], distance, 50):
# check for air around the area # check for air around the area
if len(self.find_blocks(a, clear_distance, [0], bed_clearance)) < bed_clearance: if len(self.find_blocks(a, clear_distance, [0], bed_clearance)) < bed_clearance:
continue continue
@ -163,6 +163,11 @@ class MCWorld:
if len(self.find_blocks(utils.padd(a, path.BLOCK_ABOVE), clear_distance, [0], bed_clearance)) < bed_clearance: if len(self.find_blocks(utils.padd(a, path.BLOCK_ABOVE), clear_distance, [0], bed_clearance)) < bed_clearance:
continue continue
# ensure there's no monsters within 20 blocks
# can't sleep if they are within 10, good to have a buffer
if self.find_monsters(a, 20):
continue
yield a yield a
def find_cache_areas(self, center, distance): def find_cache_areas(self, center, distance):
@ -343,7 +348,8 @@ class Game:
if solution: if solution:
solution = list(solution) solution = list(solution)
self.g.path = solution self.g.path = solution
self.g.job.stop() if self.g.job:
self.g.job.stop()
print(len(solution)) print(len(solution))
print(solution) print(solution)
print(round(time.time() - start, 3), 'seconds') print(round(time.time() - start, 3), 'seconds')

View File

@ -906,8 +906,9 @@ class ClearLeavesStates:
def find_leaves(self): def find_leaves(self):
w = self.g.world w = self.g.world
p = utils.pint(self.g.pos) p = utils.pint(self.g.pos)
pos = utils.padd(p, path.BLOCK_ABOVE)
for l in w.find_leaves(p, blocks.BREAK_DISTANCE): for l in w.find_leaves(pos, blocks.BREAK_DISTANCE):
self.leaves.append(l) self.leaves.append(l)
self.state = self.break_leaves self.state = self.break_leaves