Add module for packet handlers and reload it
This commit is contained in:
		
							
								
								
									
										21
									
								
								bot.py
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								bot.py
									
									
									
									
									
								
							@@ -4,14 +4,15 @@ if __name__ == '__main__':
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
 | 
					import importlib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
USERNAME = os.environ['USERNAME']
 | 
					USERNAME = os.environ['USERNAME']
 | 
				
			||||||
PASSWORD = os.environ['PASSWORD']
 | 
					PASSWORD = os.environ['PASSWORD']
 | 
				
			||||||
SERVER = os.environ['SERVER']
 | 
					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 import authentication
 | 
				
			||||||
from minecraft.exceptions import YggdrasilError
 | 
					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
 | 
					from custom.networking.packets.clientbound.play.block_change_packet import BlockChangePacket
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import packet_handlers
 | 
				
			||||||
 | 
					importlib.reload(packet_handlers)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TICK = 0.05
 | 
					TICK = 0.05
 | 
				
			||||||
last_tick = time.time()
 | 
					last_tick = time.time()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -57,13 +61,14 @@ def bot(global_state):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        g.connection.connect()
 | 
					        g.connection.connect()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def packet_wrapper(handler):
 | 
				
			||||||
 | 
					        def wrapper(packet):
 | 
				
			||||||
 | 
					            print('called')
 | 
				
			||||||
 | 
					            handler(packet, g)
 | 
				
			||||||
 | 
					        return wrapper
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def x(p):
 | 
					    h = packet_wrapper(packet_handlers.handle_block_change)
 | 
				
			||||||
        print('sup block change:')
 | 
					    g.connection.register_packet_listener(h, BlockChangePacket)
 | 
				
			||||||
        print(p)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    g.connection.register_packet_listener(
 | 
					 | 
				
			||||||
        x, BlockChangePacket)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        #while not player_info.pos:
 | 
					        #while not player_info.pos:
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								main.py
									
									
									
									
									
								
							@@ -49,4 +49,5 @@ def main():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    threading.Thread(target=app.run).start()
 | 
					    threading.Thread(target=app.run).start()
 | 
				
			||||||
 | 
					    time.sleep(1)
 | 
				
			||||||
    main()
 | 
					    main()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ from custom.networking.packets.clientbound.play import chunk_data, block_change_
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def get_packets(old_get_packets):
 | 
					def get_packets(old_get_packets):
 | 
				
			||||||
    def wrapper(func, context):
 | 
					    def wrapper(func, context):
 | 
				
			||||||
        print('Monkey-patched.')
 | 
					        print('Monkey-patch worked.')
 | 
				
			||||||
        packets = func(context)
 | 
					        packets = func(context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # add any custom packets here
 | 
					        # add any custom packets here
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								packet_handlers.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								packet_handlers.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					def handle_block_change(p, g):
 | 
				
			||||||
 | 
					    print('block change:')
 | 
				
			||||||
 | 
					    print(p)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user