Find trees using new 3D search
This commit is contained in:
@@ -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
|
||||
|
||||
trees.sort(key=lambda x: utils.phyp(center, x))
|
||||
return trees
|
||||
# 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)
|
||||
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user