-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
50 lines (39 loc) · 1.18 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
module.exports = init;
function init(mineflayer) {
return inject;
}
function inject(bot, options) {
options = options || {};
var path = require('path')
, express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, port = options.port || 0
, host = options.host || '0.0.0.0'
io.set('log level', 0);
app.use(express.static(path.join(__dirname, 'public')));
server.listen(port, function() {
console.info("Listening at http://" + host + ":" + server.address().port);
});
io.sockets.on('connection', function (socket) {
bot.on('move', function() {
socket.emit('entity', bot.entity);
});
bot.on('entitySpawn', function(entity) {
socket.emit('entitySpawn', entity);
});
bot.on('entityGone', function(entity) {
socket.emit('entityGone', entity);
});
bot.on('entityMoved', function(entity) {
socket.emit('entityMoved', entity);
});
socket.on('controlState', function(state) {
bot.setControlState(state.name, state.value);
});
socket.on('look', function(look) {
bot.look(look.yaw, look.pitch);
});
});
}