diff --git a/bot.py b/bot.py index 60fa8bd..4fea834 100644 --- a/bot.py +++ b/bot.py @@ -4,14 +4,15 @@ if __name__ == '__main__': import os import time +import importlib USERNAME = os.environ['USERNAME'] PASSWORD = os.environ['PASSWORD'] SERVER = os.environ['SERVER'] -from custom.managers import DataManager, ChunksManager, ChatManager +import monkey_patch # must be before any possible pyCraft imports -import monkey_patch +from custom.managers import DataManager, ChunksManager, ChatManager from minecraft import authentication from minecraft.exceptions import YggdrasilError @@ -20,6 +21,9 @@ from minecraft.networking.packets import Packet, clientbound, serverbound from custom.networking.packets.clientbound.play.block_change_packet import BlockChangePacket +import packet_handlers +importlib.reload(packet_handlers) + TICK = 0.05 last_tick = time.time() @@ -57,13 +61,14 @@ def bot(global_state): g.connection.connect() + def packet_wrapper(handler): + def wrapper(packet): + print('called') + handler(packet, g) + return wrapper - def x(p): - print('sup block change:') - print(p) - - g.connection.register_packet_listener( - x, BlockChangePacket) + h = packet_wrapper(packet_handlers.handle_block_change) + g.connection.register_packet_listener(h, BlockChangePacket) try: #while not player_info.pos: diff --git a/main.py b/main.py index d497813..1071f9a 100644 --- a/main.py +++ b/main.py @@ -49,4 +49,5 @@ def main(): if __name__ == '__main__': threading.Thread(target=app.run).start() + time.sleep(1) main() diff --git a/monkey_patch.py b/monkey_patch.py index 1f91157..9ce2f28 100644 --- a/monkey_patch.py +++ b/monkey_patch.py @@ -3,7 +3,7 @@ from custom.networking.packets.clientbound.play import chunk_data, block_change_ def get_packets(old_get_packets): def wrapper(func, context): - print('Monkey-patched.') + print('Monkey-patch worked.') packets = func(context) # add any custom packets here diff --git a/packet_handlers.py b/packet_handlers.py new file mode 100644 index 0000000..dd4fa2b --- /dev/null +++ b/packet_handlers.py @@ -0,0 +1,3 @@ +def handle_block_change(p, g): + print('block change:') + print(p)