Port loiter and harden 26.3 bed updates

This commit is contained in:
Tanner
2026-11-05 01:05:52 +00:00
parent b9d43c7c37
commit efa2140a91
12 changed files with 664 additions and 65 deletions
+67
View File
@@ -0,0 +1,67 @@
import unittest
from munch import Munch
from minecraft.networking.packets import PacketBuffer
from minecraft.networking.modern import ClientTickEnd
from mosfet.commands import Commands
from mosfet.game import Game
from mosfet.protocol.modern import ClientCommandPacket
class FakeConnection:
def __init__(self):
self.packets = []
def write_packet(self, packet, force=False):
self.packets.append((packet, force))
class FakeChat:
def __init__(self):
self.handler = None
self.messages = []
def set_handler(self, handler):
self.handler = handler
def send(self, message):
self.messages.append(message)
class TestRespawn(unittest.TestCase):
def test_client_command_encodes_perform_respawn(self):
packet = ClientCommandPacket(action_id=0)
buffer = PacketBuffer()
packet.write_fields(buffer)
self.assertEqual(packet.id, 0x0C)
self.assertEqual(buffer.get_writable(), b'\x00')
def test_game_respawn_sends_modern_client_command_and_tick_end(self):
connection = FakeConnection()
game = Game.__new__(Game)
game.g = Munch(connection=connection)
game.respawn()
packet, forced = connection.packets[0]
self.assertIsInstance(packet, ClientCommandPacket)
self.assertEqual(packet.action_id, 0)
self.assertTrue(forced)
self.assertIsInstance(connection.packets[1][0], ClientTickEnd)
self.assertIn('respawn_requested_at', game.g)
def test_respawn_command_is_enabled(self):
chat = FakeChat()
calls = []
game = Munch(respawn=lambda: calls.append('respawn'))
commands = Commands(Munch(name='mosfet1', chat=chat, game=game))
commands.handle_chat(('SYSTEM', None, 'server: 1respawn'))
self.assertEqual(calls, ['respawn'])
self.assertEqual(chat.messages, ['ok'])
if __name__ == '__main__':
unittest.main()