This repository was archived by the owner on Oct 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
42 lines (32 loc) · 1.2 KB
/
index.ts
File metadata and controls
42 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import mineflayer from "mineflayer";
import { pathfinder } from "mineflayer-pathfinder";
import Logger from "./src/logging";
import { chatWithShape } from "./src/shapes";
// Create Mineflayer bot, connect to Minecraft server, register plugins
const botOptions: mineflayer.BotOptions = {
host: process.env.MINECRAFT_HOST_IP,
port: parseInt(process.env.MINECRAFT_SERVER_PORT!),
username: process.env.MINEFLAYER_USERNAME || "Shape",
version: "1.21.4", // Can change to whichever version you want
auth: "offline",
}
export const bot = mineflayer.createBot(botOptions);
bot.loadPlugin(pathfinder);
bot.on("spawn", () => {
Logger.log(`${bot.username} successfully spawned in`, "mineflayer");
});
bot.on("chat", async (username, message) => {
if (username === bot.username) return;
Logger.log(`<${username}> ${message}`, "mineflayer");
const response = await chatWithShape(message);
if (!response) return;
Logger.log("Response received!");
Logger.log("Sending return message to Mineflayer bot...");
Logger.log(`<${bot.username}> ${response}`, "mineflayer");
bot.chat(response);
});
bot.on("death", () => {
bot.removeAllListeners();
});
bot.on("kicked", console.log);
bot.on("error", console.log);