/*1* This example is an easy way to connect mineflayer to the node:readline module2* See: https://nodejs.org/api/readline.html3* Using this, we can make a simple terminal-to-ingame-chat interface4*5* Made by Jovan04 01/24/20236*/78if (process.argv.length < 4 || process.argv.length > 6) {9console.log('Usage : node readline.js <host> <port> [<name>] [<auth>]')10process.exit(1)11}1213const mineflayer = require('mineflayer') // load mineflayer library14const readline = require('node:readline') // load the node.js readline module1516// bot options17const options = {18host: process.argv[2],19port: parseInt(process.argv[3]),20username: process.argv[4] || 'readline',21auth: process.argv[5] || 'offline'22}2324const bot = mineflayer.createBot(options) // join the minecraft server2526const rl = readline.createInterface({ // creates our readline interface with our console as input and output27input: process.stdin,28output: process.stdout29})3031bot.once('spawn', () => {32console.log(`Bot joined the game with username ${bot.username}.`)33rl.setPrompt('> '); rl.prompt() // gives us a little arrow at the bottom for the input line34})3536bot.on('message', (message) => {37readline.moveCursor(process.stdout, -2, 0) // we move the cursor to the left two places because our cursor is already two positions in (because of the input arrow)38console.log(message.toAnsi()) // convert our message to ansi to preserve chat formatting39rl.prompt() // regenerate our little arrow on the input line40})4142rl.on('line', (line) => {43readline.moveCursor(process.stdout, 0, -1) // move cursor up one line44readline.clearScreenDown(process.stdout) // clear all the lines below the cursor (i.e. the last line we entered)45bot.chat(line.toString()) // sends the line we entered to ingame chat46})4748bot.on('kicked', console.log)49bot.on('error', console.log)505152