From 514b324156f7731043b9fb27620f495b1d45b0ad Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 7 Sep 2020 16:08:59 -0600 Subject: [PATCH] Move monkey-patching into its own module --- bot.py | 15 +-------------- monkey_patch.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 monkey_patch.py diff --git a/bot.py b/bot.py index c6ebcf9..2d970ef 100644 --- a/bot.py +++ b/bot.py @@ -10,20 +10,7 @@ SERVER = '' from custom.managers import DataManager, ChunksManager, ChatManager -import minecraft.networking.packets -from custom.networking.packets.clientbound.play import chunk_data, block_change_packet - -def get_packets(old_get_packets): - def wrapper(func, context): - print('Monkey-patched.') - packets = func(context) - packets.add(chunk_data.ChunkDataPacket) - packets.add(block_change_packet.BlockChangePacket) - packets.add(block_change_packet.MultiBlockChangePacket) - 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) +import monkey_patch from minecraft import authentication from minecraft.exceptions import YggdrasilError diff --git a/monkey_patch.py b/monkey_patch.py new file mode 100644 index 0000000..1f91157 --- /dev/null +++ b/monkey_patch.py @@ -0,0 +1,17 @@ +import minecraft.networking.packets +from custom.networking.packets.clientbound.play import chunk_data, block_change_packet + +def get_packets(old_get_packets): + def wrapper(func, context): + print('Monkey-patched.') + packets = func(context) + + # add any custom packets here + packets.add(chunk_data.ChunkDataPacket) + packets.add(block_change_packet.BlockChangePacket) + packets.add(block_change_packet.MultiBlockChangePacket) + + 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)