Guard crop harvests against stale growth state
This commit is contained in:
1 parent
67381655a2
commit
b2bf939c74
2 files changed
+107
-12
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.info import blocks
|
||||
from mosfet.info import blocks, items
|
||||
from mosfet.jobs.gather_crop import GatherCropStates
|
||||
|
||||
|
||||
@@ -23,6 +23,78 @@ class CropBatchTests(unittest.TestCase):
|
||||
self.assertEqual(g.look_at, crop)
|
||||
self.assertEqual(g.path[-1], crop)
|
||||
|
||||
def test_selection_rechecks_maturity_after_candidate_search(self):
|
||||
position = (1, 64, 1)
|
||||
unripe = blocks.MCD_BLOCKS['wheat']['minStateId']
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def find_blocks_indexed(_center, block_ids, _distance):
|
||||
return [position]
|
||||
|
||||
@staticmethod
|
||||
def filter_work_positions(positions):
|
||||
return list(positions)
|
||||
|
||||
@staticmethod
|
||||
def block_at(*_position):
|
||||
return unripe
|
||||
|
||||
state = GatherCropStates(Munch(
|
||||
world=FakeWorld(), pos=(0, 64, 0)))
|
||||
state.find_new_crop()
|
||||
|
||||
self.assertIs(state.state.__func__, state.find_new_crop.__func__)
|
||||
self.assertIsNone(state.crop)
|
||||
|
||||
def test_break_skips_crop_that_became_unripe_on_the_way(self):
|
||||
position = (1, 64, 1)
|
||||
unripe = blocks.MCD_BLOCKS['wheat']['minStateId']
|
||||
mature = blocks.MATURE_WHEAT_ID
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def block_at(*_position):
|
||||
return unripe
|
||||
|
||||
class FakeGame:
|
||||
def __init__(self):
|
||||
self.break_calls = []
|
||||
|
||||
def break_block(self, target):
|
||||
self.break_calls.append(target)
|
||||
return True
|
||||
|
||||
game = FakeGame()
|
||||
state = GatherCropStates(Munch(world=FakeWorld(), game=game))
|
||||
state.crop = position
|
||||
state.type_id = mature
|
||||
|
||||
state.break_crop()
|
||||
|
||||
self.assertEqual(game.break_calls, [])
|
||||
self.assertIs(state.state.__func__, state.find_new_crop.__func__)
|
||||
|
||||
def test_seed_selection_uses_crop_species_for_any_age_state(self):
|
||||
unripe_wheat = blocks.MCD_BLOCKS['wheat']['minStateId']
|
||||
|
||||
class FakeGame:
|
||||
def __init__(self):
|
||||
self.selected = None
|
||||
|
||||
def select_item(self, item_ids):
|
||||
self.selected = set(item_ids)
|
||||
return True
|
||||
|
||||
game = FakeGame()
|
||||
state = GatherCropStates(Munch(game=game))
|
||||
state.type_id = unripe_wheat
|
||||
|
||||
state.select_seed()
|
||||
|
||||
self.assertEqual(state.target_seed, items.WHEAT_SEEDS_ID)
|
||||
self.assertEqual(game.selected, {items.WHEAT_SEEDS_ID})
|
||||
|
||||
def test_gather_crop_finishes_after_sixteen_successful_replants(self):
|
||||
unripe_wheat = blocks.MCD_BLOCKS['wheat']['minStateId']
|
||||
mature_wheat = blocks.MATURE_WHEAT_ID
|
||||
|
||||
Reference in new issue
Block a user