minecraft-bot/bot.py

52 lines
1.3 KiB
Python
Raw Normal View History

if __name__ == '__main__':
print('Run main.py instead.')
exit(1)
import time
USERNAME = ''
PASSWORD = ''
SERVER = ''
from custom.managers import DataManager, ChunksManager, ChatManager
import monkey_patch
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)