forked from PrismarineJS/mineflayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (63 loc) · 1.86 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
var mc = require('minecraft-protocol')
, EventEmitter = require('events').EventEmitter
, util = require('util')
, path = require('path')
, requireIndex = require('requireindex')
, plugins = requireIndex(path.join(__dirname, 'lib', 'plugins'))
module.exports = {
vec3: require('vec3'),
createBot: createBot,
Block: require('./lib/block'),
Location: require('./lib/location'),
Biome: require('./lib/biome'),
Entity: require('./lib/entity'),
Painting: require('./lib/painting'),
Item: require('./lib/item'),
Recipe: require('./lib/recipe'),
windows: require('./lib/windows'),
Chest: require('./lib/chest'),
Furnace: require('./lib/furnace'),
Dispenser: require('./lib/dispenser'),
EnchantmentTable: require('./lib/enchantment_table'),
blocks: require('./lib/enums/blocks'),
biomes: require('./lib/enums/biomes'),
items: require('./lib/enums/items'),
recipes: require('./lib/enums/recipes'),
instruments: require('./lib/enums/instruments'),
materials: require('./lib/enums/materials'),
};
function createBot(options) {
options = options || {};
options.username = options.username || 'Player';
var bot = new Bot();
bot.connect(options);
return bot;
}
function Bot() {
EventEmitter.call(this);
this.client = null;
}
util.inherits(Bot, EventEmitter);
Bot.prototype.connect = function(options) {
var self = this;
self.client = mc.createClient(options);
self.username = self.client.username;
self.client.on('session', function() {
self.username = self.client.username;
});
self.client.on('connect', function() {
self.emit('connect');
});
self.client.on('error', function(err) {
self.emit('error', err);
});
self.client.on('end', function() {
self.emit('end');
});
for (var pluginName in plugins) {
plugins[pluginName](self, options);
}
};
Bot.prototype.end = function() {
this.client.end();
};