Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/examples/collectblock.js
Views: 789
/**1* A quick and easy implementation of the collect block plugin. (Requires mineflayer-pathfinder and mineflayer-collectblock)2*/3const mineflayer = require('mineflayer')4const pathfinder = require('mineflayer-pathfinder').pathfinder5const collectBlock = require('mineflayer-collectblock').plugin67if (process.argv.length < 4 || process.argv.length > 6) {8console.log('Usage : node collectblock.js <host> <port> [<name>] [<password>]')9process.exit(1)10}1112const bot = mineflayer.createBot({13host: process.argv[2],14port: parseInt(process.argv[3]),15username: process.argv[4] ? process.argv[4] : 'collector',16password: process.argv[5]17})1819// Load pathfinder and collect block plugins20bot.loadPlugin(pathfinder)21bot.loadPlugin(collectBlock)2223// Listen for when a player says "collect [something]" in chat24bot.on('chat', (username, message) => {25const args = message.split(' ')26if (args[0] !== 'collect') return2728// Get the correct block type29const blockType = bot.registry.blocksByName[args[1]]30if (!blockType) {31bot.chat("I don't know any blocks with that name.")32return33}3435bot.chat('Collecting the nearest ' + blockType.name)3637// Try and find that block type in the world38const block = bot.findBlock({39matching: blockType.id,40maxDistance: 6441})4243if (!block) {44bot.chat("I don't see that block nearby.")45return46}4748// Collect the block if we found one49bot.collectBlock.collect(block, err => {50if (err) bot.chat(err.message)51})52})535455