CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/examples/modular_mineflayer/index.js
Views: 789
1
const fs = require('fs')
2
const path = require('path')
3
const mineflayer = require('mineflayer')
4
5
const OPTIONS = {
6
username: 'i_am_u9g',
7
host: 'localhost'
8
}
9
10
function injectModules (bot) {
11
const MODULES_DIRECTORY = path.join(__dirname, 'modules')
12
const modules = fs
13
.readdirSync(MODULES_DIRECTORY) // find the plugins
14
.filter(x => x.endsWith('.js')) // only use .js files
15
.map(pluginName => require(path.join(MODULES_DIRECTORY, pluginName)))
16
17
bot.loadPlugins(modules)
18
}
19
20
function initBot () {
21
const bot = mineflayer.createBot(OPTIONS)
22
injectModules(bot)
23
24
bot.on('end', initBot) // auto restart
25
}
26
27
initBot() // start the bot
28
29