Compare commits

...

3 Commits

5 changed files with 74 additions and 47 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')

67
jobs.py
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
@ -1121,7 +1122,7 @@ class FillBlocksStates:
return return
if self.last_block: if self.last_block:
self.state = self.select_block self.state = self.select_item
else: else:
self.state = self.find_last_block self.state = self.find_last_block
@ -1131,28 +1132,29 @@ class FillBlocksStates:
print('Finding last block') print('Finding last block')
b1, b2 = utils.pboundingbox(f.coord1, f.coord2) b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
box = utils.psub(b2, b1)
xz_distance = hypot(box[0]+1, box[2]+1)
y_start = f.coord1[1] y_start = f.coord1[1]
y_end = f.coord2[1] y_end = f.coord2[1]
distance = utils.phyp(f.coord1, f.coord2)
self.next_block = f.coord1 for y in range(y_start, y_end+1):
for offset in utils.search_2d(xz_distance):
check = utils.padd(f.coord1, offset)
check = (check[0], y, check[2])
for offset in utils.search_3d(distance): # ensure block is within fill area
check = utils.padd(f.coord1, offset) if check[0] < b1[0] or check[0] > b2[0]:
continue
if check[2] < b1[2] or check[2] > b2[2]:
continue
# ensure block is within fill area if w.block_at(*check) == blocks.AIR:
if check[0] < b1[0] or check[0] > b2[0]: self.state = self.select_item
continue return
if check[2] < b1[2] or check[2] > b2[2]:
continue
if w.block_at(*check) == blocks.AIR: self.last_block = check
self.state = self.select_block
return
self.last_block = check def select_item(self):
def select_block(self):
f = self.g.filling f = self.g.filling
name = blocks.BLOCKS[f.block] name = blocks.BLOCKS[f.block]
item = items.ITEMS['minecraft:'+name]['protocol_id'] item = items.ITEMS['minecraft:'+name]['protocol_id']
@ -1175,21 +1177,14 @@ class FillBlocksStates:
y_start = f.coord1[1] y_start = f.coord1[1]
y_end = f.coord2[1] y_end = f.coord2[1]
print('distance', xz_distance)
for y in range(y_start, y_end+1): for y in range(y_start, y_end+1):
for i in count(): if y not in self.iterators:
offset = utils.spiral(i) self.iterators[y] = utils.search_2d(xz_distance)
check = utils.padd(self.last_block, offset)
for offset in self.iterators[y]:
check = utils.padd(f.coord1, offset)
check = (check[0], y, check[2]) check = (check[0], y, check[2])
print('layer', y)
print('offset', offset)
print('hypot', hypot(offset[0], offset[2]))
if hypot(offset[0], offset[2]) > xz_distance:
break
# ensure block is within fill area # ensure block is within fill area
if check[0] < b1[0] or check[0] > b2[0]: if check[0] < b1[0] or check[0] > b2[0]:
continue continue
@ -1245,23 +1240,20 @@ class FillBlocksStates:
self.g.game.place_block(self.next_block, BlockFace.TOP) self.g.game.place_block(self.next_block, BlockFace.TOP)
self.g.look_at = self.next_block self.g.look_at = self.next_block
self.wait_time = 0.25 self.wait_time = 0.25
self.state = self.wait_for_block self.state = self.wait_for_block
def wait_for_block(self): def wait_for_block(self):
if self.wait_time > 0:
self.wait_time -= utils.TICK
else:
self.state = self.check_block
def check_block(self):
w = self.g.world w = self.g.world
if w.block_at(*self.next_block) != blocks.AIR: if w.block_at(*self.next_block) != blocks.AIR:
self.last_block = self.next_block self.last_block = self.next_block
self.state = self.check_obstruction
elif self.wait_time > 0:
self.wait_time -= utils.TICK
else: else:
print('Block didnt appear') print('Block didnt appear')
self.state = self.check_obstruction
self.state = self.check_obstruction
def check_obstruction(self): def check_obstruction(self):
p = utils.pint(self.g.pos) p = utils.pint(self.g.pos)
@ -1303,6 +1295,7 @@ class FillBlocksStates:
self.g = global_state self.g = global_state
self.state = self.idle self.state = self.idle
self.iterators = {}
self.wait_time = 0 self.wait_time = 0
self.last_block = None self.last_block = None
self.next_block = None self.next_block = None

