Begin port to 26.3: movement

This commit is contained in:
Tanner
2026-11-03 22:48:15 +00:00
parent 891f14b988
commit 59c76471f2
23 changed files with 30692 additions and 478 deletions
+39
View File
@@ -0,0 +1,39 @@
"""Chat adapter for the Minecraft 26.3 play protocol."""
import time
from minecraft.networking.modern import (
ChatCommand, ClientboundPlayerChatPacket, ServerboundChatPacket, SystemChat,
)
class ModernChatManager:
def __init__(self, global_state):
self.g = global_state
self.handler = None
self.g.connection.register_packet_listener(
self.handle_player_chat, ClientboundPlayerChatPacket)
def set_handler(self, callback):
self.handler = callback
def handle_player_chat(self, packet):
sender = str(packet.sender)
text = '{}: {}'.format(sender, packet.message)
print('[chat] {}: {}'.format(sender, packet.message), flush=True)
if self.handler:
self.handler(('CHAT', sender, text))
def handle_system_chat(self, packet, message):
if self.handler:
self.handler(('SYSTEM', None, message))
def send(self, message):
if not message:
return
if message.startswith('/'):
self.g.connection.write_packet(
ChatCommand(command=message[1:]), force=True)
else:
packet = ServerboundChatPacket(
message=message, timestamp=int(time.time() * 1000))
self.g.connection.write_packet(packet, force=True)