diff --git a/mosfet/jobs/gather_wart.py b/mosfet/jobs/gather_wart.py index db82122..d26d95f 100644 --- a/mosfet/jobs/gather_wart.py +++ b/mosfet/jobs/gather_wart.py @@ -9,6 +9,7 @@ from mosfet.info import items class GatherWartStates: + WARTS_PER_BATCH = 16 BREAK_TIMEOUT = 5.0 ITEM_TIMEOUT = 8.0 PLACE_TIMEOUT = 3.0 @@ -118,8 +119,15 @@ class GatherWartStates: def wait_place(self): current = self.g.world.block_at(*self.wart) if current in blocks.NETHERWART_IDS and current != self.type_id: + self.completed_warts += 1 print('Nether wart replanted at', self.wart) - self.state = self.cleanup + if self.completed_warts >= self.WARTS_PER_BATCH: + print('Completed {} nether wart harvests; running maintenance'.format( + self.completed_warts)) + self.completed_warts = 0 + self.state = self.cleanup + else: + self.state = self.find_new_wart elif time.monotonic() > self.place_deadline: print('Nether wart did not replant; blacklisting', self.wart) self._blacklist_wart() @@ -138,6 +146,7 @@ class GatherWartStates: self.wart = None self.type_id = None self.bad_warts = [] + self.completed_warts = 0 self.break_deadline = None self.item_deadline = None self.place_deadline = None diff --git a/tests/test_gather_wart.py b/tests/test_gather_wart.py index d0a8de4..b87d0f7 100644 --- a/tests/test_gather_wart.py +++ b/tests/test_gather_wart.py @@ -118,7 +118,8 @@ class GatherWartTests(unittest.TestCase): self.assertEqual(game.place_calls, [(support, 1)]) world.state_id = unripe state.wait_place() - self.assertIs(state.state.__func__, state.cleanup.__func__) + self.assertEqual(state.completed_warts, 1) + self.assertIs(state.state.__func__, state.find_new_wart.__func__) def test_navigation_looks_at_the_wart_target(self): position = (5, 64, 8) @@ -137,6 +138,29 @@ class GatherWartTests(unittest.TestCase): self.assertEqual(g.look_at, position) self.assertEqual(g.path[-1], position) + def test_gather_wart_finishes_after_sixteen_successful_replants(self): + mature = max(blocks.NETHERWART_IDS) + unripe = min(blocks.NETHERWART_IDS) + + class FakeWorld: + @staticmethod + def block_at(*_position): + return unripe + + state = GatherWartStates(Munch(world=FakeWorld())) + state.wart = (5, 64, 8) + state.type_id = mature + + for completed in range(1, state.WARTS_PER_BATCH): + state.wait_place() + self.assertEqual(state.completed_warts, completed) + self.assertIs(state.state.__func__, state.find_new_wart.__func__) + state.state = state.wait_place + + state.wait_place() + self.assertEqual(state.completed_warts, 0) + self.assertIs(state.state.__func__, state.cleanup.__func__) + def test_unreachable_wart_is_blacklisted_without_undefined_variable(self): position = (5, 64, 8)