Add handlers
This commit is contained in:
		
							
								
								
									
										17
									
								
								bot.py
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								bot.py
									
									
									
									
									
								
							| @@ -21,6 +21,8 @@ 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 | ||||||
|  |  | ||||||
|  | from panda3d.core import LPoint3f | ||||||
|  |  | ||||||
| import packet_handlers | import packet_handlers | ||||||
| importlib.reload(packet_handlers) | importlib.reload(packet_handlers) | ||||||
|  |  | ||||||
| @@ -44,14 +46,7 @@ def bot(global_state): | |||||||
|             print(e) |             print(e) | ||||||
|             sys.exit() |             sys.exit() | ||||||
|         print("Logged in as %s..." % auth_token.username) |         print("Logged in as %s..." % auth_token.username) | ||||||
|         g.connection = Connection( |         g.connection = Connection(SERVER, 25565, auth_token=auth_token) | ||||||
|             SERVER, 25565, auth_token=auth_token) |  | ||||||
|  |  | ||||||
|         def handle_join_game(join_game_packet): |  | ||||||
|             print('Connected.') |  | ||||||
|  |  | ||||||
|         g.connection.register_packet_listener( |  | ||||||
|             handle_join_game, clientbound.play.JoinGamePacket) |  | ||||||
|  |  | ||||||
|         g.chunks = ChunksManager(g.mcdata) |         g.chunks = ChunksManager(g.mcdata) | ||||||
|         g.chunks.register(g.connection) |         g.chunks.register(g.connection) | ||||||
| @@ -67,9 +62,15 @@ def bot(global_state): | |||||||
|             handler(packet, g) |             handler(packet, g) | ||||||
|         return wrapper |         return wrapper | ||||||
|  |  | ||||||
|  |     h = packet_wrapper(packet_handlers.handle_join_game) | ||||||
|  |     g.connection.register_packet_listener(h, clientbound.play.JoinGamePacket) | ||||||
|  |  | ||||||
|     h = packet_wrapper(packet_handlers.handle_block_change) |     h = packet_wrapper(packet_handlers.handle_block_change) | ||||||
|     g.connection.register_packet_listener(h, BlockChangePacket) |     g.connection.register_packet_listener(h, BlockChangePacket) | ||||||
|  |  | ||||||
|  |     h = packet_wrapper(packet_handlers.handle_position_and_look) | ||||||
|  |     g.connection.register_packet_listener(h, clientbound.play.PlayerPositionAndLookPacket) | ||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         #while not player_info.pos: |         #while not player_info.pos: | ||||||
|         #    time.sleep(TICK) |         #    time.sleep(TICK) | ||||||
|   | |||||||
| @@ -1,3 +1,16 @@ | |||||||
| def handle_block_change(p, g): | from panda3d.core import * | ||||||
|  |  | ||||||
|  | def handle_join_game(packet, g): | ||||||
|  |     print('Connected.') | ||||||
|  |     print(packet) | ||||||
|  |     g.info = packet | ||||||
|  |  | ||||||
|  | def handle_block_change(packet, g): | ||||||
|     print('block change:') |     print('block change:') | ||||||
|     print(p) |     print(packet) | ||||||
|  |  | ||||||
|  | def handle_position_and_look(packet, g): | ||||||
|  |     print('pos and look:') | ||||||
|  |     print(packet) | ||||||
|  |     p = LPoint3f(x=packet.x, y=packet.y, z=packet.z) | ||||||
|  |     g.pos = p | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ idna==2.10 | |||||||
| itsdangerous==1.1.0 | itsdangerous==1.1.0 | ||||||
| Jinja2==2.11.2 | Jinja2==2.11.2 | ||||||
| MarkupSafe==1.1.1 | MarkupSafe==1.1.1 | ||||||
|  | panda3d==1.10.6.post2 | ||||||
| pathtools==0.1.2 | pathtools==0.1.2 | ||||||
| pycparser==2.20 | pycparser==2.20 | ||||||
| pyCraft @ git+https://github.com/ammaraskar/pyCraft.git@cf93923acc2dcfbc076379b43842228d77aea188 | pyCraft @ git+https://github.com/ammaraskar/pyCraft.git@cf93923acc2dcfbc076379b43842228d77aea188 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user