How to use mineflayer - 10 common examples

To help you get started, we’ve selected a few mineflayer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PrismarineJS / mineflayer / examples / inventory.js View on Github external
* now it's time to teach your bot the same skill.
 *
 * Command your bot with chat messages and make him toss, equip, use items
 * and even craft new items using the built-in recipe book.
 *
 * To learn more about the recipe system and how crafting works
 * remember to read the API documentation!
 */
const mineflayer = require('mineflayer')

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node inventory.js   [] []')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4] ? process.argv[4] : 'inventory',
  password: process.argv[5]
})

bot.on('chat', (username, message) => {
  if (username === bot.username) return
  const command = message.split(' ')
  switch (true) {
    case /^list$/.test(message):
      sayItems()
      break
    case /^toss \d+ \w+$/.test(message):
      // toss amount name
      // ex: toss 64 diamond
github Darthfett / mineflayer-blockfinder / examples / diamondFinder.js View on Github external
var mineflayer = require('mineflayer');
var blockFinderPlugin = require('..')(mineflayer);
if(process.argv.length<4 || process.argv.length>6)
{
  console.log("Usage : node diamondFinder.js   [] []");
  process.exit(1);
}
var bot = mineflayer.createBot({
  username: process.argv[4] ? process.argv[4] : "diamondFinder",
  viewDistance: "tiny",
  verbose: true,
  port:parseInt(process.argv[3]),
  host:process.argv[2],
  password:process.argv[5]
});

// Install the plugin
bot.loadPlugin(blockFinderPlugin);

// Sample usage
bot.once('spawn', function() {
  bot.findBlock({
    point: bot.entity.position,
    matching: 56,
github voxel / voxel-clientmc / clientmc.js View on Github external
this.game.plugins.disable('voxel-land');   // also provides chunks, use ours instead
  //this.game.plugins.get('voxel-player').homePosition = [-248, 77, -198] // can't do this TODO
  //this.game.plugins.get('voxel-player').moveTo -251, 81, -309

  // login credential
  var username;
  var hash = document.location.hash;
  if (hash.length < 2) {
    // try anonymous auth
    username = 'mcwebchatuserX';
  } else {
    username = hash.substring(1); // remove #
  }

  // create bot
  this.bot = mineflayer.createBot({
    username: username
  });

  this.game.voxels.on('missingChunk', this.missingChunk.bind(this));

  this.voxelChunks = {};

  // WebSocket to server proxy (wsmc)
  var self = this;
  this.bot.on('error', function(err) {
    self.log('WebSocket error', err);
    console.log('WebSocket error',err);
    self.game.plugins.disable('voxel-clientmc');
  });
  this.bot.on('close', function() {
    self.log('WebSocket closed');
github PrismarineJS / mineflayer / examples / tab_complete.js View on Github external
const mineflayer = require('mineflayer')

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node tab_complete.js   [] []')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4] ? process.argv[4] : 'tabComplete',
  password: process.argv[5]
})

bot.on('message', (cm) => {
  if (cm.toString().includes('complete')) {
    const message = cm.toString()
    const str = cm.toString().slice(message.indexOf('complete') + 9)
    complete(str)
  }
})

function complete (str) {
  bot.tabComplete(str, (err, matches) => {
github PrismarineJS / mineflayer / examples / ansi.js View on Github external
/*
 *
 * A simple bot that logs everything that is said to the console.
 *
 */
const mineflayer = require('mineflayer')

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node ansi.js   [] []')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4] ? process.argv[4] : 'ansi',
  password: process.argv[5]
})

bot.on('message', (message) => {
  console.log(message.toAnsi())
})
github PrismarineJS / mineflayer / examples / repl.js View on Github external
const mineflayer = require('mineflayer')
const repl = require('repl')

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node repl.js   [] []')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4] ? process.argv[4] : 'repl',
  password: process.argv[5]
})

bot.on('login', () => {
  const r = repl.start('> ')
  r.context.bot = bot

  r.on('exit', () => {
    bot.end()
  })
})
github PrismarineJS / mineflayer / examples / digger.js View on Github external
*
 * As always, you can send the bot commands using chat messages, and monitor
 * his inventory at any time.
 *
 * Remember that in survival mode he might not have enough dirt to get back up,
 * so be sure to teach him a few more tricks before leaving him alone at night.
 */
const mineflayer = require('mineflayer')
const vec3 = require('vec3')

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node digger.js   [] []')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4] ? process.argv[4] : 'digger',
  password: process.argv[5]
})

bot.on('chat', (username, message) => {
  if (username === bot.username) return
  switch (message) {
    case 'list':
      sayItems()
      break
    case 'dig':
      dig()
      break
    case 'build':
github PrismarineJS / mineflayer / examples / jumper.js View on Github external
/*
 * Jumping is fun. Riding pigs is even funnier!
 *
 * Learn how to make your bot interactive with this example.
 *
 * This bot can move, jump, ride vehicles, attack nearby entities and much more.
 */
const mineflayer = require('mineflayer')

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node jumper.js   [] []')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4] ? process.argv[4] : 'jumper',
  password: process.argv[5]
})

let target = null

bot.on('chat', (username, message) => {
  if (username === bot.username) return
  target = bot.players[username].entity
  let entity
  switch (message) {
    case 'forward':
      bot.setControlState('forward', true)
      break
github PrismarineJS / mineflayer / examples / book.js View on Github external
const mineflayer = require('mineflayer')

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node book.js   [] []')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4] ? process.argv[4] : 'book',
  password: process.argv[5]
})

const pages = [
  'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
  'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
  'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
].map(page => page
  .split(' ')
  .map((word, i) => ${(i % 13 + 1).toString(16)}${i % 2 ? '§l' : ''}${word}`)
  .join(' '))
github vogonistic / mineflayer-voxel / server.js View on Github external
var mineflayer = require('mineflayer');
var vec3 = mineflayer.vec3;
var navigatePlugin = require('mineflayer-navigate')(mineflayer);
var voxelPlugin = require('./mineflayer-voxel.js')(mineflayer);
var bot = mineflayer.createBot();

navigatePlugin(bot);
voxelPlugin(bot, {port: 13333});

bot.navigate.on('pathPartFound', function (path) {
  bot.chat("Going " + path.length + " meters in the general direction for now.");
});
bot.navigate.on('pathFound', function (path) {
  bot.chat("I can get there in " + path.length + " moves.");
});
bot.navigate.on('cannotFind', function () {
  bot.chat("unable to find path");
});
bot.navigate.on('arrived', function () {
  bot.chat("I have arrived");
});

mineflayer

create minecraft bots with a stable, high level API

MIT
Latest version published 8 days ago

Package Health Score

84 / 100
Full package analysis

Similar packages