140 lines
5.4 KiB
Python
140 lines
5.4 KiB
Python
import unittest
|
|
from munch import Munch
|
|
|
|
from mosfet.info import blocks, items
|
|
from mosfet.world import World
|
|
|
|
|
|
class StorageLabelTests(unittest.TestCase):
|
|
def test_labels_resolve_to_item_categories(self):
|
|
seeds = items.storage_item_ids_for_label('Seeds')
|
|
wheat = items.storage_item_ids_for_label('Wheat')
|
|
logs = items.storage_item_ids_for_label('Logs')
|
|
sticks = items.storage_item_ids_for_label('Sticks')
|
|
saplings = items.storage_item_ids_for_label('Saplings')
|
|
sand = items.storage_item_ids_for_label('Sand')
|
|
red_sand = items.storage_item_ids_for_label('Red Sand')
|
|
|
|
self.assertEqual(sand, {items.SAND_ID})
|
|
self.assertEqual(red_sand, {items.RED_SAND_ID})
|
|
self.assertNotEqual(sand, red_sand)
|
|
self.assertEqual(seeds, items.get_set({
|
|
'beetroot_seeds', 'melon_seeds', 'pitcher_pod', 'pumpkin_seeds',
|
|
'torchflower_seeds', 'wheat_seeds',
|
|
}))
|
|
self.assertEqual(items.storage_item_ids_for_label('Dirt'), set())
|
|
self.assertEqual(items.storage_item_ids_for_label('Stone'), set())
|
|
self.assertIn(items.WHEAT_SEEDS_ID, seeds)
|
|
self.assertNotIn(items.CARROT_ID, seeds)
|
|
self.assertNotIn(items.BEETROOT_ID, seeds)
|
|
self.assertEqual(wheat, {items.WHEAT_ID})
|
|
self.assertNotIn(items.WHEAT_SEEDS_ID, wheat)
|
|
self.assertEqual(sticks, {items.STICK_ID})
|
|
self.assertEqual(items.storage_item_ids_for_label('Stick'), sticks)
|
|
self.assertEqual(logs, items.LOG_IDS)
|
|
self.assertTrue(items.get_set({
|
|
'oak_log', 'stripped_oak_log', 'oak_wood',
|
|
'stripped_oak_wood', 'crimson_stem',
|
|
'stripped_crimson_stem', 'warped_hyphae',
|
|
'stripped_warped_hyphae', 'mushroom_stem',
|
|
}) <= logs)
|
|
self.assertNotIn(items.WHEAT_ID, logs)
|
|
self.assertEqual(saplings, items.SAPLING_IDS)
|
|
self.assertTrue(items.get_set({
|
|
'oak_sapling', 'pale_oak_sapling', 'mangrove_propagule',
|
|
}) <= saplings)
|
|
self.assertFalse(saplings & items.LOG_IDS)
|
|
|
|
def test_sign_label_associates_with_adjacent_double_chest(self):
|
|
sign_pos = (0, 64, 0)
|
|
left_chest = (0, 64, 1)
|
|
right_chest = (1, 64, 1)
|
|
blocks_by_pos = {left_chest: 5552, right_chest: 5560}
|
|
chunks = Munch(
|
|
block_entities={sign_pos: {
|
|
'type': 7,
|
|
'data': {'front_text': {'messages': [
|
|
'Seeds', '', '', '',
|
|
]}},
|
|
}},
|
|
index={},
|
|
get_block_at=lambda *pos: blocks_by_pos.get(tuple(pos)),
|
|
)
|
|
chests = World(Munch(chunks=chunks)).find_labeled_chests(
|
|
sign_pos, 10)
|
|
|
|
self.assertEqual(len(chests), 1)
|
|
self.assertEqual(chests[0]['positions'], (left_chest, right_chest))
|
|
self.assertIn(items.WHEAT_SEEDS_ID, chests[0]['item_ids'])
|
|
self.assertEqual(chests[0]['labels'], {'Seeds'})
|
|
|
|
def test_general_cache_sign_matches_bot_group_and_prefers_side_chest(self):
|
|
sign_pos = (0, 64, 0)
|
|
side_chest = (1, 64, 0)
|
|
chest_below = (0, 63, 0)
|
|
sign_state = blocks.MCD_BLOCKS['oak_wall_sign']['minStateId']
|
|
chest_state = next(
|
|
state for state in blocks.CHEST_IDS
|
|
if blocks.PROPS[state].get('type') == 'single')
|
|
blocks_by_pos = {
|
|
sign_pos: sign_state,
|
|
side_chest: chest_state,
|
|
chest_below: chest_state,
|
|
}
|
|
chunks = Munch(
|
|
block_entities={sign_pos: {
|
|
'type': 7,
|
|
'data': {'front_text': {'messages': [
|
|
'mosfet cache', '', '', '',
|
|
]}},
|
|
}},
|
|
index={},
|
|
get_block_at=lambda *pos: blocks_by_pos.get(tuple(pos)),
|
|
)
|
|
world = World(Munch(chunks=chunks))
|
|
|
|
group_caches = world.find_cache_chests(sign_pos, 'mosfet2', 10)
|
|
|
|
self.assertEqual(len(group_caches), 1)
|
|
self.assertEqual(group_caches[0]['position'], side_chest)
|
|
self.assertEqual(group_caches[0]['positions'], (side_chest,))
|
|
self.assertEqual(world.find_cache_chests(
|
|
sign_pos, 'mosfet4', 10), [])
|
|
|
|
def test_side_chest_takes_priority_over_chest_below_sign(self):
|
|
sign_pos = (0, 64, 0)
|
|
side_chest = (1, 64, 0)
|
|
chest_below = (0, 63, 0)
|
|
sign_state = blocks.MCD_BLOCKS['oak_wall_sign']['minStateId']
|
|
chest_state = next(
|
|
state for state in blocks.CHEST_IDS
|
|
if blocks.PROPS[state].get('type') == 'single')
|
|
blocks_by_pos = {
|
|
sign_pos: sign_state,
|
|
side_chest: chest_state,
|
|
chest_below: chest_state,
|
|
}
|
|
chunks = Munch(
|
|
block_entities={sign_pos: {
|
|
'type': 7,
|
|
'data': {'front_text': {'messages': [
|
|
'Saplings', '', '', '',
|
|
]}},
|
|
}},
|
|
index={},
|
|
get_block_at=lambda *pos: blocks_by_pos.get(tuple(pos)),
|
|
)
|
|
|
|
chests = World(Munch(chunks=chunks)).find_labeled_chests(
|
|
sign_pos, 10)
|
|
|
|
self.assertEqual(len(chests), 1)
|
|
self.assertEqual(chests[0]['position'], side_chest)
|
|
self.assertEqual(chests[0]['positions'], (side_chest,))
|
|
self.assertNotIn(chest_below, chests[0]['positions'])
|
|
self.assertEqual(chests[0]['item_ids'], items.SAPLING_IDS)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|