Add module for packet handlers and reload it

This commit is contained in:
Tanner Collin 2020-09-07 22:31:55 -06:00
parent 76d5609c26
commit db8d8d7b85
4 changed files with 18 additions and 9 deletions

21
bot.py
View File

@ -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:

View File

@ -49,4 +49,5 @@ def main():
if __name__ == '__main__':
threading.Thread(target=app.run).start()
time.sleep(1)
main()

View File

@ -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

3
packet_handlers.py Normal file
View File

@ -0,0 +1,3 @@
def handle_block_change(p, g):
print('block change:')
print(p)