78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
import unittest
|
|
from munch import Munch
|
|
|
|
from mosfet.info import blocks, items
|
|
from mosfet.jobs.cache_items import CacheItemsStates
|
|
from mosfet.world import World
|
|
|
|
|
|
class LabeledStorageTests(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')
|
|
|
|
self.assertEqual(seeds, items.get_set({
|
|
'beetroot', 'beetroot_seeds', 'carrot', 'melon_seeds',
|
|
'nether_wart', 'pitcher_pod', 'potato', '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.assertEqual(wheat, {items.WHEAT_ID})
|
|
self.assertNotIn(items.WHEAT_SEEDS_ID, wheat)
|
|
|
|
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_wheat_chest_does_not_cache_seeds(self):
|
|
wheat = Munch(present=True, item_id=items.WHEAT_ID, item_count=64)
|
|
seeds = Munch(present=True, item_id=items.WHEAT_SEEDS_ID, item_count=64)
|
|
clicks = []
|
|
|
|
class FakeGame:
|
|
@staticmethod
|
|
def count_window_slots():
|
|
return 0
|
|
|
|
@staticmethod
|
|
def click_window(*args):
|
|
clicks.append(args)
|
|
|
|
cache = CacheItemsStates(Munch(
|
|
inv={9: wheat, 10: seeds}, item_lock=False,
|
|
window=Munch(container_slots=27, contents={
|
|
**dict.fromkeys(range(27)), 27: wheat, 28: seeds,
|
|
}),
|
|
game=FakeGame(),
|
|
))
|
|
cache.is_labeled_container = True
|
|
cache.container_item_ids = items.storage_item_ids_for_label('Wheat')
|
|
cache.move_items()
|
|
|
|
self.assertEqual(clicks, [(27, 0, 1, wheat)])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|