Program the bot to crawl, fix wood farming bugs
This commit is contained in:
parent
e642e426b9
commit
2fa3044acb
3
bot.py
3
bot.py
|
@ -142,9 +142,11 @@ def tick(global_state):
|
|||
g.y_v += g.y_a * utils.TICK
|
||||
|
||||
block_below = g.chunks.get_block_at(floor(p.x), ceil(p.y-1), floor(p.z))
|
||||
block_above = g.chunks.get_block_at(floor(p.x), ceil(p.y+1), floor(p.z))
|
||||
in_void = p.y < 0
|
||||
in_air = block_below in blocks.NON_SOLID_IDS or in_void
|
||||
in_water = block_below in blocks.WATER_IDS
|
||||
g.crawling = block_above not in blocks.NON_SOLID_IDS
|
||||
|
||||
if in_air:
|
||||
g.y_a = -36.0
|
||||
|
@ -204,6 +206,7 @@ def init(global_state):
|
|||
g.y_a = 0
|
||||
g.yaw = 360
|
||||
g.pitch = 0
|
||||
g.crawling = False
|
||||
|
||||
g.breaking = None
|
||||
g.break_time = 0
|
||||
|
|
16
game.py
16
game.py
|
@ -117,9 +117,7 @@ class MCWorld:
|
|||
log_count += 1
|
||||
|
||||
for offset in path.CHECK_DIRECTIONS:
|
||||
if self.block_at(*utils.padd(log, offset)) not in blocks.LEAF_IDS:
|
||||
break
|
||||
else: # for:
|
||||
if self.block_at(*utils.padd(log, offset)) in blocks.LEAF_IDS:
|
||||
good_leaves = True
|
||||
|
||||
# make sure it's a good tree
|
||||
|
@ -132,7 +130,7 @@ class MCWorld:
|
|||
|
||||
def find_tree_openings(self, tree):
|
||||
# returns coords in a cardinal direction where we can stand by tree
|
||||
maze_solver = path.Pathfinder(self.g.chunks)
|
||||
maze_solver = path.Pathfinder(self.g)
|
||||
result = []
|
||||
|
||||
# TODO: make sure only non-solid and leaves between
|
||||
|
@ -146,7 +144,7 @@ class MCWorld:
|
|||
return result
|
||||
|
||||
def path_to_place(self, start, place):
|
||||
maze_solver = path.Pathfinder(self.g.chunks)
|
||||
maze_solver = path.Pathfinder(self.g)
|
||||
|
||||
try:
|
||||
s = maze_solver.astar(start, place)
|
||||
|
@ -155,8 +153,8 @@ class MCWorld:
|
|||
return None
|
||||
|
||||
def find_bed_areas(self, center, distance):
|
||||
bed_clearance = 25 # 5x5 area
|
||||
clear_distance = 3
|
||||
bed_clearance = 9 # 5x5 area
|
||||
clear_distance = 2
|
||||
|
||||
for a in self.find_blocks_3d(center, [0], distance, 50):
|
||||
# check for air around the area
|
||||
|
@ -324,7 +322,7 @@ class MCWorld:
|
|||
|
||||
def find_villager_openings(self, villager):
|
||||
# returns coords in a cardinal direction where we can stand by a villager
|
||||
maze_solver = path.Pathfinder(self.g.chunks)
|
||||
maze_solver = path.Pathfinder(self.g)
|
||||
result = []
|
||||
|
||||
for distance in range(3):
|
||||
|
@ -398,7 +396,7 @@ class Game:
|
|||
print('new waypoint:', self.g.goal)
|
||||
|
||||
start = time.time()
|
||||
solution = path.Pathfinder(self.g.chunks).astar(utils.pint(self.g.pos), utils.pint(self.g.goal))
|
||||
solution = path.Pathfinder(self.g).astar(utils.pint(self.g.pos), utils.pint(self.g.goal))
|
||||
if solution:
|
||||
solution = list(solution)
|
||||
self.g.path = solution
|
||||
|
|
27
path.py
27
path.py
|
@ -121,8 +121,9 @@ HALF_PARKOUR = {
|
|||
BLOCK_CACHE_SIZE = 2**14
|
||||
|
||||
class Pathfinder(AStar):
|
||||
def __init__(self, chunks):
|
||||
self.chunks = chunks
|
||||
def __init__(self, g):
|
||||
self.g = g
|
||||
self.chunks = g.chunks
|
||||
self.start_time = time.time()
|
||||
|
||||
@functools.lru_cache(maxsize=BLOCK_CACHE_SIZE)
|
||||
|
@ -133,6 +134,23 @@ class Pathfinder(AStar):
|
|||
def bavoid(self, p):
|
||||
return self.chunks.get_block_at(*p) in blocks.AVOID_IDS or p[1] < 0
|
||||
|
||||
def check_traverse_crawling(self, node, offset):
|
||||
dest = utils.padd(node, offset)
|
||||
|
||||
if not self.bair(dest):
|
||||
return False
|
||||
|
||||
if self.bair(utils.padd(dest, BLOCK_BELOW)):
|
||||
return False
|
||||
|
||||
if self.bavoid(dest):
|
||||
return False
|
||||
|
||||
if self.bavoid(utils.padd(dest, BLOCK_BELOW)):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def check_traverse(self, node, offset):
|
||||
dest = utils.padd(node, offset)
|
||||
|
||||
|
@ -254,6 +272,11 @@ class Pathfinder(AStar):
|
|||
def neighbors(self, node):
|
||||
results = []
|
||||
|
||||
if self.g.crawling:
|
||||
for offset in TRAVERSE:
|
||||
if self.check_traverse_crawling(node, offset):
|
||||
results.append(utils.padd(node, offset))
|
||||
else:
|
||||
for offset in TRAVERSE:
|
||||
if self.check_traverse(node, offset):
|
||||
results.append(utils.padd(node, offset))
|
||||
|
|
Loading…
Reference in New Issue
Block a user