-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathbot.js
More file actions
66 lines (57 loc) · 1.57 KB
/
bot.js
File metadata and controls
66 lines (57 loc) · 1.57 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
59
60
61
62
63
64
65
66
const mineflayer = require('mineflayer');
const config = require('./config.json');
const bot = mineflayer.createBot({
host: config.serverHost,
port: config.serverPort,
username: config.botUsername,
auth: 'offline',
version: false,
viewDistance: config.botChunk
});
let movementPhase = 0;
const STEP_INTERVAL = 1500;
const STEP_SPEED = 1;
const JUMP_DURATION = 500;
bot.on('spawn', () => {
setTimeout(() => {
bot.setControlState('sneak', true);
console.log(`✅ ${config.botUsername} is Ready!`);
}, 3000);
setTimeout(movementCycle, STEP_INTERVAL);
});
function movementCycle() {
if (!bot.entity) return;
switch (movementPhase) {
case 0:
bot.setControlState('forward', true);
bot.setControlState('back', false);
bot.setControlState('jump', false);
break;
case 1:
bot.setControlState('forward', false);
bot.setControlState('back', true);
bot.setControlState('jump', false);
break;
case 2:
bot.setControlState('forward', false);
bot.setControlState('back', false);
bot.setControlState('jump', true);
setTimeout(() => {
bot.setControlState('jump', false);
}, JUMP_DURATION);
break;
case 3:
bot.setControlState('forward', false);
bot.setControlState('back', false);
bot.setControlState('jump', false);
break;
}
movementPhase = (movementPhase + 1) % 4;
setTimeout(movementCycle, STEP_INTERVAL);
}
bot.on('error', (err) => {
console.error('⚠️ Error:', err);
});
bot.on('end', () => {
console.log('⛔️ Bot Disconnected!');
});