-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.ts
116 lines (87 loc) · 2.7 KB
/
bot.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { BotOptions, createBot } from "mineflayer";
import { pathfinder, Movements, goals } from "mineflayer-pathfinder";
import { plugin } from "mineflayer-pvp";
import * as config from "./config.json";
config.accounts.forEach((account) => {
joinServer(account as BotOptions);
});
function joinServer(options: BotOptions) {
let bot = createBot(options);
bot.loadPlugin(pathfinder);
bot.loadPlugin(plugin);
bot.once("spawn", () => {
const mcData = require("minecraft-data")(bot.version);
const defaultMove = new Movements(bot, mcData);
defaultMove.allowFreeMotion = true;
defaultMove.allowSprinting = true;
defaultMove.bot.pathfinder.setMovements(defaultMove);
bot.on("chat", (username: string, message: string) => {
const msg = message.toString();
if (!msg.startsWith(bot.username)) return;
const command = msg.split(" ")[1];
const args = msg.split(" ").slice(2);
if (command === "say") {
bot.chat(args.join(" "));
}
if (command === "come") {
comeToPlayer(username);
}
if (command === "follow") {
followPlayer(username);
}
if (command === "avoid") {
avoidPlayer(args[0]);
}
if (command === "stop") {
bot.pathfinder.setGoal(null);
}
if (command === "kill") {
const target = bot.players[args[0]]?.entity;
if (!target) {
bot.chat("I don't see you !");
return;
}
bot.pvp.attack(target);
}
if (command === "stopkill") {
bot.pvp.stop();
}
if (command === "drop") {
const slot = args[0];
bot.toss(parseInt(slot, 10), null, 1);
}
if (command === "slot") {
const slot = args[0];
bot.setQuickBarSlot(parseInt(slot, 10));
}
});
function followPlayer(playername: string) {
const target = bot.players[playername]?.entity;
if (!target) {
bot.chat("I don't see you !");
return;
}
bot.pathfinder.setGoal(new goals.GoalFollow(target, 3), true);
}
function avoidPlayer(playername: string) {
const target = bot.players[playername]?.entity;
if (!target) {
bot.chat("I don't see you !");
return;
}
bot.pathfinder.setGoal(
new goals.GoalInvert(new goals.GoalFollow(target, 8)),
true
);
}
function comeToPlayer(playername: string) {
const target = bot.players[playername]?.entity;
if (!target) {
bot.chat("I don't see you !");
return;
}
const { x: playerX, y: playerY, z: playerZ } = target.position;
bot.pathfinder.setGoal(new goals.GoalNear(playerX, playerY, playerZ, 1));
}
});
}