-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattackSystem.js
More file actions
58 lines (44 loc) · 1.69 KB
/
attackSystem.js
File metadata and controls
58 lines (44 loc) · 1.69 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const chalk = require("chalk");
const validMobNames = [
"Zombie", "Skeleton", "Creeper", "Spider", "Cave Spider",
"Enderman", "Slime", "Magma Cube", "Blaze", "Witch", "Husk",
"Drowned", "Stray", "Wither Skeleton", "Ghast", "Phantom",
"Silverfish", "Shulker", "Guardian", "Elder Guardian",
"Piglin", "Piglin Brute", "Zoglin", "Vindicator", "Evoker",
"Pillager", "Ravager", "Warden"
];
module.exports = function startAttacker(bot, settings) {
if (!settings.hit || !settings.hit.enabled) return;
let lastTargetName = null;
function isValidTarget(entity) {
if (!entity || !entity.position) return false;
const dist = entity.position.distanceTo(bot.entity.position);
if (dist > 5) return false;
const mode = settings.hit.attacked;
if (mode === "player") {
return entity.username && entity.username !== bot.username;
}
if (mode === "mob") {
return entity.displayName && validMobNames.includes(entity.displayName);
}
if (mode === "both") {
const isPlayer = entity.username && entity.username !== bot.username;
const isMob = entity.displayName && validMobNames.includes(entity.displayName);
return isPlayer || isMob;
}
return false;
}
setInterval(() => {
const target = bot.nearestEntity(isValidTarget);
if (target) {
bot.attack(target);
const name = target.username || target.displayName || "unknown";
if (lastTargetName !== name) {
console.log(chalk.red(`[ATTACKED] Attacking ${settings.hit.attacked}: ${name}`));
lastTargetName = name;
}
} else {
lastTargetName = null;
}
}, settings.hit.delay || 1000);
};