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/armor_stand.js
Views: 789
/*1* This script will apply armor onto an armor stand within 4 blocks of the bot2*/3const mineflayer = require('mineflayer')45if (process.argv.length < 4 || process.argv.length > 6) {6console.log('Usage : node armor_stand.js <host> <port> [<name>] [<password>]')7process.exit(1)8}910const bot = mineflayer.createBot({11host: process.argv[2],12port: parseInt(process.argv[3]),13username: process.argv[4] ? process.argv[4] : 'armorStand',14password: process.argv[5]15})1617const armorTypes = {18helmet: [0, 1.8, 0],19chestplate: [0, 1.2, 0],20leggings: [0, 0.75, 0],21boots: [0, 0.1, 0]22}2324bot.on('chat', async (username, message) => {25const [mainCommand, subCommand] = message.split(' ')26if (mainCommand !== 'equip' && mainCommand !== 'unequip') return2728const armorStand = bot.nearestEntity(e => e.displayName === 'Armor Stand' && bot.entity.position.distanceTo(e.position) < 4)29if (!armorStand) {30bot.chat('No armor stands nearby!')31return32}3334if (mainCommand === 'equip') {35let armor = null36// parse chat37Object.keys(armorTypes).forEach(armorType => {38if (subCommand !== armorType) return39armor = bot.inventory.items().find(item => item.name.includes(armorType))40})4142if (armor === null) {43bot.chat('I have no armor items in my inventory!')44return45}4647await bot.equip(armor, 'hand')48bot.activateEntityAt(armorStand, armorStand.position)49} else if (mainCommand === 'unequip') {50await bot.unequip('hand')5152const offset = armorTypes[subCommand]53if (!offset) return5455bot.activateEntityAt(armorStand, armorStand.position.offset(...offset))56}57})585960