mc client creation ig

This commit is contained in:
Parker2991
2026-01-22 10:01:13 -06:00
parent 58a020dfd4
commit cf4560be24
2 changed files with 58 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
import mc from "minecraft-protocol";
import { EventEmitter } from "events";
export class Bot {
public listener = new EventEmitter();
public chat: any;
public bots: Array<any>
public options: any;
public entityId: any;
constructor (options: any, config: any) {
const listener = this.listener;
this.options = {
host: options.host ??= "localhost",
port: options.port ??= 25565,
version: options.version ??= "1.21.8",
username: options.username ??= "FNFBoyfriendBot"
};
this.options = options;
listener.on("init_client", (packet: any) => {
client?.on('packet', (data: any, meta: any) => {
listener.emit("packet", data, meta);
listener.emit("packet." + meta.name, data)
});
client.on('login', (packet: any) => {
this.entityId = packet.entityId;
});
client?.on("end", (reason: any) => {
listener.emit("end", reason);
});
});
const client = mc.createClient(options);
listener.emit('init_client', client);
this.bots = options.bots ?? [listener];
return this;
}
}
+10
View File
@@ -0,0 +1,10 @@
import { Bot } from "./Bot";
const config = require('../config.js');
let bots = [];
for (const options of config.bots) {
let bot = new Bot(options, config);
bot.bots.push(bot);
}