83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
import unittest
|
|
from munch import Munch
|
|
|
|
from mosfet.commands import Commands
|
|
from mosfet.info import blocks, items
|
|
from mosfet.job import JobStates
|
|
from mosfet.world import World
|
|
|
|
|
|
class FakeChunks:
|
|
def __init__(self, states):
|
|
self.states = states
|
|
self.index = {}
|
|
|
|
def get_block_at(self, x, y, z):
|
|
return self.states.get((x, y, z), blocks.AIR)
|
|
|
|
|
|
class GatherWoodPortTests(unittest.TestCase):
|
|
def test_log_states_are_indexed_for_modern_chunk_search(self):
|
|
self.assertTrue(blocks.LOG_IDS)
|
|
self.assertTrue(blocks.LOG_IDS.issubset(blocks.INDEXED_IDS))
|
|
|
|
def test_tree_search_finds_indexed_26_3_log_states(self):
|
|
oak_log = blocks.MCD_BLOCKS['oak_log']['minStateId']
|
|
oak_leaves = blocks.MCD_BLOCKS['oak_leaves']['minStateId']
|
|
stone = blocks.MCD_BLOCKS['stone']['minStateId']
|
|
states = {
|
|
(0, 63, 0): stone,
|
|
(0, 64, 0): oak_log,
|
|
(0, 65, 0): oak_log,
|
|
(0, 66, 0): oak_log,
|
|
(1, 66, 0): oak_leaves,
|
|
}
|
|
chunks = FakeChunks(states)
|
|
chunks.index[oak_log] = {
|
|
(0, 64, 0), (0, 65, 0), (0, 66, 0),
|
|
}
|
|
world = World(Munch(chunks=chunks))
|
|
self.assertEqual(list(world.find_trees((0, 64, 0), 10)),
|
|
[(0, 64, 0)])
|
|
|
|
def test_gather_wood_job_keeps_existing_machine_sequence(self):
|
|
job = JobStates(Munch())
|
|
self.assertIsNotNone(job.gather_wood_states)
|
|
self.assertEqual(job.gather_wood(), [
|
|
job.gather_wood_states,
|
|
job.sleep_with_bed_states,
|
|
job.eat_food_states,
|
|
job.cache_items_states,
|
|
])
|
|
job.gather_wood_states.state = job.gather_wood_states.find_new_tree
|
|
job.stop()
|
|
self.assertIs(job.gather_wood_states.state.__func__,
|
|
job.gather_wood_states.idle.__func__)
|
|
|
|
def test_gather_wood_command_is_enabled_but_farm_wood_is_not(self):
|
|
class FakeChat:
|
|
def __init__(self):
|
|
self.sent = []
|
|
|
|
def set_handler(self, handler):
|
|
self.handler = handler
|
|
|
|
def send(self, message):
|
|
self.sent.append(message)
|
|
|
|
job = JobStates(Munch())
|
|
chat = FakeChat()
|
|
g = Munch(name='mosfet1', chat=chat, job=job,
|
|
inv={0: Munch(item_id=next(iter(items.BED_IDS)))})
|
|
Commands(g).handle_chat(('CHAT', 'tester', 'tester: 1gather wood'))
|
|
self.assertEqual(chat.sent, ['ok'])
|
|
self.assertIs(job.state.__func__, job.gather_wood.__func__)
|
|
|
|
chat.sent.clear()
|
|
Commands(g).handle_chat(('CHAT', 'tester', 'tester: 1farm wood'))
|
|
self.assertEqual(chat.sent, ['not migrated to Minecraft 26.3 yet'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|