-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.js
More file actions
100 lines (82 loc) · 2.68 KB
/
bot.js
File metadata and controls
100 lines (82 loc) · 2.68 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
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
process.on('uncaughtException', (err) => {
if (err.message.includes('unknown chat format')) {
console.log('⚠️ Ignored a chat parsing error (Known 1.21 bug). Bot is still running.')
return
}
console.error('CRITICAL ERROR:', err)
process.exit(1)
})
const mineflayer = require('mineflayer')
const options = {
host: process.env.BOT_HOST || 'play.blockhorizon.fun',
port: parseInt(process.env.BOT_PORT) || 64345,
username: process.env.BOT_USERNAME || 'PixelForgeStudio',
auth: process.env.BOT_AUTH || 'offline',
version: '1.20.4'
}
const botPassword = process.env.BOT_PASSWORD || 'MySecretPassword123'
function createBot() {
const bot = mineflayer.createBot(options)
bot.on('messagestr', (message) => {
const msg = message.toLowerCase()
if (msg.includes('/register') || msg.includes('please register')) {
bot.chat(`/register ${botPassword} ${botPassword}`)
}
if (msg.includes('/login') || msg.includes('please login')) {
bot.chat(`/login ${botPassword}`)
}
console.log(msg)
})
bot.on('spawn', () => {
console.log('✅ Bot joined! Starting Human Simulation...')
humanBehavior(bot)
})
bot.on('kicked', (reason) => console.log('Kicked:', reason))
bot.on('error', (err) => console.log('Error:', err))
bot.on('end', () => {
console.log('Disconnected. Reconnecting in 30 seconds...')
setTimeout(createBot, 30000)
})
}
function humanBehavior(bot) {
const lookTime = Math.random() * 10000 + 10000
setTimeout(() => {
bot.look(Math.random() * Math.PI * 2, (Math.random() - 0.5) * Math.PI)
humanBehavior(bot)
}, lookTime)
const actionTime = Math.random() * 15000 + 15000
setTimeout(() => {
if (bot.entity && bot.entity.onGround) {
const action = Math.floor(Math.random() * 4)
switch(action) {
case 0:
bot.setControlState('jump', true)
bot.setControlState('forward', true)
setTimeout(() => {
bot.setControlState('jump', false)
bot.setControlState('forward', false)
}, 500)
break;
case 1:
bot.swingArm()
break;
case 2:
bot.setControlState('sneak', true)
setTimeout(() => bot.setControlState('sneak', false), 1000)
break;
case 3:
bot.setControlState('back', true)
setTimeout(() => bot.setControlState('back', false), 500)
break;
}
}
}, actionTime)
setTimeout(() => {
if (bot.entity && bot.entity.onGround) {
bot.setControlState('forward', true)
setTimeout(() => bot.setControlState('forward', false), 200)
}
setTimeout(() => humanBehavior(bot), 300000)
}, 300000)
}
createBot()