65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
import unittest
|
|
from munch import Munch
|
|
|
|
from minecraft.networking.modern import ClientTickEnd, UseItemOnBlockPacket
|
|
from minecraft.networking.types import BlockFace
|
|
from mosfet.game import Game
|
|
from mosfet.info import blocks
|
|
from mosfet.protocol.modern import PlayerInputPacket
|
|
|
|
|
|
class FakeConnection:
|
|
def __init__(self):
|
|
self.packets = []
|
|
|
|
def write_packet(self, packet, force=False):
|
|
self.packets.append((packet, force))
|
|
|
|
|
|
class SneakPlacementTests(unittest.TestCase):
|
|
def test_open_container_sends_visible_face_and_hit_cursor(self):
|
|
chest = (2, 65, -4)
|
|
connection = FakeConnection()
|
|
game = Game.__new__(Game)
|
|
game.g = Munch(
|
|
connection=connection,
|
|
chunks=Munch(get_block_at=lambda *position:
|
|
min(blocks.CHEST_IDS) if tuple(position) == chest
|
|
else None),
|
|
world=Munch())
|
|
game.sequence = 0
|
|
|
|
game.open_container(
|
|
chest, face=BlockFace.EAST, cursor=(0.9375, 0.5, 0.5))
|
|
|
|
packet = next(packet for packet, _force in connection.packets
|
|
if isinstance(packet, UseItemOnBlockPacket))
|
|
self.assertEqual(packet.location, chest)
|
|
self.assertEqual(packet.face, BlockFace.EAST)
|
|
self.assertEqual((packet.cursor_x, packet.cursor_y, packet.cursor_z),
|
|
(0.9375, 0.5, 0.5))
|
|
|
|
def test_sneaking_wraps_block_placement_and_is_released(self):
|
|
connection = FakeConnection()
|
|
game = Game.__new__(Game)
|
|
game.g = Munch(connection=connection)
|
|
game.sequence = 0
|
|
|
|
game.place_block((3, 64, 7), 1, sneaking=True)
|
|
|
|
packets = [packet for packet, _force in connection.packets]
|
|
self.assertEqual(len(packets), 6)
|
|
self.assertIsInstance(packets[0], PlayerInputPacket)
|
|
self.assertEqual(packets[0].flags, 0x20)
|
|
self.assertIsInstance(packets[1], ClientTickEnd)
|
|
self.assertIsInstance(packets[2], UseItemOnBlockPacket)
|
|
self.assertEqual(packets[2].location, (3, 64, 7))
|
|
self.assertIsInstance(packets[3], ClientTickEnd)
|
|
self.assertIsInstance(packets[4], PlayerInputPacket)
|
|
self.assertEqual(packets[4].flags, 0)
|
|
self.assertIsInstance(packets[5], ClientTickEnd)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|