76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
import unittest
|
|
from munch import Munch
|
|
|
|
from mosfet.info import blocks
|
|
from mosfet.world import World
|
|
|
|
|
|
def wall_sign_state(facing):
|
|
data = blocks.MCD_BLOCKS['oak_wall_sign']
|
|
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 SafetySignTests(unittest.TestCase):
|
|
def test_safety_and_refuge_signs_follow_group_and_individual_addresses(self):
|
|
group_sign = (0, 64, 0)
|
|
individual_sign = (3, 64, 0)
|
|
world = World(Munch(chunks=FakeChunks(
|
|
block_entities={
|
|
group_sign: {'data': {'front_text': {'messages': [
|
|
'mosfet', 'safety', '', '',
|
|
]}}},
|
|
individual_sign: {'data': {'back_text': {'messages': [
|
|
'mosfet2 refuge', '', '', '',
|
|
]}}},
|
|
},
|
|
states={
|
|
group_sign: wall_sign_state('north'),
|
|
individual_sign: wall_sign_state('east'),
|
|
})))
|
|
|
|
bot2 = world.find_safety_signs((0, 64, 0), 'mosfet2', 10)
|
|
self.assertEqual([sign['position'] for sign in bot2], [
|
|
group_sign, individual_sign,
|
|
])
|
|
self.assertEqual(bot2[1]['normal'], (-1.0, 0.0, 0.0))
|
|
self.assertEqual([sign['position'] for sign in world.find_safety_signs(
|
|
(0, 64, 0), 'mosfet1', 10)], [group_sign])
|
|
self.assertEqual([sign['position'] for sign in world.find_safety_signs(
|
|
(0, 64, 0), 'mosfet9', 10)], [group_sign])
|
|
self.assertEqual(world.find_safety_signs(
|
|
(0, 64, 0), 'mosfet10', 10), [])
|
|
|
|
def test_safety_openings_try_text_facing_standable_positions_first(self):
|
|
sign_pos = (0, 64, 0)
|
|
front = (0, 64, -1)
|
|
side = (1, 64, 0)
|
|
states = {
|
|
sign_pos: wall_sign_state('north'),
|
|
(front[0], front[1] - 1, front[2]): blocks.STONE,
|
|
(side[0], side[1] - 1, side[2]): blocks.STONE,
|
|
}
|
|
world = World(Munch(chunks=FakeChunks(states=states)))
|
|
sign = {'position': sign_pos, 'normal': (0.0, 0.0, -1.0)}
|
|
|
|
openings = world.find_safety_openings(sign)
|
|
|
|
self.assertEqual(openings[0], front)
|
|
self.assertIn(side, openings)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|