-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (65 loc) · 1.95 KB
/
index.js
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
const mineflayer = require('mineflayer')
const cmd = require('mineflayer-cmd').plugin
const fs = require('fs');
let rawdata = fs.readFileSync('config.json');
let data = JSON.parse(rawdata);
var lasttime = -1;
var moving = 0;
var connected = 0;
var actions = [ 'forward', 'back', 'left', 'right']
var lastaction;
var pi = 3.14159;
var moveinterval = 2; // 2 second movement interval
var maxrandom = 5; // 0-5 seconds added to movement interval (randomly)
var host = data["ip"];
var username = data["name"]
var nightskip = data["auto-night-skip"]
var bot = mineflayer.createBot({
host: host,
username: username
});
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
bot.loadPlugin(cmd)
bot.on('login',function(){
console.log("Logged In")
bot.chat("hello");
});
bot.on('time', function(time) {
if(nightskip == "true"){
if(bot.time.timeOfDay >= 13000){
bot.chat('/time set day')
}}
if (connected <1) {
return;
}
if (lasttime<0) {
lasttime = bot.time.age;
} else {
var randomadd = Math.random() * maxrandom * 20;
var interval = moveinterval*20 + randomadd;
if (bot.time.age - lasttime > interval) {
if (moving == 1) {
bot.setControlState(lastaction,false);
moving = 0;
lasttime = bot.time.age;
} else {
var yaw = Math.random()*pi - (0.5*pi);
var pitch = Math.random()*pi - (0.5*pi);
bot.look(yaw,pitch,false);
lastaction = actions[Math.floor(Math.random() * actions.length)];
bot.setControlState(lastaction,true);
moving = 1;
lasttime = bot.time.age;
bot.activateItem();
}
}
}
});
bot.on('spawn',function() {
connected=1;
});
bot.on('death',function() {
bot.emit("respawn")
});