45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import unittest
|
|
|
|
from munch import Munch
|
|
from minecraft.networking.modern import ClientTickEnd, PunchPacket
|
|
from minecraft.networking.packets import PacketBuffer
|
|
|
|
from mosfet.game import Game
|
|
from mosfet.protocol.modern import AttackEntityPacket
|
|
|
|
|
|
class FakeConnection:
|
|
def __init__(self):
|
|
self.packets = []
|
|
|
|
def write_packet(self, packet, force=False):
|
|
self.packets.append((packet, force))
|
|
|
|
|
|
class AttackPacketTests(unittest.TestCase):
|
|
def test_attack_packet_encodes_protocol_777_entity_id(self):
|
|
packet = AttackEntityPacket(entity_id=300)
|
|
payload = PacketBuffer()
|
|
|
|
packet.write_fields(payload)
|
|
|
|
self.assertEqual(packet.id, 0x01)
|
|
self.assertEqual(payload.get_writable(), bytes.fromhex('ac02'))
|
|
|
|
def test_game_attack_sends_attack_and_visible_main_hand_swing(self):
|
|
connection = FakeConnection()
|
|
game = Game.__new__(Game)
|
|
game.g = Munch(connection=connection)
|
|
|
|
game.attack_entity(17)
|
|
|
|
self.assertEqual(
|
|
[type(packet) for packet, _force in connection.packets],
|
|
[AttackEntityPacket, ClientTickEnd, PunchPacket, ClientTickEnd])
|
|
self.assertEqual(connection.packets[0][0].entity_id, 17)
|
|
self.assertTrue(all(force for _packet, force in connection.packets))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|