Cache active crop section and streamline harvesting

This commit is contained in:
Tanner committed 2026-11-09 17:37:32 +00:00
1 parent 1b4f32060d
commit 281e90a59f
6 files changed
+356 -22

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import unittest
from munch import Munch
from mosfet.info import blocks
from mosfet.world import World
class IndexedSearchTests(unittest.TestCase):
def test_index_deduplication_is_linear_and_sort_is_optional(self):
far = (10, 64, 0)
near = (1, 64, 0)
class FakeChunks:
def __init__(self):
self.reads = {}
@staticmethod
def indexed_positions(_block_ids):
return [far, near, far]
def get_block_at(self, *position):
position = tuple(position)
self.reads[position] = self.reads.get(position, 0) + 1
return blocks.STONE
chunks = FakeChunks()
world = World(Munch(chunks=chunks))
self.assertEqual(world.find_blocks_indexed(
(0, 64, 0), {blocks.STONE}, 50), [near, far])
self.assertEqual(chunks.reads, {far: 1, near: 1})
chunks.reads.clear()
self.assertEqual(world.find_blocks_indexed(
(0, 64, 0), {blocks.STONE}, 50, sort=False), [far, near])
self.assertEqual(chunks.reads, {far: 1, near: 1})
if __name__ == '__main__':
unittest.main()