Read nearby 26.3 sign text
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import unittest
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.commands import Commands
|
||||
from mosfet.protocol.managers import EntityManager, WorldState
|
||||
from mosfet.world import World
|
||||
|
||||
|
||||
class SignReadingTests(unittest.TestCase):
|
||||
def test_world_decodes_front_and_back_sign_components(self):
|
||||
chunks = Munch(block_entities={
|
||||
(2, 64, 3): {
|
||||
'type': 7,
|
||||
'data': {
|
||||
'front_text': {'messages': [
|
||||
'{"text":"Hello","extra":[{"text":" world"}]}',
|
||||
'{"text":"line two"}', '', ''],
|
||||
},
|
||||
'back_text': {'messages': [
|
||||
'{"text":"back"}', '', '', ''],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
signs = World(Munch(chunks=chunks)).find_signs((0, 64, 0), 10)
|
||||
|
||||
self.assertEqual(signs, [
|
||||
{'position': (2, 64, 3), 'side': 'front',
|
||||
'lines': ('Hello world', 'line two', '', '')},
|
||||
{'position': (2, 64, 3), 'side': 'back',
|
||||
'lines': ('back', '', '', '')},
|
||||
])
|
||||
|
||||
def test_block_entity_update_is_cached_for_sign_search(self):
|
||||
chunks = WorldState()
|
||||
manager = object.__new__(EntityManager)
|
||||
manager.g = Munch(chunks=chunks)
|
||||
manager.handle_block_entity_data(Munch(
|
||||
location=Munch(x=4, y=65, z=-2),
|
||||
block_entity_type=7,
|
||||
data={'front_text': {'messages': ['{"text":"Farm"}', '', '', '']}},
|
||||
))
|
||||
|
||||
signs = World(Munch(chunks=chunks)).find_signs((4, 65, -2), 1)
|
||||
self.assertEqual(signs[0]['lines'], ('Farm', '', '', ''))
|
||||
|
||||
def test_signs_command_replies_with_nearby_text(self):
|
||||
class FakeChat:
|
||||
def __init__(self):
|
||||
self.sent = []
|
||||
|
||||
def set_handler(self, handler):
|
||||
self.handler = handler
|
||||
|
||||
def send(self, message):
|
||||
self.sent.append(message)
|
||||
|
||||
chat = FakeChat()
|
||||
world = Munch(find_signs=lambda _position, _distance: [{
|
||||
'position': (1, 64, 2), 'side': 'front',
|
||||
'lines': ('Hello', 'world', '', ''),
|
||||
}])
|
||||
commands = Commands(Munch(
|
||||
name='mosfet1', chat=chat, world=world, pos=(0.5, 64.0, 0.5)))
|
||||
commands.handle_chat(('CHAT', 'tester', 'tester: !signs'))
|
||||
|
||||
self.assertEqual(chat.sent, ['front (1, 64, 2): Hello | world'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user