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/elytra.js
Views: 789
// This example will shoot the player that said "fire" in chat, when it is said in chat.1const mineflayer = require('mineflayer')23if (process.argv.length < 4 || process.argv.length > 6) {4console.log('Usage : node elytra.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] : 'elytraer',12password: process.argv[5]13})1415bot.on('error', err => {16console.log(err)17})1819bot.on('kicked', err => {20console.log(err)21})2223bot.on('spawn', async function () {24bot.chat(`/give ${bot.username} minecraft:elytra`)25bot.chat(`/give ${bot.username} minecraft:firework_rocket 64`)2627await sleep(1000)28const elytraItem = bot.inventory.slots.find(item => item?.name === 'elytra')29if (elytraItem == null) {30console.log('no elytra')31return32}33await bot.equip(elytraItem, 'torso')34const fireworkItem = bot.inventory.slots.find(item => item?.name === 'firework_rocket')35if (fireworkItem == null) {36console.log('no fireworks')37return38}39await bot.equip(fireworkItem, 'hand')40})4142bot.on('chat', async (username, message) => {43if (message === 'fly') {44await bot.look(bot.entity.yaw, 50 * Math.PI / 180)45bot.setControlState('jump', true)46bot.setControlState('jump', false)47await sleep(50)4849// try to fly50try {51await bot.elytraFly()52} catch (err) {53bot.chat(`Failed to fly: ${err}`)54return55}56await sleep(50)5758// use rocket59bot.activateItem()60}61})6263function sleep (ms) {64return new Promise(resolve => setTimeout(resolve, ms))65}666768