Cache active crop section and streamline harvesting
This commit is contained in:
1 parent
1b4f32060d
commit
281e90a59f
6 files changed
+356
-22
No files matched your search
+9
-4
@@ -353,7 +353,7 @@ class World:
|
||||
if self.block_at(*check) in block_ids:
|
||||
yield check
|
||||
|
||||
def find_blocks_indexed(self, center, block_ids, distance=0):
|
||||
def find_blocks_indexed(self, center, block_ids, distance=0, sort=True):
|
||||
chunks = self.g.chunks
|
||||
if hasattr(chunks, 'indexed_positions'):
|
||||
index = chunks.indexed_positions(block_ids)
|
||||
@@ -363,15 +363,20 @@ class World:
|
||||
index.extend(chunks.index.get(bid, []))
|
||||
|
||||
result = []
|
||||
seen = set()
|
||||
for block in index:
|
||||
block = tuple(block)
|
||||
if block in seen:
|
||||
continue
|
||||
seen.add(block)
|
||||
if self.block_at(*block) not in block_ids:
|
||||
continue
|
||||
if distance and utils.phyp(center, block) > distance:
|
||||
continue
|
||||
if block not in result:
|
||||
result.append(block)
|
||||
result.append(block)
|
||||
|
||||
result.sort(key=lambda x: utils.phyp(center, x))
|
||||
if sort:
|
||||
result.sort(key=lambda x: utils.phyp(center, x))
|
||||
return result
|
||||
|
||||
def find_blocks(self, center, distance, block_ids, limit=0):
|
||||
|
||||
Reference in new issue
Block a user