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/farmer.js
Views: 789
const { Vec3 } = require('vec3')1const mineflayer = require('mineflayer')23if (process.argv.length < 4 || process.argv.length > 6) {4console.log('Usage : node farmer.js <host> <port> [<name>] [<password>]')5process.exit(1)6}78const bot = mineflayer.createBot({9host: process.argv[2],10port: parseInt(process.argv[3]),11username: process.argv[4] ? process.argv[4] : 'farmer',12password: process.argv[5]13})1415// To fish we have to give bot the seeds16// /give farmer wheat_seeds 641718function blockToSow () {19return bot.findBlock({20point: bot.entity.position,21matching: bot.registry.blocksByName.farmland.id,22maxDistance: 6,23useExtraInfo: (block) => {24const blockAbove = bot.blockAt(block.position.offset(0, 1, 0))25return !blockAbove || blockAbove.type === 026}27})28}2930function blockToHarvest () {31return bot.findBlock({32point: bot.entity.position,33maxDistance: 6,34matching: (block) => {35return block && block.type === bot.registry.blocksByName.wheat.id && block.metadata === 736}37})38}3940async function loop () {41try {42while (1) {43const toHarvest = blockToHarvest()44if (toHarvest) {45await bot.dig(toHarvest)46} else {47break48}49}50while (1) {51const toSow = blockToSow()52if (toSow) {53await bot.equip(bot.registry.itemsByName.wheat_seeds.id, 'hand')54await bot.placeBlock(toSow, new Vec3(0, 1, 0))55} else {56break57}58}59} catch (e) {60console.log(e)61}6263// No block to harvest or sow. Postpone next loop a bit64setTimeout(loop, 1000)65}6667bot.once('login', loop)686970