Find trees using new 3D search

master
Tanner Collin 4 years ago
parent 90388cf110
commit ee2a1958f9
  1. 41
      game.py
  2. 30
      jobs.py
  3. 1
      main.py

@ -62,13 +62,8 @@ class MCWorld:
return result
def find_trees(self, center, distance):
logs = []
for i in range(5):
check = utils.padd(center, utils.alternate(i, 3))
logs.extend(self.find_blocks(check, distance, blocks.LOG_IDS, 50))
trees = []
for log in logs:
found_trees = []
for log in self.find_blocks_3d(center, blocks.LOG_IDS, distance, 15):
# crawl to the bottom log
while self.block_at(*utils.padd(log, path.BLOCK_BELOW)) in blocks.LOG_IDS:
log = utils.padd(log, path.BLOCK_BELOW)
@ -84,14 +79,18 @@ class MCWorld:
log_count += 1
# make sure it's a good tree
if self.block_at(*utils.padd(log, path.BLOCK_ABOVE)) in blocks.LEAF_IDS and log_count > 2:
# crawl back to the bottom log
while self.block_at(*utils.padd(log, path.BLOCK_BELOW)) in blocks.LOG_IDS:
log = utils.padd(log, path.BLOCK_BELOW)
trees.append(log)
if self.block_at(*utils.padd(log, path.BLOCK_ABOVE)) not in blocks.LEAF_IDS or log_count < 3:
continue
# crawl back to the bottom log
while self.block_at(*utils.padd(log, path.BLOCK_BELOW)) in blocks.LOG_IDS:
log = utils.padd(log, path.BLOCK_BELOW)
trees.sort(key=lambda x: utils.phyp(center, x))
return trees
if log in found_trees:
continue
found_trees.append(log)
yield log
def find_tree_openings(self, tree):
# returns coords in a cardinal direction where we can stand by tree
@ -261,6 +260,17 @@ class Game:
confirm_packet.teleport_id = packet.teleport_id
self.g.connection.write_packet(confirm_packet)
self.g.correction_count += 1
if self.g.get('path', None) and self.g.correction_count > 5:
self.g.correction_count = 0
dest = self.g.path[-1]
w = self.g.world
p = utils.pint(self.g.pos)
new_path = w.path_to_place(p, dest)
if new_path:
self.g.path = new_path
def handle_chat(self, message):
source, text = message
@ -679,3 +689,6 @@ class Game:
else:
self.g.dumping = None
if not len(self.g.path):
self.g.correction_count = 0

@ -140,18 +140,20 @@ class GatherWoodStates:
w = self.g.world
p = utils.pint(self.g.pos)
trees = w.find_trees(p, 100)
print('Found trees:', trees)
try:
while trees[0] in self.bad_trees:
trees.pop(0)
self.tree = trees[0]
except IndexError:
print('No good tress left, aborting.')
for tree in w.find_trees(p, 100):
print('Found tree:', tree)
if tree not in self.bad_trees:
break
else: # for
print('No good trees left, aborting.')
self.state = self.cleanup
return
self.tree = tree
self.state = self.find_openings
def find_openings(self):
w = self.g.world
self.openings = w.find_tree_openings(self.tree)
self.state = self.choose_opening
@ -251,7 +253,15 @@ class GatherWoodStates:
else:
self.g.chopped_tree = True
self.good_trees.append(self.tree)
self.state = self.check_pos
def check_pos(self):
# make sure we are at base of trunk
# doesn't always happen, for some reason
if utils.pint(self.g.pos) == self.tree:
self.state = self.cleanup
else:
self.state = self.find_openings
def cleanup(self):
self.g.look_at = None
@ -820,7 +830,7 @@ class GrabSaplingStates:
saplings = w.find_objects(items.SAPLING_IDS)
if not saplings:
print('No saplings objects found, aborting')
print('No sapling objects found, aborting')
self.state = self.cleanup
return

@ -22,6 +22,7 @@ g.inv = {}
g.objects = {}
g.window = None
g.job = None
g.correction_count = 0
@app.route('/')
def hello_world():

Loading…
Cancel
Save