65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
|
if __name__ == '__main__':
|
||
|
print('Run main.py instead.')
|
||
|
exit(1)
|
||
|
|
||
|
import time
|
||
|
|
||
|
USERNAME = ''
|
||
|
PASSWORD = ''
|
||
|
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)
|
||
|
|
||
|
from minecraft import authentication
|
||
|
from minecraft.exceptions import YggdrasilError
|
||
|
from minecraft.networking.connection import Connection
|
||
|
from minecraft.networking.packets import Packet, clientbound, serverbound
|
||
|
|
||
|
def bot(global_state):
|
||
|
g = global_state
|
||
|
|
||
|
if 'mcdata' not in g:
|
||
|
g.mcdata = DataManager('./mcdata')
|
||
|
|
||
|
if 'connection' not in g:
|
||
|
auth_token = authentication.AuthenticationToken()
|
||
|
try:
|
||
|
auth_token.authenticate(USERNAME, PASSWORD)
|
||
|
except YggdrasilError as e:
|
||
|
print(e)
|
||
|
sys.exit()
|
||
|
print("Logged in as %s..." % auth_token.username)
|
||
|
g.connection = Connection(
|
||
|
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.register(g.connection)
|
||
|
|
||
|
g.chat = ChatManager()
|
||
|
g.chat.register(g.connection)
|
||
|
|
||
|
g.connection.connect()
|
||
|
|
||
|
time.sleep(1)
|