generated from drmzio/mineflayer-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (30 loc) · 825 Bytes
/
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
require('dotenv').config();
const mineflayer = require('mineflayer');
const { mineflayer: mineflayerViewer } = require('prismarine-viewer');
/**
* Create the bot instance.
* @see https://github.com/PrismarineJS/mineflayer
*/
const bot = mineflayer.createBot({
host: process.env.MC_HOST,
username: process.env.MC_USERNAME,
password: process.env.MC_PASSWORD,
auth: process.env.MC_AUTH,
});
/**
* Creates the mineflayer viewer.
* @see https://github.com/PrismarineJS/prismarine-viewer
*/
const createViewer = () => {
// Destroy the current viewer if exists.
if (bot.viewer) {
bot.viewer.close();
bot.viewer = undefined;
}
mineflayerViewer(bot, { port: process.env.PORT || 3000 });
};
bot.once('spawn', () => {
createViewer();
});
bot.on('kicked', console.log);
bot.on('error', console.log);