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/fisherman.js
Views: 789
const mineflayer = require('mineflayer')12if (process.argv.length < 4 || process.argv.length > 6) {3console.log('Usage : node fisherman.js <host> <port> [<name>] [<password>]')4process.exit(1)5}67const bot = mineflayer.createBot({8host: process.argv[2],9port: parseInt(process.argv[3]),10username: process.argv[4] ? process.argv[4] : 'fisherman',11password: process.argv[5]12})1314// To fish we have to give bot the fishing rod and teleport bot to the water15// /give fisherman fishing_rod 116// /teleport fisherman ~ ~ ~1718// To eat we have to apply hunger first19// /effect fisherman minecraft:hunger 1 2552021bot.on('message', (cm) => {22if (cm.toString().includes('start')) {23startFishing()24}2526if (cm.toString().includes('stop')) {27stopFishing()28}2930if (cm.toString().includes('eat')) {31eat()32}33})3435let nowFishing = false3637function onCollect (player, entity) {38if (entity.kind === 'Drops' && player === bot.entity) {39bot.removeListener('playerCollect', onCollect)40startFishing()41}42}4344async function startFishing () {45bot.chat('Fishing')46try {47await bot.equip(bot.registry.itemsByName.fishing_rod.id, 'hand')48} catch (err) {49return bot.chat(err.message)50}5152nowFishing = true53bot.on('playerCollect', onCollect)5455try {56await bot.fish()57} catch (err) {58bot.chat(err.message)59}60nowFishing = false61}6263function stopFishing () {64bot.removeListener('playerCollect', onCollect)6566if (nowFishing) {67bot.activateItem()68}69}7071async function eat () {72stopFishing()7374try {75await bot.equip(bot.registry.itemsByName.fish.id, 'hand')76} catch (err) {77return bot.chat(err.message)78}7980try {81await bot.consume()82} catch (err) {83return bot.chat(err.message)84}85}868788