Port nether wart farming to 26.3
This commit is contained in:
@@ -6,15 +6,20 @@ from mosfet.bot import FARMING_PITCH, pitch_lock_for_job, update_pitch
|
||||
|
||||
|
||||
class TestFarmingPitch(unittest.TestCase):
|
||||
def test_only_crop_farming_locks_pitch(self):
|
||||
def test_crop_and_wart_farming_lock_pitch(self):
|
||||
def farm_crop():
|
||||
pass
|
||||
|
||||
def farm_wart():
|
||||
pass
|
||||
|
||||
def sleep():
|
||||
pass
|
||||
|
||||
self.assertEqual(
|
||||
pitch_lock_for_job(Munch(state=farm_crop)), FARMING_PITCH)
|
||||
self.assertEqual(
|
||||
pitch_lock_for_job(Munch(state=farm_wart)), FARMING_PITCH)
|
||||
self.assertIsNone(pitch_lock_for_job(Munch(state=sleep)))
|
||||
self.assertIsNone(pitch_lock_for_job(None))
|
||||
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
import unittest
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.commands import Commands
|
||||
from mosfet.info import blocks, items
|
||||
from mosfet.job import JobStates
|
||||
from mosfet.jobs.gather_wart import GatherWartStates
|
||||
|
||||
|
||||
class GatherWartTests(unittest.TestCase):
|
||||
def test_nether_wart_states_are_indexed_for_patch_search(self):
|
||||
self.assertTrue(blocks.NETHERWART_IDS.issubset(blocks.INDEXED_IDS))
|
||||
|
||||
def test_farm_wart_command_is_enabled_and_keeps_job_sequence(self):
|
||||
old_wanted = items.WANTED_ITEMS
|
||||
job = JobStates(Munch())
|
||||
|
||||
class FakeChat:
|
||||
def __init__(self):
|
||||
self.sent = []
|
||||
|
||||
def set_handler(self, _handler):
|
||||
pass
|
||||
|
||||
def send(self, message):
|
||||
self.sent.append(message)
|
||||
|
||||
chat = FakeChat()
|
||||
g = Munch(name='mosfet1', chat=chat, job=job,
|
||||
inv={0: Munch(item_id=next(iter(items.BED_IDS)))})
|
||||
try:
|
||||
Commands(g).handle_chat(('CHAT', 'tester',
|
||||
'tester: 1farm wart'))
|
||||
self.assertEqual(chat.sent, ['ok'])
|
||||
self.assertIs(job.state.__func__, job.farm_wart.__func__)
|
||||
self.assertIs(job.farm_wart()[0], job.gather_wart_states)
|
||||
self.assertIn(items.NETHERWART_ID, items.WANTED_ITEMS)
|
||||
finally:
|
||||
items.WANTED_ITEMS = old_wanted
|
||||
|
||||
def test_finds_only_indexed_mature_wart_allowed_by_work_signs(self):
|
||||
position = (5, 64, 8)
|
||||
mature = max(blocks.NETHERWART_IDS)
|
||||
|
||||
class FakeWorld:
|
||||
def __init__(self):
|
||||
self.search = None
|
||||
self.filter_input = None
|
||||
|
||||
def find_blocks_indexed(self, center, block_ids, distance):
|
||||
self.search = (center, block_ids, distance)
|
||||
return [position]
|
||||
|
||||
def filter_work_positions(self, positions):
|
||||
self.filter_input = list(positions)
|
||||
return list(positions)
|
||||
|
||||
world = FakeWorld()
|
||||
state = GatherWartStates(Munch(world=world, pos=(1.5, 64, 1.5)))
|
||||
|
||||
state.find_new_wart()
|
||||
|
||||
self.assertEqual(world.search, ((1, 64, 1), {mature}, 50))
|
||||
self.assertEqual(world.filter_input, [position])
|
||||
self.assertEqual(state.wart, position)
|
||||
self.assertIs(state.state.__func__, state.nav_to_wart.__func__)
|
||||
|
||||
def test_harvests_confirms_replant_on_soul_sand_below_wart(self):
|
||||
position = (5, 64, 8)
|
||||
mature = max(blocks.NETHERWART_IDS)
|
||||
unripe = min(blocks.NETHERWART_IDS)
|
||||
|
||||
class FakeWorld:
|
||||
def __init__(self):
|
||||
self.state_id = mature
|
||||
|
||||
def block_at(self, *_position):
|
||||
return self.state_id
|
||||
|
||||
class FakeGame:
|
||||
def __init__(self, global_state):
|
||||
self.g = global_state
|
||||
self.break_calls = []
|
||||
self.place_calls = []
|
||||
|
||||
def break_block(self, target):
|
||||
self.break_calls.append(target)
|
||||
return True
|
||||
|
||||
def select_item(self, item_ids):
|
||||
self.g.holding = items.NETHERWART_ID
|
||||
return items.NETHERWART_ID in item_ids
|
||||
|
||||
def place_block(self, target, face):
|
||||
self.place_calls.append((target, face))
|
||||
|
||||
world = FakeWorld()
|
||||
g = Munch(world=world, pos=position, holding=0, look_at=None)
|
||||
game = FakeGame(g)
|
||||
g.game = game
|
||||
state = GatherWartStates(g)
|
||||
state.wart = position
|
||||
state.type_id = mature
|
||||
|
||||
state.break_wart()
|
||||
self.assertIs(state.state.__func__, state.wait_break.__func__)
|
||||
self.assertEqual(game.break_calls, [position])
|
||||
|
||||
world.state_id = blocks.AIR
|
||||
state.wait_break()
|
||||
self.assertIs(state.state.__func__, state.select_wart.__func__)
|
||||
state.select_wart()
|
||||
state.wait_select()
|
||||
self.assertIs(state.state.__func__, state.place_wart.__func__)
|
||||
|
||||
state.place_wart()
|
||||
support = (position[0], position[1] - 1, position[2])
|
||||
self.assertEqual(game.place_calls, [(support, 1)])
|
||||
world.state_id = unripe
|
||||
state.wait_place()
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_unreachable_wart_is_blacklisted_without_undefined_variable(self):
|
||||
position = (5, 64, 8)
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def path_to_place(_start, _target):
|
||||
return None
|
||||
|
||||
state = GatherWartStates(Munch(
|
||||
world=FakeWorld(), pos=(1, 64, 1), path=[]))
|
||||
state.wart = position
|
||||
|
||||
state.nav_to_wart()
|
||||
|
||||
self.assertIn(position, state.bad_warts)
|
||||
self.assertIs(state.state.__func__, state.find_new_wart.__func__)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user