Improve searching for crops
This commit is contained in:
+22
-3
@@ -1,3 +1,4 @@
|
||||
import collections
|
||||
import re
|
||||
import time
|
||||
import random
|
||||
@@ -24,9 +25,27 @@ class World:
|
||||
return False
|
||||
return True
|
||||
|
||||
def find_blocks_3d(self, center, block_ids, distance=0, y_limit=0):
|
||||
for offset in utils.search_3d(distance, y_limit):
|
||||
check = utils.padd(center, offset)
|
||||
def find_blocks_3d(self, center, block_ids, distance=0, y_limit=0, thru_air=False):
|
||||
to_visit = collections.deque([(0, 0, 0)])
|
||||
visited = set()
|
||||
|
||||
while to_visit:
|
||||
cur = to_visit.pop()
|
||||
if cur in visited:
|
||||
continue
|
||||
if y_limit and abs(cur[1]) > y_limit:
|
||||
continue
|
||||
if distance and hypot(*cur) > distance:
|
||||
continue
|
||||
|
||||
check = utils.padd(center, cur)
|
||||
|
||||
if not thru_air or self.block_at(*check) in blocks.NON_SOLID_IDS:
|
||||
for neighbor in utils.get_neighbors_3d(*cur):
|
||||
to_visit.appendleft(neighbor)
|
||||
|
||||
visited.add(cur)
|
||||
|
||||
if self.block_at(*check) in block_ids:
|
||||
yield check
|
||||
|
||||
|
||||
Reference in New Issue
Block a user