View File

@ -6,19 +6,19 @@ def get_packets(old_get_packets):
print('Monkey-patch worked.') print('Monkey-patch worked.')
mc_packets = func(context) mc_packets = func(context)
# add any custom packets here # add any custom CLIENTBOUND packets here
mc_packets.add(packets.ChunkDataPacket) mc_packets.add(packets.ChunkDataPacket)
mc_packets.add(packets.AcknowledgePlayerDiggingPacket) mc_packets.add(packets.AcknowledgePlayerDiggingPacket)
mc_packets.add(packets.BlockBreakAnimationPacket) mc_packets.add(packets.BlockBreakAnimationPacket)
mc_packets.add(packets.SetSlotPacket) mc_packets.add(packets.SetSlotPacket)
mc_packets.add(packets.PlayerDiggingPacket) #mc_packets.add(packets.PlayerDiggingPacket)
mc_packets.add(packets.PickItemPacket) #mc_packets.add(packets.PickItemPacket)
mc_packets.add(packets.HeldItemChangePacket) #mc_packets.add(packets.HeldItemChangePacket)
mc_packets.add(packets.OpenWindowPacket) mc_packets.add(packets.OpenWindowPacket)
mc_packets.add(packets.CloseWindowPacket) #mc_packets.add(packets.CloseWindowPacket)
mc_packets.add(packets.ClickWindowPacket) #mc_packets.add(packets.ClickWindowPacket)
mc_packets.add(packets.ClientWindowConfirmationPacket) mc_packets.add(packets.ClientWindowConfirmationPacket)
mc_packets.add(packets.ServerWindowConfirmationPacket) #mc_packets.add(packets.ServerWindowConfirmationPacket)
mc_packets.add(packets.EntityMetadataPacket) mc_packets.add(packets.EntityMetadataPacket)
mc_packets.add(packets.SpawnLivingEntityPacket) mc_packets.add(packets.SpawnLivingEntityPacket)
mc_packets.add(packets.EntityPositionRotationPacket) mc_packets.add(packets.EntityPositionRotationPacket)
@ -26,6 +26,7 @@ def get_packets(old_get_packets):
#mc_packets.add(packets.EntityActionPacket) #mc_packets.add(packets.EntityActionPacket)
mc_packets.add(packets.SpawnPlayerPacket) mc_packets.add(packets.SpawnPlayerPacket)
return mc_packets return mc_packets
return lambda x: wrapper(old_get_packets, x) return lambda x: wrapper(old_get_packets, x)

View File

@ -107,6 +107,33 @@ def break_time(block_id, held_item=0, in_water=False, on_ground=True, enchantmen
return time return time
def search_2d(distance=0):
def get_neighbors(x,y,z):
return [
(x+1, y+0, z+0),
#(x+1, y+0, z+1),
(x+0, y+0, z-1),
#(x-1, y+0, z+1),
(x-1, y+0, z+0),
#(x-1, y+0, z-1),
(x+0, y+0, z+1),
#(x+1, y+0, z-1),
]
to_visit = collections.deque([(0, 0, 0)])
visited = set()
while to_visit:
cur = to_visit.pop()
if cur in visited:
continue
if distance and hypot(*cur) > distance:
continue
for neighbor in get_neighbors(*cur):
to_visit.appendleft(neighbor)
visited.add(cur)
yield cur
def search_3d(distance=0, y_limit=0): def search_3d(distance=0, y_limit=0):
def get_neighbors(x,y,z): def get_neighbors(x,y,z):
return [ return [