Confirm crop seed selection before planting
This commit is contained in:
1 parent
1a7bdb2be4
commit
46b0657bcf
4 files changed
+105
-21
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import io
|
||||
import time
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from unittest.mock import patch
|
||||
@@ -7,6 +8,7 @@ from munch import Munch
|
||||
|
||||
from mosfet.info import blocks, items
|
||||
from mosfet.jobs.gather_crop import GatherCropStates
|
||||
from mosfet.protocol.types import Slot
|
||||
|
||||
|
||||
class CropBatchTests(unittest.TestCase):
|
||||
@@ -116,32 +118,52 @@ class CropBatchTests(unittest.TestCase):
|
||||
self.assertEqual(game.break_calls, [])
|
||||
self.assertIs(state.state.__func__, state.find_new_crop.__func__)
|
||||
|
||||
def test_already_held_seed_skips_selection_and_places_from_held_hand(self):
|
||||
def test_seed_selection_forces_slot_and_checks_inventory_hand(self):
|
||||
position = (1, 64, 1)
|
||||
seed = items.WHEAT_SEEDS_ID
|
||||
|
||||
class FakeGame:
|
||||
def __init__(self):
|
||||
self.placements = []
|
||||
self.selections = []
|
||||
|
||||
def select_item(self, _item_ids):
|
||||
raise AssertionError('already-held seed should not be selected')
|
||||
def select_item(self, item_ids, force=False):
|
||||
self.selections.append((set(item_ids), force))
|
||||
return True
|
||||
|
||||
def place_block(self, location, face, hand=0):
|
||||
self.placements.append((location, face, hand))
|
||||
|
||||
game = FakeGame()
|
||||
state = GatherCropStates(Munch(
|
||||
game=game, holding=seed, holding_hand=1))
|
||||
game=game, holding=seed, holding_hand=1,
|
||||
inv={45: Slot(True, seed, 1)}))
|
||||
state.crop = position
|
||||
state.type_id = blocks.MCD_BLOCKS['wheat']['minStateId']
|
||||
|
||||
state.select_seed()
|
||||
|
||||
self.assertEqual(game.selections, [({seed}, True)])
|
||||
self.assertIs(state.state.__func__, state.wait_select.__func__)
|
||||
state.wait_select()
|
||||
self.assertIs(state.state.__func__, state.place_crop.__func__)
|
||||
state.place_crop()
|
||||
self.assertEqual(game.placements, [((1, 63, 1), 1, 1)])
|
||||
|
||||
def test_wait_select_rejects_stale_local_held_item(self):
|
||||
seed = items.WHEAT_SEEDS_ID
|
||||
other_item = next(iter(items.AXE_IDS))
|
||||
state = GatherCropStates(Munch(
|
||||
holding=seed, holding_hand=0, holding_slot=0,
|
||||
inv={36: Slot(True, other_item, 1)}))
|
||||
state.target_seed = seed
|
||||
state.seed_deadline = time.monotonic() + 5.0
|
||||
state.state = state.wait_select
|
||||
|
||||
state.wait_select()
|
||||
|
||||
self.assertIs(state.state.__func__, state.wait_select.__func__)
|
||||
|
||||
def test_seed_selection_uses_crop_species_for_any_age_state(self):
|
||||
unripe_wheat = blocks.MCD_BLOCKS['wheat']['minStateId']
|
||||
|
||||
@@ -149,8 +171,9 @@ class CropBatchTests(unittest.TestCase):
|
||||
def __init__(self):
|
||||
self.selected = None
|
||||
|
||||
def select_item(self, item_ids):
|
||||
def select_item(self, item_ids, force=False):
|
||||
self.selected = set(item_ids)
|
||||
self.force = force
|
||||
return True
|
||||
|
||||
game = FakeGame()
|
||||
|
||||
Reference in new issue
Block a user