146 lines
5.6 KiB
Python
146 lines
5.6 KiB
Python
import unittest
|
|
from munch import Munch
|
|
|
|
from mosfet.info import blocks, items
|
|
from mosfet.world import World
|
|
|
|
|
|
def wall_sign_state(facing):
|
|
name = 'oak_wall_sign'
|
|
data = blocks.MCD_BLOCKS[name]
|
|
return next(
|
|
state_id for state_id in range(data['minStateId'], data['maxStateId'] + 1)
|
|
if blocks.PROPS[state_id].get('facing') == facing and
|
|
blocks.PROPS[state_id].get('waterlogged') == 'false'
|
|
)
|
|
|
|
|
|
class FakeChunks:
|
|
def __init__(self, block_entities=None, states=None):
|
|
self.block_entities = block_entities or {}
|
|
self.states = states or {}
|
|
|
|
def get_block_at(self, *position):
|
|
return self.states.get(tuple(position), blocks.AIR)
|
|
|
|
|
|
class ThrowSignTests(unittest.TestCase):
|
|
def test_throw_directives_support_group_bot_and_item_categories(self):
|
|
group_sign = (0, 64, 0)
|
|
individual_sign = (4, 64, 0)
|
|
chunks = FakeChunks(
|
|
block_entities={
|
|
group_sign: {'data': {
|
|
'front_text': {'messages': [
|
|
'mosfet', 'throw seeds', '', '',
|
|
]},
|
|
'back_text': {'messages': [
|
|
'mosfet3 throw bread', '', '', '',
|
|
]},
|
|
}},
|
|
individual_sign: {'data': {'front_text': {'messages': [
|
|
'mosfet2 throw wheat_seeds', '', '', '',
|
|
]}}},
|
|
},
|
|
states={
|
|
group_sign: wall_sign_state('north'),
|
|
individual_sign: wall_sign_state('west'),
|
|
})
|
|
world = World(Munch(chunks=chunks))
|
|
|
|
bot2 = world.find_throw_signs((0, 64, 0), 'mosfet2', 10)
|
|
self.assertEqual(len(bot2), 2)
|
|
group = next(sign for sign in bot2 if sign['position'] == group_sign)
|
|
individual = next(sign for sign in bot2
|
|
if sign['position'] == individual_sign)
|
|
self.assertEqual(group['item_ids'],
|
|
items.storage_item_ids_for_label('seeds'))
|
|
self.assertNotIn(items.CARROT_ID, group['item_ids'])
|
|
self.assertNotIn(items.BEETROOT_ID, group['item_ids'])
|
|
self.assertEqual(individual['item_ids'],
|
|
{items.WHEAT_SEEDS_ID})
|
|
self.assertEqual(group['normal'], (0.0, 0.0, -1.0))
|
|
self.assertEqual(individual['normal'], (-1.0, 0.0, 0.0))
|
|
|
|
bot1 = world.find_throw_signs((0, 64, 0), 'mosfet1', 10)
|
|
self.assertEqual([sign['position'] for sign in bot1], [group_sign])
|
|
bot9 = world.find_throw_signs((0, 64, 0), 'mosfet9', 10)
|
|
self.assertEqual([sign['position'] for sign in bot9], [group_sign])
|
|
self.assertEqual(world.find_throw_signs(
|
|
(0, 64, 0), 'mosfet10', 10), [])
|
|
|
|
def test_throw_accepts_unqualified_items_and_species_log_labels(self):
|
|
single_item_sign = (0, 64, 0)
|
|
oak_family_sign = (4, 64, 0)
|
|
chunks = FakeChunks(
|
|
block_entities={
|
|
single_item_sign: {'data': {'front_text': {'messages': [
|
|
'mosfet1 throw oak_log', '', '', '',
|
|
]}}},
|
|
oak_family_sign: {'data': {'front_text': {'messages': [
|
|
'mosfet1 throw Oak Logs', '', '', '',
|
|
]}}},
|
|
},
|
|
states={
|
|
single_item_sign: wall_sign_state('north'),
|
|
oak_family_sign: wall_sign_state('north'),
|
|
})
|
|
world = World(Munch(chunks=chunks))
|
|
|
|
directives = world.find_throw_signs((0, 64, 0), 'mosfet1', 10)
|
|
exact = next(sign for sign in directives
|
|
if sign['position'] == single_item_sign)
|
|
family = next(sign for sign in directives
|
|
if sign['position'] == oak_family_sign)
|
|
|
|
self.assertEqual(exact['item_ids'], {items.get_id('oak_log')})
|
|
self.assertEqual(family['item_ids'], items.get_set({
|
|
'oak_log', 'stripped_oak_log', 'oak_wood', 'stripped_oak_wood',
|
|
}))
|
|
|
|
def test_back_text_uses_back_face_normal(self):
|
|
position = (0, 64, 0)
|
|
world = World(Munch(chunks=FakeChunks(
|
|
block_entities={position: {'data': {
|
|
'front_text': {'messages': ['front', '', '', '']},
|
|
'back_text': {'messages': [
|
|
'mosfet2 throw seeds', '', '', '',
|
|
]},
|
|
}}},
|
|
states={position: wall_sign_state('north')})))
|
|
|
|
directive = world.find_throw_signs(position, 'mosfet2', 3)[0]
|
|
|
|
self.assertEqual(directive['side'], 'back')
|
|
self.assertEqual(directive['normal'], (0.0, 0.0, 1.0))
|
|
|
|
def test_throw_openings_prefer_text_face_and_skip_chute_holes(self):
|
|
sign_pos = (0, 64, 0)
|
|
states = {sign_pos: wall_sign_state('north')}
|
|
for x in range(-4, 5):
|
|
for z in range(-4, 5):
|
|
states[(x, 63, z)] = blocks.STONE
|
|
# The closest point on the sign's text-facing side is a drop chute.
|
|
states[(0, 63, -1)] = blocks.AIR
|
|
directive = {
|
|
'position': sign_pos,
|
|
'side': 'front',
|
|
'normal': (0.0, 0.0, -1.0),
|
|
}
|
|
world = World(Munch(chunks=FakeChunks(states=states)))
|
|
|
|
openings = world.find_throw_openings(
|
|
directive, center=(2, 64, 0), radius=3)
|
|
|
|
self.assertTrue(openings)
|
|
self.assertNotIn((0, 64, -1), {
|
|
tuple(opening['position']) for opening in openings
|
|
})
|
|
self.assertLessEqual(max(opening['distance'] for opening in openings), 3)
|
|
self.assertGreater(openings[0]['alignment'], 0.9)
|
|
self.assertEqual(tuple(openings[0]['position']), (0, 64, -2))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|