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/jumper.js
Views: 789
/*1* Jumping is fun. Riding pigs is even funnier!2*3* Learn how to make your bot interactive with this example.4*5* This bot can move, jump, ride vehicles, attack nearby entities and much more.6*/7const mineflayer = require('mineflayer')89if (process.argv.length < 4 || process.argv.length > 6) {10console.log('Usage : node jumper.js <host> <port> [<name>] [<password>]')11process.exit(1)12}1314const bot = mineflayer.createBot({15host: process.argv[2],16port: parseInt(process.argv[3]),17username: process.argv[4] ? process.argv[4] : 'jumper',18password: process.argv[5]19})2021let target = null2223bot.on('chat', (username, message) => {24if (username === bot.username) return25target = bot.players[username].entity26let entity27switch (message) {28case 'forward':29bot.setControlState('forward', true)30break31case 'back':32bot.setControlState('back', true)33break34case 'left':35bot.setControlState('left', true)36break37case 'right':38bot.setControlState('right', true)39break40case 'sprint':41bot.setControlState('sprint', true)42break43case 'stop':44bot.clearControlStates()45break46case 'jump':47bot.setControlState('jump', true)48bot.setControlState('jump', false)49break50case 'jump a lot':51bot.setControlState('jump', true)52break53case 'stop jumping':54bot.setControlState('jump', false)55break56case 'attack':57entity = bot.nearestEntity()58if (entity) {59bot.attack(entity, true)60} else {61bot.chat('no nearby entities')62}63break64case 'mount':65entity = bot.nearestEntity((entity) => { return entity.name === 'minecart' })66if (entity) {67bot.mount(entity)68} else {69bot.chat('no nearby objects')70}71break72case 'dismount':73bot.dismount()74break75case 'move vehicle forward':76bot.moveVehicle(0.0, 1.0)77break78case 'move vehicle backward':79bot.moveVehicle(0.0, -1.0)80break81case 'move vehicle left':82bot.moveVehicle(1.0, 0.0)83break84case 'move vehicle right':85bot.moveVehicle(-1.0, 0.0)86break87case 'tp':88bot.entity.position.y += 1089break90case 'pos':91bot.chat(bot.entity.position.toString())92break93case 'yp':94bot.chat(`Yaw ${bot.entity.yaw}, pitch: ${bot.entity.pitch}`)95break96}97})9899bot.once('spawn', () => {100// keep your eyes on the target, so creepy!101setInterval(watchTarget, 50)102103function watchTarget () {104if (!target) return105bot.lookAt(target.position.offset(0, target.height, 0))106}107})108109bot.on('mount', () => {110bot.chat(`mounted ${bot.vehicle.displayName}`)111})112113bot.on('dismount', (vehicle) => {114bot.chat(`dismounted ${vehicle.displayName}`)115})116117118