-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.js
44 lines (41 loc) · 1.31 KB
/
server.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
var mineflayer = require('mineflayer');
var vec3 = mineflayer.vec3;
var navigatePlugin = require('mineflayer-navigate')(mineflayer);
var voxelPlugin = require('./mineflayer-voxel.js')(mineflayer);
var bot = mineflayer.createBot();
navigatePlugin(bot);
voxelPlugin(bot, {port: 13333});
bot.navigate.on('pathPartFound', function (path) {
bot.chat("Going " + path.length + " meters in the general direction for now.");
});
bot.navigate.on('pathFound', function (path) {
bot.chat("I can get there in " + path.length + " moves.");
});
bot.navigate.on('cannotFind', function () {
bot.chat("unable to find path");
});
bot.navigate.on('arrived', function () {
bot.chat("I have arrived");
});
bot.navigate.on('stop', function() {
bot.chat("stopping");
});
var lookInterval, lookTarget;
bot.on('chat', function(username, message) {
if (username === bot.username) return;
var target = bot.players[username].entity;
if (message === 'come') {
bot.navigate.to(target.position);
} else if (message === 'stop') {
bot.navigate.stop();
bot.clearControlStates();
clearInterval(lookInterval);
} else if (message === 'watch') {
clearInterval(lookInterval);
lookInterval = setInterval(look, 100);
lookTarget = target;
}
});
function look() {
bot.lookAt(lookTarget.position.offset(0, lookTarget.height, 0));
}