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/graffiti.js
Views: 789
/*1* What's better than a bot that knows how to read and understands art?2*3* Learn how easy it is to interact with signs and paintings in this example.4*5* You can send commands to this bot using chat messages, the bot will6* reply by telling you the name of the nearest painting or the text written on7* the nearest sign, and you can also update signs with custom messages!8*9* To update a sign simply send a message in this format: write [your message]10*/11const mineflayer = require('mineflayer')1213if (process.argv.length < 4 || process.argv.length > 6) {14console.log('Usage : node graffiti.js <host> <port> [<name>] [<password>]')15process.exit(1)16}1718const bot = mineflayer.createBot({19host: process.argv[2],20port: parseInt(process.argv[3]),21username: process.argv[4] ? process.argv[4] : 'graffiti',22password: process.argv[5]23})2425bot.on('chat', (username, message) => {26if (username === bot.username) return27switch (true) {28case /^watch$/.test(message):29watchPaintingOrSign()30break31case /^write .+$/.test(message):32// write message33// ex: write I love diamonds34updateSign(message)35break36}37})3839function watchPaintingOrSign () {40const paintingBlock = bot.findBlock({41matching (block) {42return !!block.painting43}44})45const signBlock = bot.findBlock({46matching: ['painting', 'sign'].map(name => bot.registry.blocksByName[name].id)47})48if (signBlock) {49bot.chat(`The sign says: ${signBlock.signText}`)50} else if (paintingBlock) {51bot.chat(`The painting is: ${paintingBlock.painting.name}`)52} else {53bot.chat('There are no signs or paintings near me')54}55}5657function updateSign (message) {58const signBlock = bot.findBlock({59matching: ['painting', 'sign'].map(name => bot.registry.blocksByName[name].id)60})61if (signBlock) {62bot.updateSign(signBlock, message.split(' ').slice(1).join(' '))63bot.chat('Sign updated')64} else {65bot.chat('There are no signs near me')66}67}686970