From 303612fcf1267e22fe42ba415b265b25e75ef9b0 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 5 Sep 2020 22:19:48 -0600 Subject: [PATCH] Monkey-patch in custom packets --- .../packets/clientbound/play/chunk_data.py | 5 +--- start.py | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/custom/networking/packets/clientbound/play/chunk_data.py b/custom/networking/packets/clientbound/play/chunk_data.py index 1192b78..6ec6157 100644 --- a/custom/networking/packets/clientbound/play/chunk_data.py +++ b/custom/networking/packets/clientbound/play/chunk_data.py @@ -9,10 +9,7 @@ from minecraft.networking.types import ( from ....types import nbt class ChunkDataPacket(Packet): - @staticmethod - def get_id(context): - return 0x20 # FIXME - + id = 0x20 packet_name = 'chunk data' fields = 'x', 'bit_mask_y', 'z', 'full_chunk' diff --git a/start.py b/start.py index 7c3ba54..ae55275 100644 --- a/start.py +++ b/start.py @@ -5,13 +5,26 @@ import sys import re from optparse import OptionParser +from custom.managers import DataManager, ChunksManager +from custom.networking.packets.clientbound.play import chunk_data + +import minecraft.networking.packets + +def get_packets(old_get_packets): + def wrapper(func, context): + print('Monkey-patched.') + packets = func(context) + packets.add(chunk_data.ChunkDataPacket) + return packets + return lambda x: wrapper(old_get_packets, x) + +minecraft.networking.packets.clientbound.play.get_packets = get_packets(minecraft.networking.packets.clientbound.play.get_packets) + from minecraft import authentication from minecraft.exceptions import YggdrasilError from minecraft.networking.connection import Connection from minecraft.networking.packets import Packet, clientbound, serverbound -from custom.managers import DataManager, ChunksManager - def get_options(): parser = OptionParser() @@ -111,12 +124,18 @@ def main(): print("Message (%s): %s" % ( chat_packet.field_string('position'), chat_packet.json_data)) - chunks = ChunksManager(mcdata) - chunks.register(connection) + #chunks = ChunksManager(mcdata) + #chunks.register(connection) connection.register_packet_listener( print_chat, clientbound.play.ChatMessagePacket) + def handle_chunk(chunk_packet): + print(chunk_packet) + + def register(self, connection): + connection.register_packet_listener(handle_chunk, chunk_data.ChunkDataPacket) + connection.connect() while True: