Advertisement
acxl

code base version 1.4

Dec 11th, 2020
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 335.56 KB | None | 0 0
  1. const mineflayer = require('mineflayer', 'minecraft-protocol')
  2. const Vec3 = require('vec3').Vec3
  3. const fs = require('fs')
  4. const { version } = require('os')
  5. const pvp = require('mineflayer-pvp').plugin
  6. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  7. const armorManager = require('mineflayer-armor-manager')
  8. const autoeat = require('mineflayer-auto-eat')
  9. const minecraftHawkEye = require('minecrafthawkeye')
  10.  
  11. function jsonReader(filePath, cb) {
  12.     fs.readFile(filePath, (err, fileData) => {
  13.         if (err) {
  14.             return cb && cb(err)
  15.         }
  16.         try {
  17.             const object = JSON.parse(fileData)
  18.             return cb && cb(null, object)
  19.         } catch (err) {
  20.             return cb && cb(err)
  21.         }
  22.     })
  23. }
  24.  
  25. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  26.     if (err) {
  27.         console.log(err)
  28.         return
  29.     }
  30.  
  31.     const bot = mineflayer.createBot({
  32.         version: mc_login_info.version,
  33.         host: mc_login_info.host,
  34.         port: mc_login_info.port,
  35.         username: mc_login_info.username,
  36.         password: mc_login_info.password,
  37.         // give time for communication to hosts&client with longer ping times
  38.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  39.         logErrors: true
  40.     })
  41. })
  42.  
  43.     bot._client.on('custom_payload', (packet) => {
  44.         // console.log(packet)
  45.         if (packet.channel === "minecraft:brand") {
  46.             let data = packet.data
  47.             let brand = String.fromCharCode.apply(null, data)
  48.             console.log(brand)
  49.         }
  50.     })
  51.  
  52.     bot.once('login', () => {
  53.         console.log('logged in')
  54.         console.log(`curent client version ${bot.version}`)
  55.         // console.log(`curent server version is ${server.version}`)
  56.     })
  57.  
  58.     bot.loadPlugin(autoeat)
  59.     bot.loadPlugin(armorManager)
  60.     bot.loadPlugin(minecraftHawkEye)
  61.     bot.loadPlugin(pathfinder)
  62.     bot.loadPlugin(pvp)
  63.  
  64.    
  65.     bot.on('playerCollect', (collector, itemDrop) => {
  66.         if (collector !== bot.entity) return
  67.        
  68.         setTimeout(() => {
  69.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  70.             if (sword) bot.equip(sword, 'hand')
  71.         }, 150)
  72.     })
  73.    
  74.     bot.on('playerCollect', (collector, itemDrop) => {
  75.         if (collector !== bot.entity) return
  76.        
  77.         setTimeout(() => {
  78.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  79.             if (shield) bot.equip(shield, 'off-hand')
  80.         }, 250)
  81.     })
  82.    
  83.     let guardPos = null
  84.     let busy = false
  85.  
  86.     bot.on('spawn', () => { // gives error when bot spawns
  87.         console.log('spawned in server')
  88.         bot.hawkEye.stop()
  89.         stopGuarding()
  90.         bot.chat('I spawned, watch out!')
  91.     })
  92.    
  93.     function canSee(pos) {
  94.         const block = bot.blockAt(pos)
  95.         const r = bot.canSeeBlock(block)
  96.         if (r) {
  97.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  98.         } else {
  99.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  100.         }
  101.     }
  102.    
  103.     function sayPosition(username) {
  104.         //bot.chat(`My puplic position is disabled`)
  105.         bot.chat(`I am at ${bot.entity.position}`)
  106.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  107.         //bot.chat(`I don't know your position.`)
  108.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  109.    }
  110.  
  111.    function sayEquipment() {
  112.        const eq = bot.players[username].entity.equipment
  113.        const eqText = []
  114.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  115.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  116.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  117.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  118.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  119.        if (eqText.length) {
  120.            bot.chat(`You are ${eqText.join(', ')}.`)
  121.        } else {
  122.            bot.chat('You are without armor!')
  123.        }
  124.    }
  125.  
  126.    function sayVersion() { // work in prograss not working yet
  127.        bot.chat('/version')
  128.        console.log(`${command.message} confermed ${brand}`)
  129.    }
  130.  
  131.    function saySpawnPoint() {
  132.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  133.    }
  134.  
  135.    function sayBlockUnder() {
  136.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  137.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  138.        console.log(block)
  139.    }
  140.  
  141.    function quit(username) {
  142.        console.log('quit command used')
  143.        bot.quit(`${username} told me too`)
  144.    }
  145.  
  146.    function sayNick() {
  147.        bot.chat(`My name is ${bot.player.displayName}`)
  148.    }
  149.    
  150.    // begin of autoeats paste
  151.    bot.once('spawn', () => {
  152.        bot.autoEat.options = {
  153.            priority: 'foodPoints',
  154.            startAt: 14,
  155.            bannedFood: []
  156.        }
  157.    })
  158.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  159.    bot.on('autoeat_started', () => {
  160.        console.log('Auto Eat started!')
  161.    })
  162.  
  163.    bot.on('autoeat_stopped', () => {
  164.        console.log('Auto Eat stopped!')
  165.    })
  166.  
  167.    bot.on('health', () => {
  168.        if (bot.food === 20) bot.autoEat.disable()
  169.        // Disable the plugin if the bot is at 20 food points
  170.        else bot.autoEat.enable() // Else enable the plugin again
  171.    })
  172.    // end of paste autoeat
  173.  
  174.    bot.on('whisper', (username, message, rawMessage) => {
  175.        console.log(`I received a message from ${username}: ${message}`)
  176.        bot.whisper(username, 'I can tell secrets too.')
  177.    })
  178.  
  179.    bot.on('nonSpokenChat', (message) => {
  180.        console.log(`Non spoken chat: ${message}`)
  181.    })
  182.    
  183.    bot.on('login', () => {
  184.        bot.chat('Hi everyone!')
  185.    })
  186.    
  187.    bot.on('spawnReset', (message) => {
  188.        console.log('spawnReset command used')
  189.        stopGuarding()
  190.        bot.hawkEye.stop()
  191.        bot.chat('Oh noez! My bed is broken.')
  192.    })
  193.    
  194.    bot.on('forcedMove', () => {
  195.        console.log(`I have been forced to move to ${bot.entity.position}`)
  196.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  197.    })
  198.    
  199.    bot.on('health', () => {
  200.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  201.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  202.    })
  203.  
  204.    bot.on('death', () => {
  205.        console.log('I died, stopping and respawning')
  206.        stopGuarding()
  207.        bot.hawkEye.stop()
  208.        bot.respawn
  209.        bot.chat('I died x.x ugh!!')
  210.        // need instructions to return to
  211.        // what i was doing.
  212.    })
  213.  
  214.    bot.on('kicked', (reason) => {
  215.        console.log(`I got kicked for ${reason}`)
  216.    })
  217.    
  218.    bot.on('rain', () => {
  219.        if (bot.isRaining) {
  220.            console.log('It started raining.')
  221.            //bot.chat('It started raining.')
  222.        } else {
  223.            console.log('It stopped raining.')
  224.            //bot.chat('It stopped raining.')
  225.        }
  226.    })
  227.  
  228.    bot.on('noteHeard', (block, instrument, pitch) => {
  229.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  230.    })
  231.  
  232.    bot.on('chestLidMove', (block, isOpen) => {
  233.        const action = isOpen ? 'open' : 'close'
  234.        bot.chat(`Hey, did someone just ${action} a chest?`)
  235.    })
  236.  
  237.    bot.on('pistonMove', (block, isPulling, direction) => {
  238.        const action = isPulling ? 'pulling' : 'pushing'
  239.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  240.    })
  241.  
  242.    bot.on('playerJoined', (player) => {
  243.        if (player.username !== bot.username) {
  244.            console.log(`${player.username}! Joined the server.`)
  245.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  246.        }
  247.    })
  248.  
  249.    bot.on('playerLeft', (player) => {
  250.        if (player.username === bot.username) return
  251.        console.log(`${player.username} left the server`)
  252.        // bot.chat(`Bye ${player.username}`)
  253.    })
  254.    /*
  255.    bot.on('playerCollect', (collector, collected) => {
  256.        if (collector.type === 'player' && collected.type === 'object') {
  257.            const rawItem = collected.metadata[10]
  258.            const item = mineflayer.Item.fromNotch(rawItem)
  259.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  260.        }
  261.    })
  262.    */
  263.    /*    
  264.    bot.on('entitySpawn', (entity) => {
  265.        if (entity.type === 'mob') {
  266.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  267.        } else if (entity.type === 'player') {
  268.            console.log(`Look who decided to show up: ${entity.username}`)
  269.        } else if (entity.type === 'object') {
  270.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  271.        } else if (entity.type === 'global') {
  272.            console.log('Ooh lightning!')
  273.        } else if (entity.type === 'orb') {
  274.            console.log('Gimme dat exp orb!')
  275.        }
  276.    })
  277.    */    
  278.  
  279.    const target = bot.hawkEye.getPlayer()
  280.    console.log(target)
  281.    if (!target) {
  282.        return false
  283.    }
  284.  
  285.    function Start() {
  286.        bot.hawkEye.autoAttack(target)
  287.    }
  288.  
  289.    bot.on('entityHurt', (entity) => {
  290.        if (entity.type === 'mob') {
  291.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  292.        } else if (entity.type === 'player') {
  293.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  294.        }
  295.    })
  296.  
  297.    bot.on('entitySwingArm', (entity) => {
  298.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  299.    })
  300.  
  301.    bot.on('entityCrouch', (entity) => {
  302.        bot.chat(`${entity.username}: you so sneaky.`)
  303.    })
  304.  
  305.    bot.on('entityUncrouch', (entity) => {
  306.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  307.    })
  308.  
  309.    bot.on('entitySleep', (entity) => {
  310.        bot.chat(`Good night, ${entity.username}`)
  311.    })
  312.  
  313.    bot.on('entityWake', (entity) => {
  314.        bot.chat(`Top of the morning, ${entity.username}`)
  315.    })
  316.  
  317.    bot.on('entityEat', (entity) => {
  318.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  319.    })
  320.  
  321.    bot.on('entityAttach', (entity, vehicle) => {
  322.        if (entity.type === 'player' && vehicle.type === 'object') {
  323.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  324.        }
  325.    })
  326.  
  327.    bot.on('entityDetach', (entity, vehicle) => {
  328.        if (entity.type === 'player' && vehicle.type === 'object') {
  329.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  330.        }
  331.    })
  332.  
  333.    bot.on('entityEquipmentChange', (entity) => {
  334.        console.log('entityEquipmentChange', entity)
  335.    })
  336.  
  337.    bot.on('entityEffect', (entity, effect) => {
  338.        console.log('entityEffect', entity, effect)
  339.    })
  340.  
  341.    bot.on('entityEffectEnd', (entity, effect) => {
  342.        console.log('entityEffectEnd', entity, effect)
  343.    })
  344.  
  345.    function guardArea(pos) {
  346.        guardPos = pos.clone()
  347.        
  348.        if (!bot.pvp.target) {
  349.            moveToGuardPos()
  350.        }
  351.    }
  352.    
  353.    function stopGuarding() {
  354.        guardPos = null
  355.        bot.pvp.stop()
  356.        bot.pathfinder.setGoal(null)
  357.    }
  358.    
  359.    function moveToGuardPos() {
  360.        const mcData = require('minecraft-data')(bot.version)
  361.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  362.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  363.    }
  364.    
  365.    bot.on('stoppedAttacking', () => {
  366.        if (guardPos) {
  367.            moveToGuardPos()
  368.        }
  369.    })
  370.    
  371.    bot.on('physicTick', () => {
  372.        if (bot.pvp.target) return
  373.        if (bot.pathfinder.isMoving()) return
  374.        
  375.        const entity = bot.nearestEntity()
  376.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  377.    })
  378.    
  379.    bot.on('physicTick', () => {
  380.        if (!guardPos) return
  381.        
  382.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  383.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  384.        
  385.        const entity = bot.nearestEntity(filter)
  386.        if (entity) {
  387.            bot.pvp.attack(entity)
  388.        }
  389.    })
  390.    /*
  391.    bot.on('chat', (username, message) => {
  392.        if (username === bot.username) return
  393.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  394.        if (result) {
  395.            canSee(new Vec3(result[1], result[2], result[3]))
  396.            return
  397.        }
  398.        switch (message) {
  399.            case 'pos':
  400.                console.log("pos command used")
  401.                sayPosition(username)
  402.                break
  403.            case 'wearing':
  404.                console.log("wearing command used")
  405.                sayEquipment()
  406.                break
  407.            case 'nick':
  408.                console.log("saynick command used")
  409.                sayNick()
  410.                break
  411.            case 'spawn':
  412.                console.log("spawn command used")
  413.                saySpawnPoint()
  414.                break
  415.            case 'block':
  416.                console.log("block command used")
  417.                sayBlockUnder(username)
  418.                break
  419.            default:
  420.                console.log("I am ready!")
  421.                bot.chat("I am ready!")
  422.    }
  423.    */
  424.  
  425.    // text of bots username and help will give a list of bot commands
  426.    bot.on('chat', (username, message) => { // work in progress....
  427.        if (message === `${bot.player.displayName} help`)
  428.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  429.            bot.chat('pos, wearing, nick, spawn, block ')
  430.            bot.chat('arch-start, Version.(wip not all commands work...)')
  431.            bot.chat('Bot may just leave if it errors out.')
  432.    })
  433.  
  434.    bot.on('chat', (username, message) => { // work in progress....
  435.        if (message === 'Version') {
  436.            console.log("Version command used just used")
  437.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  438.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  439.            console.log("sayVersion command used")
  440.            sayVersion(username)
  441.            return
  442.        }
  443.    })
  444.  
  445.    bot.on('chat', (username, message) => {
  446.        if (message === 'leave') {
  447.                console.log("leave command used")
  448.                bot.chat("Yes sir right away!")
  449.                bot.quit(username)
  450.                return
  451.        }
  452.    })
  453.  
  454.    bot.on('chat', (username, message) => {
  455.        if (message === 'arch-start') {
  456.            console.log("arch-start command used")
  457.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  458.            Start()
  459.            return
  460.        }
  461.    })
  462.  
  463.    bot.on('chat', (username, message) => {
  464.        if (message === 'guard') {          // if message guard do gaurd
  465.            const player = bot.players[username]
  466.  
  467.            if (!player) {
  468.                bot.chat("I can't see you.")
  469.                return
  470.            }
  471.        bot.chat('I will guard that location.')
  472.            guardArea(player.entity.position)
  473.            }
  474.  
  475.            if (message === 'fight me') {
  476.                const player = bot.players[username]
  477.  
  478.                if (!player) {
  479.                    bot.chat("I can't see you.")
  480.                    return
  481.                }
  482.  
  483.            bot.chat('Prepare to fight!')
  484.            bot.chat('5')
  485.            bot.chat('4')
  486.            bot.chat('3')
  487.            bot.chat('2')
  488.            bot.chat('1')
  489.            bot.chat('GO!!!')
  490.            bot.pvp.attack(player.entity)
  491.            }
  492.  
  493.            if (message === 'stop') {
  494.                bot.chat('I will stop!')
  495.                bot.hawkEye.stop()
  496.                stopGuarding()
  497.            }
  498.    })
  499.  
  500.    function not_busy() {
  501.        guardPos = pos.clone()
  502.  
  503.        if (guardPos == null) {
  504.            return false
  505.        
  506.        } else { (guardPos == !null)
  507.                return true
  508.            }
  509.        }
  510.    
  511.    
  512.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  513.        if (busy == true) {
  514.        console.log("I am busy!")
  515.        bot.chat("I am busy!")
  516.            } else { if (busy == false)
  517.            console.log('I am ready!')
  518.            bot.chat('I am ready!')
  519.            }
  520.    
  521.    })
  522.  
  523.    bot.on('sleep', () => {
  524.        bot.chat('Good night!')
  525.    })
  526.  
  527.    bot.on('wake', () => {
  528.        bot.chat('Good morning!')
  529.    })
  530.  
  531.    function goToSleep() {
  532.        const bed = bot.findBlock({
  533.            matching: block => bot.isABed(block)
  534.        })
  535.        if (bed) {
  536.            bot.sleep(bed, (err) => {
  537.                if (err) {
  538.                    bot.chat(`I can't sleep: ${err.message}`)
  539.                } else {
  540.                    bot.chat("I'm sleeping")
  541.                }
  542.            })
  543.        } else {
  544.            bot.chat('No nearby bed')
  545.        }
  546.    }
  547.  
  548.    function wakeUp() {
  549.        bot.wake((err) => {
  550.            if (err) {
  551.                bot.chat(`I can't wake up: ${err.message}`)
  552.             } else {
  553.                 bot.chat('I woke up')
  554.             }
  555.         }
  556.        
  557.     )
  558. }
  559. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  560. const Vec3 = require('vec3').Vec3
  561. const fs = require('fs')
  562. const { version } = require('os')
  563. const pvp = require('mineflayer-pvp').plugin
  564. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  565. const armorManager = require('mineflayer-armor-manager')
  566. const autoeat = require('mineflayer-auto-eat')
  567. const minecraftHawkEye = require('minecrafthawkeye')
  568.  
  569. function jsonReader(filePath, cb) {
  570.     fs.readFile(filePath, (err, fileData) => {
  571.         if (err) {
  572.             return cb && cb(err)
  573.         }
  574.         try {
  575.             const object = JSON.parse(fileData)
  576.             return cb && cb(null, object)
  577.         } catch (err) {
  578.             return cb && cb(err)
  579.         }
  580.     })
  581. }
  582.  
  583. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  584.     if (err) {
  585.         console.log(err)
  586.         return
  587.     }
  588.  
  589.     const bot = mineflayer.createBot({
  590.         version: mc_login_info.version,
  591.         host: mc_login_info.host,
  592.         port: mc_login_info.port,
  593.         username: mc_login_info.username,
  594.         password: mc_login_info.password,
  595.         // give time for communication to hosts&client with longer ping times
  596.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  597.         logErrors: true
  598.     })
  599. })
  600.  
  601.     bot._client.on('custom_payload', (packet) => {
  602.         // console.log(packet)
  603.         if (packet.channel === "minecraft:brand") {
  604.             let data = packet.data
  605.             let brand = String.fromCharCode.apply(null, data)
  606.             console.log(brand)
  607.         }
  608.     })
  609.  
  610.     bot.once('login', () => {
  611.         console.log('logged in')
  612.         console.log(`curent client version ${bot.version}`)
  613.         // console.log(`curent server version is ${server.version}`)
  614.     })
  615.  
  616.     bot.loadPlugin(autoeat)
  617.     bot.loadPlugin(armorManager)
  618.     bot.loadPlugin(minecraftHawkEye)
  619.     bot.loadPlugin(pathfinder)
  620.     bot.loadPlugin(pvp)
  621.  
  622.    
  623.     bot.on('playerCollect', (collector, itemDrop) => {
  624.         if (collector !== bot.entity) return
  625.        
  626.         setTimeout(() => {
  627.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  628.             if (sword) bot.equip(sword, 'hand')
  629.         }, 150)
  630.     })
  631.    
  632.     bot.on('playerCollect', (collector, itemDrop) => {
  633.         if (collector !== bot.entity) return
  634.        
  635.         setTimeout(() => {
  636.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  637.             if (shield) bot.equip(shield, 'off-hand')
  638.         }, 250)
  639.     })
  640.    
  641.     let guardPos = null
  642.     let busy = false
  643.  
  644.     bot.on('spawn', () => { // gives error when bot spawns
  645.         console.log('spawned in server')
  646.         bot.hawkEye.stop()
  647.         stopGuarding()
  648.         bot.chat('I spawned, watch out!')
  649.     })
  650.    
  651.     function canSee(pos) {
  652.         const block = bot.blockAt(pos)
  653.         const r = bot.canSeeBlock(block)
  654.         if (r) {
  655.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  656.         } else {
  657.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  658.         }
  659.     }
  660.    
  661.     function sayPosition(username) {
  662.         //bot.chat(`My puplic position is disabled`)
  663.         bot.chat(`I am at ${bot.entity.position}`)
  664.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  665.         //bot.chat(`I don't know your position.`)
  666.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  667.    }
  668.  
  669.    function sayEquipment() {
  670.        const eq = bot.players[username].entity.equipment
  671.        const eqText = []
  672.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  673.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  674.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  675.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  676.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  677.        if (eqText.length) {
  678.            bot.chat(`You are ${eqText.join(', ')}.`)
  679.        } else {
  680.            bot.chat('You are without armor!')
  681.        }
  682.    }
  683.  
  684.    function sayVersion() { // work in prograss not working yet
  685.        bot.chat('/version')
  686.        console.log(`${command.message} confermed ${brand}`)
  687.    }
  688.  
  689.    function saySpawnPoint() {
  690.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  691.    }
  692.  
  693.    function sayBlockUnder() {
  694.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  695.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  696.        console.log(block)
  697.    }
  698.  
  699.    function quit(username) {
  700.        console.log('quit command used')
  701.        bot.quit(`${username} told me too`)
  702.    }
  703.  
  704.    function sayNick() {
  705.        bot.chat(`My name is ${bot.player.displayName}`)
  706.    }
  707.    
  708.    // begin of autoeats paste
  709.    bot.once('spawn', () => {
  710.        bot.autoEat.options = {
  711.            priority: 'foodPoints',
  712.            startAt: 14,
  713.            bannedFood: []
  714.        }
  715.    })
  716.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  717.    bot.on('autoeat_started', () => {
  718.        console.log('Auto Eat started!')
  719.    })
  720.  
  721.    bot.on('autoeat_stopped', () => {
  722.        console.log('Auto Eat stopped!')
  723.    })
  724.  
  725.    bot.on('health', () => {
  726.        if (bot.food === 20) bot.autoEat.disable()
  727.        // Disable the plugin if the bot is at 20 food points
  728.        else bot.autoEat.enable() // Else enable the plugin again
  729.    })
  730.    // end of paste autoeat
  731.  
  732.    bot.on('whisper', (username, message, rawMessage) => {
  733.        console.log(`I received a message from ${username}: ${message}`)
  734.        bot.whisper(username, 'I can tell secrets too.')
  735.    })
  736.  
  737.    bot.on('nonSpokenChat', (message) => {
  738.        console.log(`Non spoken chat: ${message}`)
  739.    })
  740.    
  741.    bot.on('login', () => {
  742.        bot.chat('Hi everyone!')
  743.    })
  744.    
  745.    bot.on('spawnReset', (message) => {
  746.        console.log('spawnReset command used')
  747.        stopGuarding()
  748.        bot.hawkEye.stop()
  749.        bot.chat('Oh noez! My bed is broken.')
  750.    })
  751.    
  752.    bot.on('forcedMove', () => {
  753.        console.log(`I have been forced to move to ${bot.entity.position}`)
  754.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  755.    })
  756.    
  757.    bot.on('health', () => {
  758.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  759.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  760.    })
  761.  
  762.    bot.on('death', () => {
  763.        console.log('I died, stopping and respawning')
  764.        stopGuarding()
  765.        bot.hawkEye.stop()
  766.        bot.respawn
  767.        bot.chat('I died x.x ugh!!')
  768.        // need instructions to return to
  769.        // what i was doing.
  770.    })
  771.  
  772.    bot.on('kicked', (reason) => {
  773.        console.log(`I got kicked for ${reason}`)
  774.    })
  775.    
  776.    bot.on('rain', () => {
  777.        if (bot.isRaining) {
  778.            console.log('It started raining.')
  779.            //bot.chat('It started raining.')
  780.        } else {
  781.            console.log('It stopped raining.')
  782.            //bot.chat('It stopped raining.')
  783.        }
  784.    })
  785.  
  786.    bot.on('noteHeard', (block, instrument, pitch) => {
  787.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  788.    })
  789.  
  790.    bot.on('chestLidMove', (block, isOpen) => {
  791.        const action = isOpen ? 'open' : 'close'
  792.        bot.chat(`Hey, did someone just ${action} a chest?`)
  793.    })
  794.  
  795.    bot.on('pistonMove', (block, isPulling, direction) => {
  796.        const action = isPulling ? 'pulling' : 'pushing'
  797.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  798.    })
  799.  
  800.    bot.on('playerJoined', (player) => {
  801.        if (player.username !== bot.username) {
  802.            console.log(`${player.username}! Joined the server.`)
  803.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  804.        }
  805.    })
  806.  
  807.    bot.on('playerLeft', (player) => {
  808.        if (player.username === bot.username) return
  809.        console.log(`${player.username} left the server`)
  810.        // bot.chat(`Bye ${player.username}`)
  811.    })
  812.    /*
  813.    bot.on('playerCollect', (collector, collected) => {
  814.        if (collector.type === 'player' && collected.type === 'object') {
  815.            const rawItem = collected.metadata[10]
  816.            const item = mineflayer.Item.fromNotch(rawItem)
  817.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  818.        }
  819.    })
  820.    */
  821.    /*    
  822.    bot.on('entitySpawn', (entity) => {
  823.        if (entity.type === 'mob') {
  824.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  825.        } else if (entity.type === 'player') {
  826.            console.log(`Look who decided to show up: ${entity.username}`)
  827.        } else if (entity.type === 'object') {
  828.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  829.        } else if (entity.type === 'global') {
  830.            console.log('Ooh lightning!')
  831.        } else if (entity.type === 'orb') {
  832.            console.log('Gimme dat exp orb!')
  833.        }
  834.    })
  835.    */    
  836.  
  837.    const target = bot.hawkEye.getPlayer()
  838.    console.log(target)
  839.    if (!target) {
  840.        return false
  841.    }
  842.  
  843.    function Start() {
  844.        bot.hawkEye.autoAttack(target)
  845.    }
  846.  
  847.    bot.on('entityHurt', (entity) => {
  848.        if (entity.type === 'mob') {
  849.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  850.        } else if (entity.type === 'player') {
  851.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  852.        }
  853.    })
  854.  
  855.    bot.on('entitySwingArm', (entity) => {
  856.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  857.    })
  858.  
  859.    bot.on('entityCrouch', (entity) => {
  860.        bot.chat(`${entity.username}: you so sneaky.`)
  861.    })
  862.  
  863.    bot.on('entityUncrouch', (entity) => {
  864.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  865.    })
  866.  
  867.    bot.on('entitySleep', (entity) => {
  868.        bot.chat(`Good night, ${entity.username}`)
  869.    })
  870.  
  871.    bot.on('entityWake', (entity) => {
  872.        bot.chat(`Top of the morning, ${entity.username}`)
  873.    })
  874.  
  875.    bot.on('entityEat', (entity) => {
  876.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  877.    })
  878.  
  879.    bot.on('entityAttach', (entity, vehicle) => {
  880.        if (entity.type === 'player' && vehicle.type === 'object') {
  881.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  882.        }
  883.    })
  884.  
  885.    bot.on('entityDetach', (entity, vehicle) => {
  886.        if (entity.type === 'player' && vehicle.type === 'object') {
  887.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  888.        }
  889.    })
  890.  
  891.    bot.on('entityEquipmentChange', (entity) => {
  892.        console.log('entityEquipmentChange', entity)
  893.    })
  894.  
  895.    bot.on('entityEffect', (entity, effect) => {
  896.        console.log('entityEffect', entity, effect)
  897.    })
  898.  
  899.    bot.on('entityEffectEnd', (entity, effect) => {
  900.        console.log('entityEffectEnd', entity, effect)
  901.    })
  902.  
  903.    function guardArea(pos) {
  904.        guardPos = pos.clone()
  905.        
  906.        if (!bot.pvp.target) {
  907.            moveToGuardPos()
  908.        }
  909.    }
  910.    
  911.    function stopGuarding() {
  912.        guardPos = null
  913.        bot.pvp.stop()
  914.        bot.pathfinder.setGoal(null)
  915.    }
  916.    
  917.    function moveToGuardPos() {
  918.        const mcData = require('minecraft-data')(bot.version)
  919.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  920.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  921.    }
  922.    
  923.    bot.on('stoppedAttacking', () => {
  924.        if (guardPos) {
  925.            moveToGuardPos()
  926.        }
  927.    })
  928.    
  929.    bot.on('physicTick', () => {
  930.        if (bot.pvp.target) return
  931.        if (bot.pathfinder.isMoving()) return
  932.        
  933.        const entity = bot.nearestEntity()
  934.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  935.    })
  936.    
  937.    bot.on('physicTick', () => {
  938.        if (!guardPos) return
  939.        
  940.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  941.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  942.        
  943.        const entity = bot.nearestEntity(filter)
  944.        if (entity) {
  945.            bot.pvp.attack(entity)
  946.        }
  947.    })
  948.    /*
  949.    bot.on('chat', (username, message) => {
  950.        if (username === bot.username) return
  951.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  952.        if (result) {
  953.            canSee(new Vec3(result[1], result[2], result[3]))
  954.            return
  955.        }
  956.        switch (message) {
  957.            case 'pos':
  958.                console.log("pos command used")
  959.                sayPosition(username)
  960.                break
  961.            case 'wearing':
  962.                console.log("wearing command used")
  963.                sayEquipment()
  964.                break
  965.            case 'nick':
  966.                console.log("saynick command used")
  967.                sayNick()
  968.                break
  969.            case 'spawn':
  970.                console.log("spawn command used")
  971.                saySpawnPoint()
  972.                break
  973.            case 'block':
  974.                console.log("block command used")
  975.                sayBlockUnder(username)
  976.                break
  977.            default:
  978.                console.log("I am ready!")
  979.                bot.chat("I am ready!")
  980.    }
  981.    */
  982.  
  983.    // text of bots username and help will give a list of bot commands
  984.    bot.on('chat', (username, message) => { // work in progress....
  985.        if (message === `${bot.player.displayName} help`)
  986.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  987.            bot.chat('pos, wearing, nick, spawn, block ')
  988.            bot.chat('arch-start, Version.(wip not all commands work...)')
  989.            bot.chat('Bot may just leave if it errors out.')
  990.    })
  991.  
  992.    bot.on('chat', (username, message) => { // work in progress....
  993.        if (message === 'Version') {
  994.            console.log("Version command used just used")
  995.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  996.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  997.            console.log("sayVersion command used")
  998.            sayVersion(username)
  999.            return
  1000.        }
  1001.    })
  1002.  
  1003.    bot.on('chat', (username, message) => {
  1004.        if (message === 'leave') {
  1005.                console.log("leave command used")
  1006.                bot.chat("Yes sir right away!")
  1007.                bot.quit(username)
  1008.                return
  1009.        }
  1010.    })
  1011.  
  1012.    bot.on('chat', (username, message) => {
  1013.        if (message === 'arch-start') {
  1014.            console.log("arch-start command used")
  1015.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  1016.            Start()
  1017.            return
  1018.        }
  1019.    })
  1020.  
  1021.    bot.on('chat', (username, message) => {
  1022.        if (message === 'guard') {          // if message guard do gaurd
  1023.            const player = bot.players[username]
  1024.  
  1025.            if (!player) {
  1026.                bot.chat("I can't see you.")
  1027.                return
  1028.            }
  1029.        bot.chat('I will guard that location.')
  1030.            guardArea(player.entity.position)
  1031.            }
  1032.  
  1033.            if (message === 'fight me') {
  1034.                const player = bot.players[username]
  1035.  
  1036.                if (!player) {
  1037.                    bot.chat("I can't see you.")
  1038.                    return
  1039.                }
  1040.  
  1041.            bot.chat('Prepare to fight!')
  1042.            bot.chat('5')
  1043.            bot.chat('4')
  1044.            bot.chat('3')
  1045.            bot.chat('2')
  1046.            bot.chat('1')
  1047.            bot.chat('GO!!!')
  1048.            bot.pvp.attack(player.entity)
  1049.            }
  1050.  
  1051.            if (message === 'stop') {
  1052.                bot.chat('I will stop!')
  1053.                bot.hawkEye.stop()
  1054.                stopGuarding()
  1055.            }
  1056.    })
  1057.  
  1058.    function not_busy() {
  1059.        guardPos = pos.clone()
  1060.  
  1061.        if (guardPos == null) {
  1062.            return false
  1063.        
  1064.        } else { (guardPos == !null)
  1065.                return true
  1066.            }
  1067.        }
  1068.    
  1069.    
  1070.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  1071.        if (busy == true) {
  1072.        console.log("I am busy!")
  1073.        bot.chat("I am busy!")
  1074.            } else { if (busy == false)
  1075.            console.log('I am ready!')
  1076.            bot.chat('I am ready!')
  1077.            }
  1078.    
  1079.    })
  1080.  
  1081.    bot.on('sleep', () => {
  1082.        bot.chat('Good night!')
  1083.    })
  1084.  
  1085.    bot.on('wake', () => {
  1086.        bot.chat('Good morning!')
  1087.    })
  1088.  
  1089.    function goToSleep() {
  1090.        const bed = bot.findBlock({
  1091.            matching: block => bot.isABed(block)
  1092.        })
  1093.        if (bed) {
  1094.            bot.sleep(bed, (err) => {
  1095.                if (err) {
  1096.                    bot.chat(`I can't sleep: ${err.message}`)
  1097.                } else {
  1098.                    bot.chat("I'm sleeping")
  1099.                }
  1100.            })
  1101.        } else {
  1102.            bot.chat('No nearby bed')
  1103.        }
  1104.    }
  1105.  
  1106.    function wakeUp() {
  1107.        bot.wake((err) => {
  1108.            if (err) {
  1109.                bot.chat(`I can't wake up: ${err.message}`)
  1110.             } else {
  1111.                 bot.chat('I woke up')
  1112.             }
  1113.         }
  1114.        
  1115.     )
  1116. }
  1117. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  1118. const Vec3 = require('vec3').Vec3
  1119. const fs = require('fs')
  1120. const { version } = require('os')
  1121. const pvp = require('mineflayer-pvp').plugin
  1122. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  1123. const armorManager = require('mineflayer-armor-manager')
  1124. const autoeat = require('mineflayer-auto-eat')
  1125. const minecraftHawkEye = require('minecrafthawkeye')
  1126.  
  1127. function jsonReader(filePath, cb) {
  1128.     fs.readFile(filePath, (err, fileData) => {
  1129.         if (err) {
  1130.             return cb && cb(err)
  1131.         }
  1132.         try {
  1133.             const object = JSON.parse(fileData)
  1134.             return cb && cb(null, object)
  1135.         } catch (err) {
  1136.             return cb && cb(err)
  1137.         }
  1138.     })
  1139. }
  1140.  
  1141. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  1142.     if (err) {
  1143.         console.log(err)
  1144.         return
  1145.     }
  1146.  
  1147.     const bot = mineflayer.createBot({
  1148.         version: mc_login_info.version,
  1149.         host: mc_login_info.host,
  1150.         port: mc_login_info.port,
  1151.         username: mc_login_info.username,
  1152.         password: mc_login_info.password,
  1153.         // give time for communication to hosts&client with longer ping times
  1154.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  1155.         logErrors: true
  1156.     })
  1157. })
  1158.  
  1159.     bot._client.on('custom_payload', (packet) => {
  1160.         // console.log(packet)
  1161.         if (packet.channel === "minecraft:brand") {
  1162.             let data = packet.data
  1163.             let brand = String.fromCharCode.apply(null, data)
  1164.             console.log(brand)
  1165.         }
  1166.     })
  1167.  
  1168.     bot.once('login', () => {
  1169.         console.log('logged in')
  1170.         console.log(`curent client version ${bot.version}`)
  1171.         // console.log(`curent server version is ${server.version}`)
  1172.     })
  1173.  
  1174.     bot.loadPlugin(autoeat)
  1175.     bot.loadPlugin(armorManager)
  1176.     bot.loadPlugin(minecraftHawkEye)
  1177.     bot.loadPlugin(pathfinder)
  1178.     bot.loadPlugin(pvp)
  1179.  
  1180.    
  1181.     bot.on('playerCollect', (collector, itemDrop) => {
  1182.         if (collector !== bot.entity) return
  1183.        
  1184.         setTimeout(() => {
  1185.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  1186.             if (sword) bot.equip(sword, 'hand')
  1187.         }, 150)
  1188.     })
  1189.    
  1190.     bot.on('playerCollect', (collector, itemDrop) => {
  1191.         if (collector !== bot.entity) return
  1192.        
  1193.         setTimeout(() => {
  1194.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  1195.             if (shield) bot.equip(shield, 'off-hand')
  1196.         }, 250)
  1197.     })
  1198.    
  1199.     let guardPos = null
  1200.     let busy = false
  1201.  
  1202.     bot.on('spawn', () => { // gives error when bot spawns
  1203.         console.log('spawned in server')
  1204.         bot.hawkEye.stop()
  1205.         stopGuarding()
  1206.         bot.chat('I spawned, watch out!')
  1207.     })
  1208.    
  1209.     function canSee(pos) {
  1210.         const block = bot.blockAt(pos)
  1211.         const r = bot.canSeeBlock(block)
  1212.         if (r) {
  1213.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  1214.         } else {
  1215.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  1216.         }
  1217.     }
  1218.    
  1219.     function sayPosition(username) {
  1220.         //bot.chat(`My puplic position is disabled`)
  1221.         bot.chat(`I am at ${bot.entity.position}`)
  1222.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  1223.         //bot.chat(`I don't know your position.`)
  1224.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  1225.    }
  1226.  
  1227.    function sayEquipment() {
  1228.        const eq = bot.players[username].entity.equipment
  1229.        const eqText = []
  1230.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  1231.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  1232.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  1233.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  1234.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  1235.        if (eqText.length) {
  1236.            bot.chat(`You are ${eqText.join(', ')}.`)
  1237.        } else {
  1238.            bot.chat('You are without armor!')
  1239.        }
  1240.    }
  1241.  
  1242.    function sayVersion() { // work in prograss not working yet
  1243.        bot.chat('/version')
  1244.        console.log(`${command.message} confermed ${brand}`)
  1245.    }
  1246.  
  1247.    function saySpawnPoint() {
  1248.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  1249.    }
  1250.  
  1251.    function sayBlockUnder() {
  1252.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  1253.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  1254.        console.log(block)
  1255.    }
  1256.  
  1257.    function quit(username) {
  1258.        console.log('quit command used')
  1259.        bot.quit(`${username} told me too`)
  1260.    }
  1261.  
  1262.    function sayNick() {
  1263.        bot.chat(`My name is ${bot.player.displayName}`)
  1264.    }
  1265.    
  1266.    // begin of autoeats paste
  1267.    bot.once('spawn', () => {
  1268.        bot.autoEat.options = {
  1269.            priority: 'foodPoints',
  1270.            startAt: 14,
  1271.            bannedFood: []
  1272.        }
  1273.    })
  1274.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  1275.    bot.on('autoeat_started', () => {
  1276.        console.log('Auto Eat started!')
  1277.    })
  1278.  
  1279.    bot.on('autoeat_stopped', () => {
  1280.        console.log('Auto Eat stopped!')
  1281.    })
  1282.  
  1283.    bot.on('health', () => {
  1284.        if (bot.food === 20) bot.autoEat.disable()
  1285.        // Disable the plugin if the bot is at 20 food points
  1286.        else bot.autoEat.enable() // Else enable the plugin again
  1287.    })
  1288.    // end of paste autoeat
  1289.  
  1290.    bot.on('whisper', (username, message, rawMessage) => {
  1291.        console.log(`I received a message from ${username}: ${message}`)
  1292.        bot.whisper(username, 'I can tell secrets too.')
  1293.    })
  1294.  
  1295.    bot.on('nonSpokenChat', (message) => {
  1296.        console.log(`Non spoken chat: ${message}`)
  1297.    })
  1298.    
  1299.    bot.on('login', () => {
  1300.        bot.chat('Hi everyone!')
  1301.    })
  1302.    
  1303.    bot.on('spawnReset', (message) => {
  1304.        console.log('spawnReset command used')
  1305.        stopGuarding()
  1306.        bot.hawkEye.stop()
  1307.        bot.chat('Oh noez! My bed is broken.')
  1308.    })
  1309.    
  1310.    bot.on('forcedMove', () => {
  1311.        console.log(`I have been forced to move to ${bot.entity.position}`)
  1312.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  1313.    })
  1314.    
  1315.    bot.on('health', () => {
  1316.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  1317.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  1318.    })
  1319.  
  1320.    bot.on('death', () => {
  1321.        console.log('I died, stopping and respawning')
  1322.        stopGuarding()
  1323.        bot.hawkEye.stop()
  1324.        bot.respawn
  1325.        bot.chat('I died x.x ugh!!')
  1326.        // need instructions to return to
  1327.        // what i was doing.
  1328.    })
  1329.  
  1330.    bot.on('kicked', (reason) => {
  1331.        console.log(`I got kicked for ${reason}`)
  1332.    })
  1333.    
  1334.    bot.on('rain', () => {
  1335.        if (bot.isRaining) {
  1336.            console.log('It started raining.')
  1337.            //bot.chat('It started raining.')
  1338.        } else {
  1339.            console.log('It stopped raining.')
  1340.            //bot.chat('It stopped raining.')
  1341.        }
  1342.    })
  1343.  
  1344.    bot.on('noteHeard', (block, instrument, pitch) => {
  1345.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  1346.    })
  1347.  
  1348.    bot.on('chestLidMove', (block, isOpen) => {
  1349.        const action = isOpen ? 'open' : 'close'
  1350.        bot.chat(`Hey, did someone just ${action} a chest?`)
  1351.    })
  1352.  
  1353.    bot.on('pistonMove', (block, isPulling, direction) => {
  1354.        const action = isPulling ? 'pulling' : 'pushing'
  1355.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  1356.    })
  1357.  
  1358.    bot.on('playerJoined', (player) => {
  1359.        if (player.username !== bot.username) {
  1360.            console.log(`${player.username}! Joined the server.`)
  1361.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  1362.        }
  1363.    })
  1364.  
  1365.    bot.on('playerLeft', (player) => {
  1366.        if (player.username === bot.username) return
  1367.        console.log(`${player.username} left the server`)
  1368.        // bot.chat(`Bye ${player.username}`)
  1369.    })
  1370.    /*
  1371.    bot.on('playerCollect', (collector, collected) => {
  1372.        if (collector.type === 'player' && collected.type === 'object') {
  1373.            const rawItem = collected.metadata[10]
  1374.            const item = mineflayer.Item.fromNotch(rawItem)
  1375.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  1376.        }
  1377.    })
  1378.    */
  1379.    /*    
  1380.    bot.on('entitySpawn', (entity) => {
  1381.        if (entity.type === 'mob') {
  1382.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  1383.        } else if (entity.type === 'player') {
  1384.            console.log(`Look who decided to show up: ${entity.username}`)
  1385.        } else if (entity.type === 'object') {
  1386.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  1387.        } else if (entity.type === 'global') {
  1388.            console.log('Ooh lightning!')
  1389.        } else if (entity.type === 'orb') {
  1390.            console.log('Gimme dat exp orb!')
  1391.        }
  1392.    })
  1393.    */    
  1394.  
  1395.    const target = bot.hawkEye.getPlayer()
  1396.    console.log(target)
  1397.    if (!target) {
  1398.        return false
  1399.    }
  1400.  
  1401.    function Start() {
  1402.        bot.hawkEye.autoAttack(target)
  1403.    }
  1404.  
  1405.    bot.on('entityHurt', (entity) => {
  1406.        if (entity.type === 'mob') {
  1407.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  1408.        } else if (entity.type === 'player') {
  1409.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  1410.        }
  1411.    })
  1412.  
  1413.    bot.on('entitySwingArm', (entity) => {
  1414.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  1415.    })
  1416.  
  1417.    bot.on('entityCrouch', (entity) => {
  1418.        bot.chat(`${entity.username}: you so sneaky.`)
  1419.    })
  1420.  
  1421.    bot.on('entityUncrouch', (entity) => {
  1422.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  1423.    })
  1424.  
  1425.    bot.on('entitySleep', (entity) => {
  1426.        bot.chat(`Good night, ${entity.username}`)
  1427.    })
  1428.  
  1429.    bot.on('entityWake', (entity) => {
  1430.        bot.chat(`Top of the morning, ${entity.username}`)
  1431.    })
  1432.  
  1433.    bot.on('entityEat', (entity) => {
  1434.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  1435.    })
  1436.  
  1437.    bot.on('entityAttach', (entity, vehicle) => {
  1438.        if (entity.type === 'player' && vehicle.type === 'object') {
  1439.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  1440.        }
  1441.    })
  1442.  
  1443.    bot.on('entityDetach', (entity, vehicle) => {
  1444.        if (entity.type === 'player' && vehicle.type === 'object') {
  1445.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  1446.        }
  1447.    })
  1448.  
  1449.    bot.on('entityEquipmentChange', (entity) => {
  1450.        console.log('entityEquipmentChange', entity)
  1451.    })
  1452.  
  1453.    bot.on('entityEffect', (entity, effect) => {
  1454.        console.log('entityEffect', entity, effect)
  1455.    })
  1456.  
  1457.    bot.on('entityEffectEnd', (entity, effect) => {
  1458.        console.log('entityEffectEnd', entity, effect)
  1459.    })
  1460.  
  1461.    function guardArea(pos) {
  1462.        guardPos = pos.clone()
  1463.        
  1464.        if (!bot.pvp.target) {
  1465.            moveToGuardPos()
  1466.        }
  1467.    }
  1468.    
  1469.    function stopGuarding() {
  1470.        guardPos = null
  1471.        bot.pvp.stop()
  1472.        bot.pathfinder.setGoal(null)
  1473.    }
  1474.    
  1475.    function moveToGuardPos() {
  1476.        const mcData = require('minecraft-data')(bot.version)
  1477.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  1478.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  1479.    }
  1480.    
  1481.    bot.on('stoppedAttacking', () => {
  1482.        if (guardPos) {
  1483.            moveToGuardPos()
  1484.        }
  1485.    })
  1486.    
  1487.    bot.on('physicTick', () => {
  1488.        if (bot.pvp.target) return
  1489.        if (bot.pathfinder.isMoving()) return
  1490.        
  1491.        const entity = bot.nearestEntity()
  1492.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  1493.    })
  1494.    
  1495.    bot.on('physicTick', () => {
  1496.        if (!guardPos) return
  1497.        
  1498.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  1499.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  1500.        
  1501.        const entity = bot.nearestEntity(filter)
  1502.        if (entity) {
  1503.            bot.pvp.attack(entity)
  1504.        }
  1505.    })
  1506.    /*
  1507.    bot.on('chat', (username, message) => {
  1508.        if (username === bot.username) return
  1509.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  1510.        if (result) {
  1511.            canSee(new Vec3(result[1], result[2], result[3]))
  1512.            return
  1513.        }
  1514.        switch (message) {
  1515.            case 'pos':
  1516.                console.log("pos command used")
  1517.                sayPosition(username)
  1518.                break
  1519.            case 'wearing':
  1520.                console.log("wearing command used")
  1521.                sayEquipment()
  1522.                break
  1523.            case 'nick':
  1524.                console.log("saynick command used")
  1525.                sayNick()
  1526.                break
  1527.            case 'spawn':
  1528.                console.log("spawn command used")
  1529.                saySpawnPoint()
  1530.                break
  1531.            case 'block':
  1532.                console.log("block command used")
  1533.                sayBlockUnder(username)
  1534.                break
  1535.            default:
  1536.                console.log("I am ready!")
  1537.                bot.chat("I am ready!")
  1538.    }
  1539.    */
  1540.  
  1541.    // text of bots username and help will give a list of bot commands
  1542.    bot.on('chat', (username, message) => { // work in progress....
  1543.        if (message === `${bot.player.displayName} help`)
  1544.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  1545.            bot.chat('pos, wearing, nick, spawn, block ')
  1546.            bot.chat('arch-start, Version.(wip not all commands work...)')
  1547.            bot.chat('Bot may just leave if it errors out.')
  1548.    })
  1549.  
  1550.    bot.on('chat', (username, message) => { // work in progress....
  1551.        if (message === 'Version') {
  1552.            console.log("Version command used just used")
  1553.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  1554.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  1555.            console.log("sayVersion command used")
  1556.            sayVersion(username)
  1557.            return
  1558.        }
  1559.    })
  1560.  
  1561.    bot.on('chat', (username, message) => {
  1562.        if (message === 'leave') {
  1563.                console.log("leave command used")
  1564.                bot.chat("Yes sir right away!")
  1565.                bot.quit(username)
  1566.                return
  1567.        }
  1568.    })
  1569.  
  1570.    bot.on('chat', (username, message) => {
  1571.        if (message === 'arch-start') {
  1572.            console.log("arch-start command used")
  1573.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  1574.            Start()
  1575.            return
  1576.        }
  1577.    })
  1578.  
  1579.    bot.on('chat', (username, message) => {
  1580.        if (message === 'guard') {          // if message guard do gaurd
  1581.            const player = bot.players[username]
  1582.  
  1583.            if (!player) {
  1584.                bot.chat("I can't see you.")
  1585.                return
  1586.            }
  1587.        bot.chat('I will guard that location.')
  1588.            guardArea(player.entity.position)
  1589.            }
  1590.  
  1591.            if (message === 'fight me') {
  1592.                const player = bot.players[username]
  1593.  
  1594.                if (!player) {
  1595.                    bot.chat("I can't see you.")
  1596.                    return
  1597.                }
  1598.  
  1599.            bot.chat('Prepare to fight!')
  1600.            bot.chat('5')
  1601.            bot.chat('4')
  1602.            bot.chat('3')
  1603.            bot.chat('2')
  1604.            bot.chat('1')
  1605.            bot.chat('GO!!!')
  1606.            bot.pvp.attack(player.entity)
  1607.            }
  1608.  
  1609.            if (message === 'stop') {
  1610.                bot.chat('I will stop!')
  1611.                bot.hawkEye.stop()
  1612.                stopGuarding()
  1613.            }
  1614.    })
  1615.  
  1616.    function not_busy() {
  1617.        guardPos = pos.clone()
  1618.  
  1619.        if (guardPos == null) {
  1620.            return false
  1621.        
  1622.        } else { (guardPos == !null)
  1623.                return true
  1624.            }
  1625.        }
  1626.    
  1627.    
  1628.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  1629.        if (busy == true) {
  1630.        console.log("I am busy!")
  1631.        bot.chat("I am busy!")
  1632.            } else { if (busy == false)
  1633.            console.log('I am ready!')
  1634.            bot.chat('I am ready!')
  1635.            }
  1636.    
  1637.    })
  1638.  
  1639.    bot.on('sleep', () => {
  1640.        bot.chat('Good night!')
  1641.    })
  1642.  
  1643.    bot.on('wake', () => {
  1644.        bot.chat('Good morning!')
  1645.    })
  1646.  
  1647.    function goToSleep() {
  1648.        const bed = bot.findBlock({
  1649.            matching: block => bot.isABed(block)
  1650.        })
  1651.        if (bed) {
  1652.            bot.sleep(bed, (err) => {
  1653.                if (err) {
  1654.                    bot.chat(`I can't sleep: ${err.message}`)
  1655.                } else {
  1656.                    bot.chat("I'm sleeping")
  1657.                }
  1658.            })
  1659.        } else {
  1660.            bot.chat('No nearby bed')
  1661.        }
  1662.    }
  1663.  
  1664.    function wakeUp() {
  1665.        bot.wake((err) => {
  1666.            if (err) {
  1667.                bot.chat(`I can't wake up: ${err.message}`)
  1668.             } else {
  1669.                 bot.chat('I woke up')
  1670.             }
  1671.         }
  1672.        
  1673.     )
  1674. }
  1675. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  1676. const Vec3 = require('vec3').Vec3
  1677. const fs = require('fs')
  1678. const { version } = require('os')
  1679. const pvp = require('mineflayer-pvp').plugin
  1680. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  1681. const armorManager = require('mineflayer-armor-manager')
  1682. const autoeat = require('mineflayer-auto-eat')
  1683. const minecraftHawkEye = require('minecrafthawkeye')
  1684.  
  1685. function jsonReader(filePath, cb) {
  1686.     fs.readFile(filePath, (err, fileData) => {
  1687.         if (err) {
  1688.             return cb && cb(err)
  1689.         }
  1690.         try {
  1691.             const object = JSON.parse(fileData)
  1692.             return cb && cb(null, object)
  1693.         } catch (err) {
  1694.             return cb && cb(err)
  1695.         }
  1696.     })
  1697. }
  1698.  
  1699. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  1700.     if (err) {
  1701.         console.log(err)
  1702.         return
  1703.     }
  1704.  
  1705.     const bot = mineflayer.createBot({
  1706.         version: mc_login_info.version,
  1707.         host: mc_login_info.host,
  1708.         port: mc_login_info.port,
  1709.         username: mc_login_info.username,
  1710.         password: mc_login_info.password,
  1711.         // give time for communication to hosts&client with longer ping times
  1712.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  1713.         logErrors: true
  1714.     })
  1715. })
  1716.  
  1717.     bot._client.on('custom_payload', (packet) => {
  1718.         // console.log(packet)
  1719.         if (packet.channel === "minecraft:brand") {
  1720.             let data = packet.data
  1721.             let brand = String.fromCharCode.apply(null, data)
  1722.             console.log(brand)
  1723.         }
  1724.     })
  1725.  
  1726.     bot.once('login', () => {
  1727.         console.log('logged in')
  1728.         console.log(`curent client version ${bot.version}`)
  1729.         // console.log(`curent server version is ${server.version}`)
  1730.     })
  1731.  
  1732.     bot.loadPlugin(autoeat)
  1733.     bot.loadPlugin(armorManager)
  1734.     bot.loadPlugin(minecraftHawkEye)
  1735.     bot.loadPlugin(pathfinder)
  1736.     bot.loadPlugin(pvp)
  1737.  
  1738.    
  1739.     bot.on('playerCollect', (collector, itemDrop) => {
  1740.         if (collector !== bot.entity) return
  1741.        
  1742.         setTimeout(() => {
  1743.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  1744.             if (sword) bot.equip(sword, 'hand')
  1745.         }, 150)
  1746.     })
  1747.    
  1748.     bot.on('playerCollect', (collector, itemDrop) => {
  1749.         if (collector !== bot.entity) return
  1750.        
  1751.         setTimeout(() => {
  1752.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  1753.             if (shield) bot.equip(shield, 'off-hand')
  1754.         }, 250)
  1755.     })
  1756.    
  1757.     let guardPos = null
  1758.     let busy = false
  1759.  
  1760.     bot.on('spawn', () => { // gives error when bot spawns
  1761.         console.log('spawned in server')
  1762.         bot.hawkEye.stop()
  1763.         stopGuarding()
  1764.         bot.chat('I spawned, watch out!')
  1765.     })
  1766.    
  1767.     function canSee(pos) {
  1768.         const block = bot.blockAt(pos)
  1769.         const r = bot.canSeeBlock(block)
  1770.         if (r) {
  1771.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  1772.         } else {
  1773.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  1774.         }
  1775.     }
  1776.    
  1777.     function sayPosition(username) {
  1778.         //bot.chat(`My puplic position is disabled`)
  1779.         bot.chat(`I am at ${bot.entity.position}`)
  1780.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  1781.         //bot.chat(`I don't know your position.`)
  1782.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  1783.    }
  1784.  
  1785.    function sayEquipment() {
  1786.        const eq = bot.players[username].entity.equipment
  1787.        const eqText = []
  1788.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  1789.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  1790.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  1791.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  1792.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  1793.        if (eqText.length) {
  1794.            bot.chat(`You are ${eqText.join(', ')}.`)
  1795.        } else {
  1796.            bot.chat('You are without armor!')
  1797.        }
  1798.    }
  1799.  
  1800.    function sayVersion() { // work in prograss not working yet
  1801.        bot.chat('/version')
  1802.        console.log(`${command.message} confermed ${brand}`)
  1803.    }
  1804.  
  1805.    function saySpawnPoint() {
  1806.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  1807.    }
  1808.  
  1809.    function sayBlockUnder() {
  1810.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  1811.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  1812.        console.log(block)
  1813.    }
  1814.  
  1815.    function quit(username) {
  1816.        console.log('quit command used')
  1817.        bot.quit(`${username} told me too`)
  1818.    }
  1819.  
  1820.    function sayNick() {
  1821.        bot.chat(`My name is ${bot.player.displayName}`)
  1822.    }
  1823.    
  1824.    // begin of autoeats paste
  1825.    bot.once('spawn', () => {
  1826.        bot.autoEat.options = {
  1827.            priority: 'foodPoints',
  1828.            startAt: 14,
  1829.            bannedFood: []
  1830.        }
  1831.    })
  1832.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  1833.    bot.on('autoeat_started', () => {
  1834.        console.log('Auto Eat started!')
  1835.    })
  1836.  
  1837.    bot.on('autoeat_stopped', () => {
  1838.        console.log('Auto Eat stopped!')
  1839.    })
  1840.  
  1841.    bot.on('health', () => {
  1842.        if (bot.food === 20) bot.autoEat.disable()
  1843.        // Disable the plugin if the bot is at 20 food points
  1844.        else bot.autoEat.enable() // Else enable the plugin again
  1845.    })
  1846.    // end of paste autoeat
  1847.  
  1848.    bot.on('whisper', (username, message, rawMessage) => {
  1849.        console.log(`I received a message from ${username}: ${message}`)
  1850.        bot.whisper(username, 'I can tell secrets too.')
  1851.    })
  1852.  
  1853.    bot.on('nonSpokenChat', (message) => {
  1854.        console.log(`Non spoken chat: ${message}`)
  1855.    })
  1856.    
  1857.    bot.on('login', () => {
  1858.        bot.chat('Hi everyone!')
  1859.    })
  1860.    
  1861.    bot.on('spawnReset', (message) => {
  1862.        console.log('spawnReset command used')
  1863.        stopGuarding()
  1864.        bot.hawkEye.stop()
  1865.        bot.chat('Oh noez! My bed is broken.')
  1866.    })
  1867.    
  1868.    bot.on('forcedMove', () => {
  1869.        console.log(`I have been forced to move to ${bot.entity.position}`)
  1870.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  1871.    })
  1872.    
  1873.    bot.on('health', () => {
  1874.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  1875.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  1876.    })
  1877.  
  1878.    bot.on('death', () => {
  1879.        console.log('I died, stopping and respawning')
  1880.        stopGuarding()
  1881.        bot.hawkEye.stop()
  1882.        bot.respawn
  1883.        bot.chat('I died x.x ugh!!')
  1884.        // need instructions to return to
  1885.        // what i was doing.
  1886.    })
  1887.  
  1888.    bot.on('kicked', (reason) => {
  1889.        console.log(`I got kicked for ${reason}`)
  1890.    })
  1891.    
  1892.    bot.on('rain', () => {
  1893.        if (bot.isRaining) {
  1894.            console.log('It started raining.')
  1895.            //bot.chat('It started raining.')
  1896.        } else {
  1897.            console.log('It stopped raining.')
  1898.            //bot.chat('It stopped raining.')
  1899.        }
  1900.    })
  1901.  
  1902.    bot.on('noteHeard', (block, instrument, pitch) => {
  1903.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  1904.    })
  1905.  
  1906.    bot.on('chestLidMove', (block, isOpen) => {
  1907.        const action = isOpen ? 'open' : 'close'
  1908.        bot.chat(`Hey, did someone just ${action} a chest?`)
  1909.    })
  1910.  
  1911.    bot.on('pistonMove', (block, isPulling, direction) => {
  1912.        const action = isPulling ? 'pulling' : 'pushing'
  1913.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  1914.    })
  1915.  
  1916.    bot.on('playerJoined', (player) => {
  1917.        if (player.username !== bot.username) {
  1918.            console.log(`${player.username}! Joined the server.`)
  1919.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  1920.        }
  1921.    })
  1922.  
  1923.    bot.on('playerLeft', (player) => {
  1924.        if (player.username === bot.username) return
  1925.        console.log(`${player.username} left the server`)
  1926.        // bot.chat(`Bye ${player.username}`)
  1927.    })
  1928.    /*
  1929.    bot.on('playerCollect', (collector, collected) => {
  1930.        if (collector.type === 'player' && collected.type === 'object') {
  1931.            const rawItem = collected.metadata[10]
  1932.            const item = mineflayer.Item.fromNotch(rawItem)
  1933.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  1934.        }
  1935.    })
  1936.    */
  1937.    /*    
  1938.    bot.on('entitySpawn', (entity) => {
  1939.        if (entity.type === 'mob') {
  1940.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  1941.        } else if (entity.type === 'player') {
  1942.            console.log(`Look who decided to show up: ${entity.username}`)
  1943.        } else if (entity.type === 'object') {
  1944.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  1945.        } else if (entity.type === 'global') {
  1946.            console.log('Ooh lightning!')
  1947.        } else if (entity.type === 'orb') {
  1948.            console.log('Gimme dat exp orb!')
  1949.        }
  1950.    })
  1951.    */    
  1952.  
  1953.    const target = bot.hawkEye.getPlayer()
  1954.    console.log(target)
  1955.    if (!target) {
  1956.        return false
  1957.    }
  1958.  
  1959.    function Start() {
  1960.        bot.hawkEye.autoAttack(target)
  1961.    }
  1962.  
  1963.    bot.on('entityHurt', (entity) => {
  1964.        if (entity.type === 'mob') {
  1965.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  1966.        } else if (entity.type === 'player') {
  1967.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  1968.        }
  1969.    })
  1970.  
  1971.    bot.on('entitySwingArm', (entity) => {
  1972.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  1973.    })
  1974.  
  1975.    bot.on('entityCrouch', (entity) => {
  1976.        bot.chat(`${entity.username}: you so sneaky.`)
  1977.    })
  1978.  
  1979.    bot.on('entityUncrouch', (entity) => {
  1980.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  1981.    })
  1982.  
  1983.    bot.on('entitySleep', (entity) => {
  1984.        bot.chat(`Good night, ${entity.username}`)
  1985.    })
  1986.  
  1987.    bot.on('entityWake', (entity) => {
  1988.        bot.chat(`Top of the morning, ${entity.username}`)
  1989.    })
  1990.  
  1991.    bot.on('entityEat', (entity) => {
  1992.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  1993.    })
  1994.  
  1995.    bot.on('entityAttach', (entity, vehicle) => {
  1996.        if (entity.type === 'player' && vehicle.type === 'object') {
  1997.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  1998.        }
  1999.    })
  2000.  
  2001.    bot.on('entityDetach', (entity, vehicle) => {
  2002.        if (entity.type === 'player' && vehicle.type === 'object') {
  2003.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  2004.        }
  2005.    })
  2006.  
  2007.    bot.on('entityEquipmentChange', (entity) => {
  2008.        console.log('entityEquipmentChange', entity)
  2009.    })
  2010.  
  2011.    bot.on('entityEffect', (entity, effect) => {
  2012.        console.log('entityEffect', entity, effect)
  2013.    })
  2014.  
  2015.    bot.on('entityEffectEnd', (entity, effect) => {
  2016.        console.log('entityEffectEnd', entity, effect)
  2017.    })
  2018.  
  2019.    function guardArea(pos) {
  2020.        guardPos = pos.clone()
  2021.        
  2022.        if (!bot.pvp.target) {
  2023.            moveToGuardPos()
  2024.        }
  2025.    }
  2026.    
  2027.    function stopGuarding() {
  2028.        guardPos = null
  2029.        bot.pvp.stop()
  2030.        bot.pathfinder.setGoal(null)
  2031.    }
  2032.    
  2033.    function moveToGuardPos() {
  2034.        const mcData = require('minecraft-data')(bot.version)
  2035.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  2036.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  2037.    }
  2038.    
  2039.    bot.on('stoppedAttacking', () => {
  2040.        if (guardPos) {
  2041.            moveToGuardPos()
  2042.        }
  2043.    })
  2044.    
  2045.    bot.on('physicTick', () => {
  2046.        if (bot.pvp.target) return
  2047.        if (bot.pathfinder.isMoving()) return
  2048.        
  2049.        const entity = bot.nearestEntity()
  2050.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  2051.    })
  2052.    
  2053.    bot.on('physicTick', () => {
  2054.        if (!guardPos) return
  2055.        
  2056.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  2057.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  2058.        
  2059.        const entity = bot.nearestEntity(filter)
  2060.        if (entity) {
  2061.            bot.pvp.attack(entity)
  2062.        }
  2063.    })
  2064.    /*
  2065.    bot.on('chat', (username, message) => {
  2066.        if (username === bot.username) return
  2067.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  2068.        if (result) {
  2069.            canSee(new Vec3(result[1], result[2], result[3]))
  2070.            return
  2071.        }
  2072.        switch (message) {
  2073.            case 'pos':
  2074.                console.log("pos command used")
  2075.                sayPosition(username)
  2076.                break
  2077.            case 'wearing':
  2078.                console.log("wearing command used")
  2079.                sayEquipment()
  2080.                break
  2081.            case 'nick':
  2082.                console.log("saynick command used")
  2083.                sayNick()
  2084.                break
  2085.            case 'spawn':
  2086.                console.log("spawn command used")
  2087.                saySpawnPoint()
  2088.                break
  2089.            case 'block':
  2090.                console.log("block command used")
  2091.                sayBlockUnder(username)
  2092.                break
  2093.            default:
  2094.                console.log("I am ready!")
  2095.                bot.chat("I am ready!")
  2096.    }
  2097.    */
  2098.  
  2099.    // text of bots username and help will give a list of bot commands
  2100.    bot.on('chat', (username, message) => { // work in progress....
  2101.        if (message === `${bot.player.displayName} help`)
  2102.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  2103.            bot.chat('pos, wearing, nick, spawn, block ')
  2104.            bot.chat('arch-start, Version.(wip not all commands work...)')
  2105.            bot.chat('Bot may just leave if it errors out.')
  2106.    })
  2107.  
  2108.    bot.on('chat', (username, message) => { // work in progress....
  2109.        if (message === 'Version') {
  2110.            console.log("Version command used just used")
  2111.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  2112.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  2113.            console.log("sayVersion command used")
  2114.            sayVersion(username)
  2115.            return
  2116.        }
  2117.    })
  2118.  
  2119.    bot.on('chat', (username, message) => {
  2120.        if (message === 'leave') {
  2121.                console.log("leave command used")
  2122.                bot.chat("Yes sir right away!")
  2123.                bot.quit(username)
  2124.                return
  2125.        }
  2126.    })
  2127.  
  2128.    bot.on('chat', (username, message) => {
  2129.        if (message === 'arch-start') {
  2130.            console.log("arch-start command used")
  2131.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  2132.            Start()
  2133.            return
  2134.        }
  2135.    })
  2136.  
  2137.    bot.on('chat', (username, message) => {
  2138.        if (message === 'guard') {          // if message guard do gaurd
  2139.            const player = bot.players[username]
  2140.  
  2141.            if (!player) {
  2142.                bot.chat("I can't see you.")
  2143.                return
  2144.            }
  2145.        bot.chat('I will guard that location.')
  2146.            guardArea(player.entity.position)
  2147.            }
  2148.  
  2149.            if (message === 'fight me') {
  2150.                const player = bot.players[username]
  2151.  
  2152.                if (!player) {
  2153.                    bot.chat("I can't see you.")
  2154.                    return
  2155.                }
  2156.  
  2157.            bot.chat('Prepare to fight!')
  2158.            bot.chat('5')
  2159.            bot.chat('4')
  2160.            bot.chat('3')
  2161.            bot.chat('2')
  2162.            bot.chat('1')
  2163.            bot.chat('GO!!!')
  2164.            bot.pvp.attack(player.entity)
  2165.            }
  2166.  
  2167.            if (message === 'stop') {
  2168.                bot.chat('I will stop!')
  2169.                bot.hawkEye.stop()
  2170.                stopGuarding()
  2171.            }
  2172.    })
  2173.  
  2174.    function not_busy() {
  2175.        guardPos = pos.clone()
  2176.  
  2177.        if (guardPos == null) {
  2178.            return false
  2179.        
  2180.        } else { (guardPos == !null)
  2181.                return true
  2182.            }
  2183.        }
  2184.    
  2185.    
  2186.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  2187.        if (busy == true) {
  2188.        console.log("I am busy!")
  2189.        bot.chat("I am busy!")
  2190.            } else { if (busy == false)
  2191.            console.log('I am ready!')
  2192.            bot.chat('I am ready!')
  2193.            }
  2194.    
  2195.    })
  2196.  
  2197.    bot.on('sleep', () => {
  2198.        bot.chat('Good night!')
  2199.    })
  2200.  
  2201.    bot.on('wake', () => {
  2202.        bot.chat('Good morning!')
  2203.    })
  2204.  
  2205.    function goToSleep() {
  2206.        const bed = bot.findBlock({
  2207.            matching: block => bot.isABed(block)
  2208.        })
  2209.        if (bed) {
  2210.            bot.sleep(bed, (err) => {
  2211.                if (err) {
  2212.                    bot.chat(`I can't sleep: ${err.message}`)
  2213.                } else {
  2214.                    bot.chat("I'm sleeping")
  2215.                }
  2216.            })
  2217.        } else {
  2218.            bot.chat('No nearby bed')
  2219.        }
  2220.    }
  2221.  
  2222.    function wakeUp() {
  2223.        bot.wake((err) => {
  2224.            if (err) {
  2225.                bot.chat(`I can't wake up: ${err.message}`)
  2226.             } else {
  2227.                 bot.chat('I woke up')
  2228.             }
  2229.         }
  2230.        
  2231.     )
  2232. }
  2233. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  2234. const Vec3 = require('vec3').Vec3
  2235. const fs = require('fs')
  2236. const { version } = require('os')
  2237. const pvp = require('mineflayer-pvp').plugin
  2238. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  2239. const armorManager = require('mineflayer-armor-manager')
  2240. const autoeat = require('mineflayer-auto-eat')
  2241. const minecraftHawkEye = require('minecrafthawkeye')
  2242.  
  2243. function jsonReader(filePath, cb) {
  2244.     fs.readFile(filePath, (err, fileData) => {
  2245.         if (err) {
  2246.             return cb && cb(err)
  2247.         }
  2248.         try {
  2249.             const object = JSON.parse(fileData)
  2250.             return cb && cb(null, object)
  2251.         } catch (err) {
  2252.             return cb && cb(err)
  2253.         }
  2254.     })
  2255. }
  2256.  
  2257. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  2258.     if (err) {
  2259.         console.log(err)
  2260.         return
  2261.     }
  2262.  
  2263.     const bot = mineflayer.createBot({
  2264.         version: mc_login_info.version,
  2265.         host: mc_login_info.host,
  2266.         port: mc_login_info.port,
  2267.         username: mc_login_info.username,
  2268.         password: mc_login_info.password,
  2269.         // give time for communication to hosts&client with longer ping times
  2270.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  2271.         logErrors: true
  2272.     })
  2273. })
  2274.  
  2275.     bot._client.on('custom_payload', (packet) => {
  2276.         // console.log(packet)
  2277.         if (packet.channel === "minecraft:brand") {
  2278.             let data = packet.data
  2279.             let brand = String.fromCharCode.apply(null, data)
  2280.             console.log(brand)
  2281.         }
  2282.     })
  2283.  
  2284.     bot.once('login', () => {
  2285.         console.log('logged in')
  2286.         console.log(`curent client version ${bot.version}`)
  2287.         // console.log(`curent server version is ${server.version}`)
  2288.     })
  2289.  
  2290.     bot.loadPlugin(autoeat)
  2291.     bot.loadPlugin(armorManager)
  2292.     bot.loadPlugin(minecraftHawkEye)
  2293.     bot.loadPlugin(pathfinder)
  2294.     bot.loadPlugin(pvp)
  2295.  
  2296.    
  2297.     bot.on('playerCollect', (collector, itemDrop) => {
  2298.         if (collector !== bot.entity) return
  2299.        
  2300.         setTimeout(() => {
  2301.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  2302.             if (sword) bot.equip(sword, 'hand')
  2303.         }, 150)
  2304.     })
  2305.    
  2306.     bot.on('playerCollect', (collector, itemDrop) => {
  2307.         if (collector !== bot.entity) return
  2308.        
  2309.         setTimeout(() => {
  2310.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  2311.             if (shield) bot.equip(shield, 'off-hand')
  2312.         }, 250)
  2313.     })
  2314.    
  2315.     let guardPos = null
  2316.     let busy = false
  2317.  
  2318.     bot.on('spawn', () => { // gives error when bot spawns
  2319.         console.log('spawned in server')
  2320.         bot.hawkEye.stop()
  2321.         stopGuarding()
  2322.         bot.chat('I spawned, watch out!')
  2323.     })
  2324.    
  2325.     function canSee(pos) {
  2326.         const block = bot.blockAt(pos)
  2327.         const r = bot.canSeeBlock(block)
  2328.         if (r) {
  2329.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  2330.         } else {
  2331.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  2332.         }
  2333.     }
  2334.    
  2335.     function sayPosition(username) {
  2336.         //bot.chat(`My puplic position is disabled`)
  2337.         bot.chat(`I am at ${bot.entity.position}`)
  2338.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  2339.         //bot.chat(`I don't know your position.`)
  2340.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  2341.    }
  2342.  
  2343.    function sayEquipment() {
  2344.        const eq = bot.players[username].entity.equipment
  2345.        const eqText = []
  2346.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  2347.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  2348.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  2349.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  2350.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  2351.        if (eqText.length) {
  2352.            bot.chat(`You are ${eqText.join(', ')}.`)
  2353.        } else {
  2354.            bot.chat('You are without armor!')
  2355.        }
  2356.    }
  2357.  
  2358.    function sayVersion() { // work in prograss not working yet
  2359.        bot.chat('/version')
  2360.        console.log(`${command.message} confermed ${brand}`)
  2361.    }
  2362.  
  2363.    function saySpawnPoint() {
  2364.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  2365.    }
  2366.  
  2367.    function sayBlockUnder() {
  2368.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  2369.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  2370.        console.log(block)
  2371.    }
  2372.  
  2373.    function quit(username) {
  2374.        console.log('quit command used')
  2375.        bot.quit(`${username} told me too`)
  2376.    }
  2377.  
  2378.    function sayNick() {
  2379.        bot.chat(`My name is ${bot.player.displayName}`)
  2380.    }
  2381.    
  2382.    // begin of autoeats paste
  2383.    bot.once('spawn', () => {
  2384.        bot.autoEat.options = {
  2385.            priority: 'foodPoints',
  2386.            startAt: 14,
  2387.            bannedFood: []
  2388.        }
  2389.    })
  2390.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  2391.    bot.on('autoeat_started', () => {
  2392.        console.log('Auto Eat started!')
  2393.    })
  2394.  
  2395.    bot.on('autoeat_stopped', () => {
  2396.        console.log('Auto Eat stopped!')
  2397.    })
  2398.  
  2399.    bot.on('health', () => {
  2400.        if (bot.food === 20) bot.autoEat.disable()
  2401.        // Disable the plugin if the bot is at 20 food points
  2402.        else bot.autoEat.enable() // Else enable the plugin again
  2403.    })
  2404.    // end of paste autoeat
  2405.  
  2406.    bot.on('whisper', (username, message, rawMessage) => {
  2407.        console.log(`I received a message from ${username}: ${message}`)
  2408.        bot.whisper(username, 'I can tell secrets too.')
  2409.    })
  2410.  
  2411.    bot.on('nonSpokenChat', (message) => {
  2412.        console.log(`Non spoken chat: ${message}`)
  2413.    })
  2414.    
  2415.    bot.on('login', () => {
  2416.        bot.chat('Hi everyone!')
  2417.    })
  2418.    
  2419.    bot.on('spawnReset', (message) => {
  2420.        console.log('spawnReset command used')
  2421.        stopGuarding()
  2422.        bot.hawkEye.stop()
  2423.        bot.chat('Oh noez! My bed is broken.')
  2424.    })
  2425.    
  2426.    bot.on('forcedMove', () => {
  2427.        console.log(`I have been forced to move to ${bot.entity.position}`)
  2428.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  2429.    })
  2430.    
  2431.    bot.on('health', () => {
  2432.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  2433.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  2434.    })
  2435.  
  2436.    bot.on('death', () => {
  2437.        console.log('I died, stopping and respawning')
  2438.        stopGuarding()
  2439.        bot.hawkEye.stop()
  2440.        bot.respawn
  2441.        bot.chat('I died x.x ugh!!')
  2442.        // need instructions to return to
  2443.        // what i was doing.
  2444.    })
  2445.  
  2446.    bot.on('kicked', (reason) => {
  2447.        console.log(`I got kicked for ${reason}`)
  2448.    })
  2449.    
  2450.    bot.on('rain', () => {
  2451.        if (bot.isRaining) {
  2452.            console.log('It started raining.')
  2453.            //bot.chat('It started raining.')
  2454.        } else {
  2455.            console.log('It stopped raining.')
  2456.            //bot.chat('It stopped raining.')
  2457.        }
  2458.    })
  2459.  
  2460.    bot.on('noteHeard', (block, instrument, pitch) => {
  2461.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  2462.    })
  2463.  
  2464.    bot.on('chestLidMove', (block, isOpen) => {
  2465.        const action = isOpen ? 'open' : 'close'
  2466.        bot.chat(`Hey, did someone just ${action} a chest?`)
  2467.    })
  2468.  
  2469.    bot.on('pistonMove', (block, isPulling, direction) => {
  2470.        const action = isPulling ? 'pulling' : 'pushing'
  2471.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  2472.    })
  2473.  
  2474.    bot.on('playerJoined', (player) => {
  2475.        if (player.username !== bot.username) {
  2476.            console.log(`${player.username}! Joined the server.`)
  2477.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  2478.        }
  2479.    })
  2480.  
  2481.    bot.on('playerLeft', (player) => {
  2482.        if (player.username === bot.username) return
  2483.        console.log(`${player.username} left the server`)
  2484.        // bot.chat(`Bye ${player.username}`)
  2485.    })
  2486.    /*
  2487.    bot.on('playerCollect', (collector, collected) => {
  2488.        if (collector.type === 'player' && collected.type === 'object') {
  2489.            const rawItem = collected.metadata[10]
  2490.            const item = mineflayer.Item.fromNotch(rawItem)
  2491.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  2492.        }
  2493.    })
  2494.    */
  2495.    /*    
  2496.    bot.on('entitySpawn', (entity) => {
  2497.        if (entity.type === 'mob') {
  2498.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  2499.        } else if (entity.type === 'player') {
  2500.            console.log(`Look who decided to show up: ${entity.username}`)
  2501.        } else if (entity.type === 'object') {
  2502.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  2503.        } else if (entity.type === 'global') {
  2504.            console.log('Ooh lightning!')
  2505.        } else if (entity.type === 'orb') {
  2506.            console.log('Gimme dat exp orb!')
  2507.        }
  2508.    })
  2509.    */    
  2510.  
  2511.    const target = bot.hawkEye.getPlayer()
  2512.    console.log(target)
  2513.    if (!target) {
  2514.        return false
  2515.    }
  2516.  
  2517.    function Start() {
  2518.        bot.hawkEye.autoAttack(target)
  2519.    }
  2520.  
  2521.    bot.on('entityHurt', (entity) => {
  2522.        if (entity.type === 'mob') {
  2523.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  2524.        } else if (entity.type === 'player') {
  2525.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  2526.        }
  2527.    })
  2528.  
  2529.    bot.on('entitySwingArm', (entity) => {
  2530.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  2531.    })
  2532.  
  2533.    bot.on('entityCrouch', (entity) => {
  2534.        bot.chat(`${entity.username}: you so sneaky.`)
  2535.    })
  2536.  
  2537.    bot.on('entityUncrouch', (entity) => {
  2538.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  2539.    })
  2540.  
  2541.    bot.on('entitySleep', (entity) => {
  2542.        bot.chat(`Good night, ${entity.username}`)
  2543.    })
  2544.  
  2545.    bot.on('entityWake', (entity) => {
  2546.        bot.chat(`Top of the morning, ${entity.username}`)
  2547.    })
  2548.  
  2549.    bot.on('entityEat', (entity) => {
  2550.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  2551.    })
  2552.  
  2553.    bot.on('entityAttach', (entity, vehicle) => {
  2554.        if (entity.type === 'player' && vehicle.type === 'object') {
  2555.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  2556.        }
  2557.    })
  2558.  
  2559.    bot.on('entityDetach', (entity, vehicle) => {
  2560.        if (entity.type === 'player' && vehicle.type === 'object') {
  2561.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  2562.        }
  2563.    })
  2564.  
  2565.    bot.on('entityEquipmentChange', (entity) => {
  2566.        console.log('entityEquipmentChange', entity)
  2567.    })
  2568.  
  2569.    bot.on('entityEffect', (entity, effect) => {
  2570.        console.log('entityEffect', entity, effect)
  2571.    })
  2572.  
  2573.    bot.on('entityEffectEnd', (entity, effect) => {
  2574.        console.log('entityEffectEnd', entity, effect)
  2575.    })
  2576.  
  2577.    function guardArea(pos) {
  2578.        guardPos = pos.clone()
  2579.        
  2580.        if (!bot.pvp.target) {
  2581.            moveToGuardPos()
  2582.        }
  2583.    }
  2584.    
  2585.    function stopGuarding() {
  2586.        guardPos = null
  2587.        bot.pvp.stop()
  2588.        bot.pathfinder.setGoal(null)
  2589.    }
  2590.    
  2591.    function moveToGuardPos() {
  2592.        const mcData = require('minecraft-data')(bot.version)
  2593.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  2594.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  2595.    }
  2596.    
  2597.    bot.on('stoppedAttacking', () => {
  2598.        if (guardPos) {
  2599.            moveToGuardPos()
  2600.        }
  2601.    })
  2602.    
  2603.    bot.on('physicTick', () => {
  2604.        if (bot.pvp.target) return
  2605.        if (bot.pathfinder.isMoving()) return
  2606.        
  2607.        const entity = bot.nearestEntity()
  2608.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  2609.    })
  2610.    
  2611.    bot.on('physicTick', () => {
  2612.        if (!guardPos) return
  2613.        
  2614.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  2615.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  2616.        
  2617.        const entity = bot.nearestEntity(filter)
  2618.        if (entity) {
  2619.            bot.pvp.attack(entity)
  2620.        }
  2621.    })
  2622.    /*
  2623.    bot.on('chat', (username, message) => {
  2624.        if (username === bot.username) return
  2625.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  2626.        if (result) {
  2627.            canSee(new Vec3(result[1], result[2], result[3]))
  2628.            return
  2629.        }
  2630.        switch (message) {
  2631.            case 'pos':
  2632.                console.log("pos command used")
  2633.                sayPosition(username)
  2634.                break
  2635.            case 'wearing':
  2636.                console.log("wearing command used")
  2637.                sayEquipment()
  2638.                break
  2639.            case 'nick':
  2640.                console.log("saynick command used")
  2641.                sayNick()
  2642.                break
  2643.            case 'spawn':
  2644.                console.log("spawn command used")
  2645.                saySpawnPoint()
  2646.                break
  2647.            case 'block':
  2648.                console.log("block command used")
  2649.                sayBlockUnder(username)
  2650.                break
  2651.            default:
  2652.                console.log("I am ready!")
  2653.                bot.chat("I am ready!")
  2654.    }
  2655.    */
  2656.  
  2657.    // text of bots username and help will give a list of bot commands
  2658.    bot.on('chat', (username, message) => { // work in progress....
  2659.        if (message === `${bot.player.displayName} help`)
  2660.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  2661.            bot.chat('pos, wearing, nick, spawn, block ')
  2662.            bot.chat('arch-start, Version.(wip not all commands work...)')
  2663.            bot.chat('Bot may just leave if it errors out.')
  2664.    })
  2665.  
  2666.    bot.on('chat', (username, message) => { // work in progress....
  2667.        if (message === 'Version') {
  2668.            console.log("Version command used just used")
  2669.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  2670.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  2671.            console.log("sayVersion command used")
  2672.            sayVersion(username)
  2673.            return
  2674.        }
  2675.    })
  2676.  
  2677.    bot.on('chat', (username, message) => {
  2678.        if (message === 'leave') {
  2679.                console.log("leave command used")
  2680.                bot.chat("Yes sir right away!")
  2681.                bot.quit(username)
  2682.                return
  2683.        }
  2684.    })
  2685.  
  2686.    bot.on('chat', (username, message) => {
  2687.        if (message === 'arch-start') {
  2688.            console.log("arch-start command used")
  2689.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  2690.            Start()
  2691.            return
  2692.        }
  2693.    })
  2694.  
  2695.    bot.on('chat', (username, message) => {
  2696.        if (message === 'guard') {          // if message guard do gaurd
  2697.            const player = bot.players[username]
  2698.  
  2699.            if (!player) {
  2700.                bot.chat("I can't see you.")
  2701.                return
  2702.            }
  2703.        bot.chat('I will guard that location.')
  2704.            guardArea(player.entity.position)
  2705.            }
  2706.  
  2707.            if (message === 'fight me') {
  2708.                const player = bot.players[username]
  2709.  
  2710.                if (!player) {
  2711.                    bot.chat("I can't see you.")
  2712.                    return
  2713.                }
  2714.  
  2715.            bot.chat('Prepare to fight!')
  2716.            bot.chat('5')
  2717.            bot.chat('4')
  2718.            bot.chat('3')
  2719.            bot.chat('2')
  2720.            bot.chat('1')
  2721.            bot.chat('GO!!!')
  2722.            bot.pvp.attack(player.entity)
  2723.            }
  2724.  
  2725.            if (message === 'stop') {
  2726.                bot.chat('I will stop!')
  2727.                bot.hawkEye.stop()
  2728.                stopGuarding()
  2729.            }
  2730.    })
  2731.  
  2732.    function not_busy() {
  2733.        guardPos = pos.clone()
  2734.  
  2735.        if (guardPos == null) {
  2736.            return false
  2737.        
  2738.        } else { (guardPos == !null)
  2739.                return true
  2740.            }
  2741.        }
  2742.    
  2743.    
  2744.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  2745.        if (busy == true) {
  2746.        console.log("I am busy!")
  2747.        bot.chat("I am busy!")
  2748.            } else { if (busy == false)
  2749.            console.log('I am ready!')
  2750.            bot.chat('I am ready!')
  2751.            }
  2752.    
  2753.    })
  2754.  
  2755.    bot.on('sleep', () => {
  2756.        bot.chat('Good night!')
  2757.    })
  2758.  
  2759.    bot.on('wake', () => {
  2760.        bot.chat('Good morning!')
  2761.    })
  2762.  
  2763.    function goToSleep() {
  2764.        const bed = bot.findBlock({
  2765.            matching: block => bot.isABed(block)
  2766.        })
  2767.        if (bed) {
  2768.            bot.sleep(bed, (err) => {
  2769.                if (err) {
  2770.                    bot.chat(`I can't sleep: ${err.message}`)
  2771.                } else {
  2772.                    bot.chat("I'm sleeping")
  2773.                }
  2774.            })
  2775.        } else {
  2776.            bot.chat('No nearby bed')
  2777.        }
  2778.    }
  2779.  
  2780.    function wakeUp() {
  2781.        bot.wake((err) => {
  2782.            if (err) {
  2783.                bot.chat(`I can't wake up: ${err.message}`)
  2784.             } else {
  2785.                 bot.chat('I woke up')
  2786.             }
  2787.         }
  2788.        
  2789.     )
  2790. }
  2791. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  2792. const Vec3 = require('vec3').Vec3
  2793. const fs = require('fs')
  2794. const { version } = require('os')
  2795. const pvp = require('mineflayer-pvp').plugin
  2796. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  2797. const armorManager = require('mineflayer-armor-manager')
  2798. const autoeat = require('mineflayer-auto-eat')
  2799. const minecraftHawkEye = require('minecrafthawkeye')
  2800.  
  2801. function jsonReader(filePath, cb) {
  2802.     fs.readFile(filePath, (err, fileData) => {
  2803.         if (err) {
  2804.             return cb && cb(err)
  2805.         }
  2806.         try {
  2807.             const object = JSON.parse(fileData)
  2808.             return cb && cb(null, object)
  2809.         } catch (err) {
  2810.             return cb && cb(err)
  2811.         }
  2812.     })
  2813. }
  2814.  
  2815. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  2816.     if (err) {
  2817.         console.log(err)
  2818.         return
  2819.     }
  2820.  
  2821.     const bot = mineflayer.createBot({
  2822.         version: mc_login_info.version,
  2823.         host: mc_login_info.host,
  2824.         port: mc_login_info.port,
  2825.         username: mc_login_info.username,
  2826.         password: mc_login_info.password,
  2827.         // give time for communication to hosts&client with longer ping times
  2828.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  2829.         logErrors: true
  2830.     })
  2831. })
  2832.  
  2833.     bot._client.on('custom_payload', (packet) => {
  2834.         // console.log(packet)
  2835.         if (packet.channel === "minecraft:brand") {
  2836.             let data = packet.data
  2837.             let brand = String.fromCharCode.apply(null, data)
  2838.             console.log(brand)
  2839.         }
  2840.     })
  2841.  
  2842.     bot.once('login', () => {
  2843.         console.log('logged in')
  2844.         console.log(`curent client version ${bot.version}`)
  2845.         // console.log(`curent server version is ${server.version}`)
  2846.     })
  2847.  
  2848.     bot.loadPlugin(autoeat)
  2849.     bot.loadPlugin(armorManager)
  2850.     bot.loadPlugin(minecraftHawkEye)
  2851.     bot.loadPlugin(pathfinder)
  2852.     bot.loadPlugin(pvp)
  2853.  
  2854.    
  2855.     bot.on('playerCollect', (collector, itemDrop) => {
  2856.         if (collector !== bot.entity) return
  2857.        
  2858.         setTimeout(() => {
  2859.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  2860.             if (sword) bot.equip(sword, 'hand')
  2861.         }, 150)
  2862.     })
  2863.    
  2864.     bot.on('playerCollect', (collector, itemDrop) => {
  2865.         if (collector !== bot.entity) return
  2866.        
  2867.         setTimeout(() => {
  2868.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  2869.             if (shield) bot.equip(shield, 'off-hand')
  2870.         }, 250)
  2871.     })
  2872.    
  2873.     let guardPos = null
  2874.     let busy = false
  2875.  
  2876.     bot.on('spawn', () => { // gives error when bot spawns
  2877.         console.log('spawned in server')
  2878.         bot.hawkEye.stop()
  2879.         stopGuarding()
  2880.         bot.chat('I spawned, watch out!')
  2881.     })
  2882.    
  2883.     function canSee(pos) {
  2884.         const block = bot.blockAt(pos)
  2885.         const r = bot.canSeeBlock(block)
  2886.         if (r) {
  2887.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  2888.         } else {
  2889.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  2890.         }
  2891.     }
  2892.    
  2893.     function sayPosition(username) {
  2894.         //bot.chat(`My puplic position is disabled`)
  2895.         bot.chat(`I am at ${bot.entity.position}`)
  2896.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  2897.         //bot.chat(`I don't know your position.`)
  2898.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  2899.    }
  2900.  
  2901.    function sayEquipment() {
  2902.        const eq = bot.players[username].entity.equipment
  2903.        const eqText = []
  2904.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  2905.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  2906.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  2907.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  2908.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  2909.        if (eqText.length) {
  2910.            bot.chat(`You are ${eqText.join(', ')}.`)
  2911.        } else {
  2912.            bot.chat('You are without armor!')
  2913.        }
  2914.    }
  2915.  
  2916.    function sayVersion() { // work in prograss not working yet
  2917.        bot.chat('/version')
  2918.        console.log(`${command.message} confermed ${brand}`)
  2919.    }
  2920.  
  2921.    function saySpawnPoint() {
  2922.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  2923.    }
  2924.  
  2925.    function sayBlockUnder() {
  2926.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  2927.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  2928.        console.log(block)
  2929.    }
  2930.  
  2931.    function quit(username) {
  2932.        console.log('quit command used')
  2933.        bot.quit(`${username} told me too`)
  2934.    }
  2935.  
  2936.    function sayNick() {
  2937.        bot.chat(`My name is ${bot.player.displayName}`)
  2938.    }
  2939.    
  2940.    // begin of autoeats paste
  2941.    bot.once('spawn', () => {
  2942.        bot.autoEat.options = {
  2943.            priority: 'foodPoints',
  2944.            startAt: 14,
  2945.            bannedFood: []
  2946.        }
  2947.    })
  2948.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  2949.    bot.on('autoeat_started', () => {
  2950.        console.log('Auto Eat started!')
  2951.    })
  2952.  
  2953.    bot.on('autoeat_stopped', () => {
  2954.        console.log('Auto Eat stopped!')
  2955.    })
  2956.  
  2957.    bot.on('health', () => {
  2958.        if (bot.food === 20) bot.autoEat.disable()
  2959.        // Disable the plugin if the bot is at 20 food points
  2960.        else bot.autoEat.enable() // Else enable the plugin again
  2961.    })
  2962.    // end of paste autoeat
  2963.  
  2964.    bot.on('whisper', (username, message, rawMessage) => {
  2965.        console.log(`I received a message from ${username}: ${message}`)
  2966.        bot.whisper(username, 'I can tell secrets too.')
  2967.    })
  2968.  
  2969.    bot.on('nonSpokenChat', (message) => {
  2970.        console.log(`Non spoken chat: ${message}`)
  2971.    })
  2972.    
  2973.    bot.on('login', () => {
  2974.        bot.chat('Hi everyone!')
  2975.    })
  2976.    
  2977.    bot.on('spawnReset', (message) => {
  2978.        console.log('spawnReset command used')
  2979.        stopGuarding()
  2980.        bot.hawkEye.stop()
  2981.        bot.chat('Oh noez! My bed is broken.')
  2982.    })
  2983.    
  2984.    bot.on('forcedMove', () => {
  2985.        console.log(`I have been forced to move to ${bot.entity.position}`)
  2986.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  2987.    })
  2988.    
  2989.    bot.on('health', () => {
  2990.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  2991.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  2992.    })
  2993.  
  2994.    bot.on('death', () => {
  2995.        console.log('I died, stopping and respawning')
  2996.        stopGuarding()
  2997.        bot.hawkEye.stop()
  2998.        bot.respawn
  2999.        bot.chat('I died x.x ugh!!')
  3000.        // need instructions to return to
  3001.        // what i was doing.
  3002.    })
  3003.  
  3004.    bot.on('kicked', (reason) => {
  3005.        console.log(`I got kicked for ${reason}`)
  3006.    })
  3007.    
  3008.    bot.on('rain', () => {
  3009.        if (bot.isRaining) {
  3010.            console.log('It started raining.')
  3011.            //bot.chat('It started raining.')
  3012.        } else {
  3013.            console.log('It stopped raining.')
  3014.            //bot.chat('It stopped raining.')
  3015.        }
  3016.    })
  3017.  
  3018.    bot.on('noteHeard', (block, instrument, pitch) => {
  3019.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  3020.    })
  3021.  
  3022.    bot.on('chestLidMove', (block, isOpen) => {
  3023.        const action = isOpen ? 'open' : 'close'
  3024.        bot.chat(`Hey, did someone just ${action} a chest?`)
  3025.    })
  3026.  
  3027.    bot.on('pistonMove', (block, isPulling, direction) => {
  3028.        const action = isPulling ? 'pulling' : 'pushing'
  3029.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  3030.    })
  3031.  
  3032.    bot.on('playerJoined', (player) => {
  3033.        if (player.username !== bot.username) {
  3034.            console.log(`${player.username}! Joined the server.`)
  3035.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  3036.        }
  3037.    })
  3038.  
  3039.    bot.on('playerLeft', (player) => {
  3040.        if (player.username === bot.username) return
  3041.        console.log(`${player.username} left the server`)
  3042.        // bot.chat(`Bye ${player.username}`)
  3043.    })
  3044.    /*
  3045.    bot.on('playerCollect', (collector, collected) => {
  3046.        if (collector.type === 'player' && collected.type === 'object') {
  3047.            const rawItem = collected.metadata[10]
  3048.            const item = mineflayer.Item.fromNotch(rawItem)
  3049.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  3050.        }
  3051.    })
  3052.    */
  3053.    /*    
  3054.    bot.on('entitySpawn', (entity) => {
  3055.        if (entity.type === 'mob') {
  3056.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  3057.        } else if (entity.type === 'player') {
  3058.            console.log(`Look who decided to show up: ${entity.username}`)
  3059.        } else if (entity.type === 'object') {
  3060.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  3061.        } else if (entity.type === 'global') {
  3062.            console.log('Ooh lightning!')
  3063.        } else if (entity.type === 'orb') {
  3064.            console.log('Gimme dat exp orb!')
  3065.        }
  3066.    })
  3067.    */    
  3068.  
  3069.    const target = bot.hawkEye.getPlayer()
  3070.    console.log(target)
  3071.    if (!target) {
  3072.        return false
  3073.    }
  3074.  
  3075.    function Start() {
  3076.        bot.hawkEye.autoAttack(target)
  3077.    }
  3078.  
  3079.    bot.on('entityHurt', (entity) => {
  3080.        if (entity.type === 'mob') {
  3081.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  3082.        } else if (entity.type === 'player') {
  3083.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  3084.        }
  3085.    })
  3086.  
  3087.    bot.on('entitySwingArm', (entity) => {
  3088.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  3089.    })
  3090.  
  3091.    bot.on('entityCrouch', (entity) => {
  3092.        bot.chat(`${entity.username}: you so sneaky.`)
  3093.    })
  3094.  
  3095.    bot.on('entityUncrouch', (entity) => {
  3096.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  3097.    })
  3098.  
  3099.    bot.on('entitySleep', (entity) => {
  3100.        bot.chat(`Good night, ${entity.username}`)
  3101.    })
  3102.  
  3103.    bot.on('entityWake', (entity) => {
  3104.        bot.chat(`Top of the morning, ${entity.username}`)
  3105.    })
  3106.  
  3107.    bot.on('entityEat', (entity) => {
  3108.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  3109.    })
  3110.  
  3111.    bot.on('entityAttach', (entity, vehicle) => {
  3112.        if (entity.type === 'player' && vehicle.type === 'object') {
  3113.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  3114.        }
  3115.    })
  3116.  
  3117.    bot.on('entityDetach', (entity, vehicle) => {
  3118.        if (entity.type === 'player' && vehicle.type === 'object') {
  3119.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  3120.        }
  3121.    })
  3122.  
  3123.    bot.on('entityEquipmentChange', (entity) => {
  3124.        console.log('entityEquipmentChange', entity)
  3125.    })
  3126.  
  3127.    bot.on('entityEffect', (entity, effect) => {
  3128.        console.log('entityEffect', entity, effect)
  3129.    })
  3130.  
  3131.    bot.on('entityEffectEnd', (entity, effect) => {
  3132.        console.log('entityEffectEnd', entity, effect)
  3133.    })
  3134.  
  3135.    function guardArea(pos) {
  3136.        guardPos = pos.clone()
  3137.        
  3138.        if (!bot.pvp.target) {
  3139.            moveToGuardPos()
  3140.        }
  3141.    }
  3142.    
  3143.    function stopGuarding() {
  3144.        guardPos = null
  3145.        bot.pvp.stop()
  3146.        bot.pathfinder.setGoal(null)
  3147.    }
  3148.    
  3149.    function moveToGuardPos() {
  3150.        const mcData = require('minecraft-data')(bot.version)
  3151.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  3152.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  3153.    }
  3154.    
  3155.    bot.on('stoppedAttacking', () => {
  3156.        if (guardPos) {
  3157.            moveToGuardPos()
  3158.        }
  3159.    })
  3160.    
  3161.    bot.on('physicTick', () => {
  3162.        if (bot.pvp.target) return
  3163.        if (bot.pathfinder.isMoving()) return
  3164.        
  3165.        const entity = bot.nearestEntity()
  3166.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  3167.    })
  3168.    
  3169.    bot.on('physicTick', () => {
  3170.        if (!guardPos) return
  3171.        
  3172.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  3173.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  3174.        
  3175.        const entity = bot.nearestEntity(filter)
  3176.        if (entity) {
  3177.            bot.pvp.attack(entity)
  3178.        }
  3179.    })
  3180.    /*
  3181.    bot.on('chat', (username, message) => {
  3182.        if (username === bot.username) return
  3183.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  3184.        if (result) {
  3185.            canSee(new Vec3(result[1], result[2], result[3]))
  3186.            return
  3187.        }
  3188.        switch (message) {
  3189.            case 'pos':
  3190.                console.log("pos command used")
  3191.                sayPosition(username)
  3192.                break
  3193.            case 'wearing':
  3194.                console.log("wearing command used")
  3195.                sayEquipment()
  3196.                break
  3197.            case 'nick':
  3198.                console.log("saynick command used")
  3199.                sayNick()
  3200.                break
  3201.            case 'spawn':
  3202.                console.log("spawn command used")
  3203.                saySpawnPoint()
  3204.                break
  3205.            case 'block':
  3206.                console.log("block command used")
  3207.                sayBlockUnder(username)
  3208.                break
  3209.            default:
  3210.                console.log("I am ready!")
  3211.                bot.chat("I am ready!")
  3212.    }
  3213.    */
  3214.  
  3215.    // text of bots username and help will give a list of bot commands
  3216.    bot.on('chat', (username, message) => { // work in progress....
  3217.        if (message === `${bot.player.displayName} help`)
  3218.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  3219.            bot.chat('pos, wearing, nick, spawn, block ')
  3220.            bot.chat('arch-start, Version.(wip not all commands work...)')
  3221.            bot.chat('Bot may just leave if it errors out.')
  3222.    })
  3223.  
  3224.    bot.on('chat', (username, message) => { // work in progress....
  3225.        if (message === 'Version') {
  3226.            console.log("Version command used just used")
  3227.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  3228.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  3229.            console.log("sayVersion command used")
  3230.            sayVersion(username)
  3231.            return
  3232.        }
  3233.    })
  3234.  
  3235.    bot.on('chat', (username, message) => {
  3236.        if (message === 'leave') {
  3237.                console.log("leave command used")
  3238.                bot.chat("Yes sir right away!")
  3239.                bot.quit(username)
  3240.                return
  3241.        }
  3242.    })
  3243.  
  3244.    bot.on('chat', (username, message) => {
  3245.        if (message === 'arch-start') {
  3246.            console.log("arch-start command used")
  3247.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  3248.            Start()
  3249.            return
  3250.        }
  3251.    })
  3252.  
  3253.    bot.on('chat', (username, message) => {
  3254.        if (message === 'guard') {          // if message guard do gaurd
  3255.            const player = bot.players[username]
  3256.  
  3257.            if (!player) {
  3258.                bot.chat("I can't see you.")
  3259.                return
  3260.            }
  3261.        bot.chat('I will guard that location.')
  3262.            guardArea(player.entity.position)
  3263.            }
  3264.  
  3265.            if (message === 'fight me') {
  3266.                const player = bot.players[username]
  3267.  
  3268.                if (!player) {
  3269.                    bot.chat("I can't see you.")
  3270.                    return
  3271.                }
  3272.  
  3273.            bot.chat('Prepare to fight!')
  3274.            bot.chat('5')
  3275.            bot.chat('4')
  3276.            bot.chat('3')
  3277.            bot.chat('2')
  3278.            bot.chat('1')
  3279.            bot.chat('GO!!!')
  3280.            bot.pvp.attack(player.entity)
  3281.            }
  3282.  
  3283.            if (message === 'stop') {
  3284.                bot.chat('I will stop!')
  3285.                bot.hawkEye.stop()
  3286.                stopGuarding()
  3287.            }
  3288.    })
  3289.  
  3290.    function not_busy() {
  3291.        guardPos = pos.clone()
  3292.  
  3293.        if (guardPos == null) {
  3294.            return false
  3295.        
  3296.        } else { (guardPos == !null)
  3297.                return true
  3298.            }
  3299.        }
  3300.    
  3301.    
  3302.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  3303.        if (busy == true) {
  3304.        console.log("I am busy!")
  3305.        bot.chat("I am busy!")
  3306.            } else { if (busy == false)
  3307.            console.log('I am ready!')
  3308.            bot.chat('I am ready!')
  3309.            }
  3310.    
  3311.    })
  3312.  
  3313.    bot.on('sleep', () => {
  3314.        bot.chat('Good night!')
  3315.    })
  3316.  
  3317.    bot.on('wake', () => {
  3318.        bot.chat('Good morning!')
  3319.    })
  3320.  
  3321.    function goToSleep() {
  3322.        const bed = bot.findBlock({
  3323.            matching: block => bot.isABed(block)
  3324.        })
  3325.        if (bed) {
  3326.            bot.sleep(bed, (err) => {
  3327.                if (err) {
  3328.                    bot.chat(`I can't sleep: ${err.message}`)
  3329.                } else {
  3330.                    bot.chat("I'm sleeping")
  3331.                }
  3332.            })
  3333.        } else {
  3334.            bot.chat('No nearby bed')
  3335.        }
  3336.    }
  3337.  
  3338.    function wakeUp() {
  3339.        bot.wake((err) => {
  3340.            if (err) {
  3341.                bot.chat(`I can't wake up: ${err.message}`)
  3342.             } else {
  3343.                 bot.chat('I woke up')
  3344.             }
  3345.         }
  3346.        
  3347.     )
  3348. }
  3349. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  3350. const Vec3 = require('vec3').Vec3
  3351. const fs = require('fs')
  3352. const { version } = require('os')
  3353. const pvp = require('mineflayer-pvp').plugin
  3354. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  3355. const armorManager = require('mineflayer-armor-manager')
  3356. const autoeat = require('mineflayer-auto-eat')
  3357. const minecraftHawkEye = require('minecrafthawkeye')
  3358.  
  3359. function jsonReader(filePath, cb) {
  3360.     fs.readFile(filePath, (err, fileData) => {
  3361.         if (err) {
  3362.             return cb && cb(err)
  3363.         }
  3364.         try {
  3365.             const object = JSON.parse(fileData)
  3366.             return cb && cb(null, object)
  3367.         } catch (err) {
  3368.             return cb && cb(err)
  3369.         }
  3370.     })
  3371. }
  3372.  
  3373. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  3374.     if (err) {
  3375.         console.log(err)
  3376.         return
  3377.     }
  3378.  
  3379.     const bot = mineflayer.createBot({
  3380.         version: mc_login_info.version,
  3381.         host: mc_login_info.host,
  3382.         port: mc_login_info.port,
  3383.         username: mc_login_info.username,
  3384.         password: mc_login_info.password,
  3385.         // give time for communication to hosts&client with longer ping times
  3386.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  3387.         logErrors: true
  3388.     })
  3389. })
  3390.  
  3391.     bot._client.on('custom_payload', (packet) => {
  3392.         // console.log(packet)
  3393.         if (packet.channel === "minecraft:brand") {
  3394.             let data = packet.data
  3395.             let brand = String.fromCharCode.apply(null, data)
  3396.             console.log(brand)
  3397.         }
  3398.     })
  3399.  
  3400.     bot.once('login', () => {
  3401.         console.log('logged in')
  3402.         console.log(`curent client version ${bot.version}`)
  3403.         // console.log(`curent server version is ${server.version}`)
  3404.     })
  3405.  
  3406.     bot.loadPlugin(autoeat)
  3407.     bot.loadPlugin(armorManager)
  3408.     bot.loadPlugin(minecraftHawkEye)
  3409.     bot.loadPlugin(pathfinder)
  3410.     bot.loadPlugin(pvp)
  3411.  
  3412.    
  3413.     bot.on('playerCollect', (collector, itemDrop) => {
  3414.         if (collector !== bot.entity) return
  3415.        
  3416.         setTimeout(() => {
  3417.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  3418.             if (sword) bot.equip(sword, 'hand')
  3419.         }, 150)
  3420.     })
  3421.    
  3422.     bot.on('playerCollect', (collector, itemDrop) => {
  3423.         if (collector !== bot.entity) return
  3424.        
  3425.         setTimeout(() => {
  3426.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  3427.             if (shield) bot.equip(shield, 'off-hand')
  3428.         }, 250)
  3429.     })
  3430.    
  3431.     let guardPos = null
  3432.     let busy = false
  3433.  
  3434.     bot.on('spawn', () => { // gives error when bot spawns
  3435.         console.log('spawned in server')
  3436.         bot.hawkEye.stop()
  3437.         stopGuarding()
  3438.         bot.chat('I spawned, watch out!')
  3439.     })
  3440.    
  3441.     function canSee(pos) {
  3442.         const block = bot.blockAt(pos)
  3443.         const r = bot.canSeeBlock(block)
  3444.         if (r) {
  3445.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  3446.         } else {
  3447.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  3448.         }
  3449.     }
  3450.    
  3451.     function sayPosition(username) {
  3452.         //bot.chat(`My puplic position is disabled`)
  3453.         bot.chat(`I am at ${bot.entity.position}`)
  3454.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  3455.         //bot.chat(`I don't know your position.`)
  3456.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  3457.    }
  3458.  
  3459.    function sayEquipment() {
  3460.        const eq = bot.players[username].entity.equipment
  3461.        const eqText = []
  3462.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  3463.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  3464.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  3465.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  3466.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  3467.        if (eqText.length) {
  3468.            bot.chat(`You are ${eqText.join(', ')}.`)
  3469.        } else {
  3470.            bot.chat('You are without armor!')
  3471.        }
  3472.    }
  3473.  
  3474.    function sayVersion() { // work in prograss not working yet
  3475.        bot.chat('/version')
  3476.        console.log(`${command.message} confermed ${brand}`)
  3477.    }
  3478.  
  3479.    function saySpawnPoint() {
  3480.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  3481.    }
  3482.  
  3483.    function sayBlockUnder() {
  3484.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  3485.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  3486.        console.log(block)
  3487.    }
  3488.  
  3489.    function quit(username) {
  3490.        console.log('quit command used')
  3491.        bot.quit(`${username} told me too`)
  3492.    }
  3493.  
  3494.    function sayNick() {
  3495.        bot.chat(`My name is ${bot.player.displayName}`)
  3496.    }
  3497.    
  3498.    // begin of autoeats paste
  3499.    bot.once('spawn', () => {
  3500.        bot.autoEat.options = {
  3501.            priority: 'foodPoints',
  3502.            startAt: 14,
  3503.            bannedFood: []
  3504.        }
  3505.    })
  3506.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  3507.    bot.on('autoeat_started', () => {
  3508.        console.log('Auto Eat started!')
  3509.    })
  3510.  
  3511.    bot.on('autoeat_stopped', () => {
  3512.        console.log('Auto Eat stopped!')
  3513.    })
  3514.  
  3515.    bot.on('health', () => {
  3516.        if (bot.food === 20) bot.autoEat.disable()
  3517.        // Disable the plugin if the bot is at 20 food points
  3518.        else bot.autoEat.enable() // Else enable the plugin again
  3519.    })
  3520.    // end of paste autoeat
  3521.  
  3522.    bot.on('whisper', (username, message, rawMessage) => {
  3523.        console.log(`I received a message from ${username}: ${message}`)
  3524.        bot.whisper(username, 'I can tell secrets too.')
  3525.    })
  3526.  
  3527.    bot.on('nonSpokenChat', (message) => {
  3528.        console.log(`Non spoken chat: ${message}`)
  3529.    })
  3530.    
  3531.    bot.on('login', () => {
  3532.        bot.chat('Hi everyone!')
  3533.    })
  3534.    
  3535.    bot.on('spawnReset', (message) => {
  3536.        console.log('spawnReset command used')
  3537.        stopGuarding()
  3538.        bot.hawkEye.stop()
  3539.        bot.chat('Oh noez! My bed is broken.')
  3540.    })
  3541.    
  3542.    bot.on('forcedMove', () => {
  3543.        console.log(`I have been forced to move to ${bot.entity.position}`)
  3544.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  3545.    })
  3546.    
  3547.    bot.on('health', () => {
  3548.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  3549.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  3550.    })
  3551.  
  3552.    bot.on('death', () => {
  3553.        console.log('I died, stopping and respawning')
  3554.        stopGuarding()
  3555.        bot.hawkEye.stop()
  3556.        bot.respawn
  3557.        bot.chat('I died x.x ugh!!')
  3558.        // need instructions to return to
  3559.        // what i was doing.
  3560.    })
  3561.  
  3562.    bot.on('kicked', (reason) => {
  3563.        console.log(`I got kicked for ${reason}`)
  3564.    })
  3565.    
  3566.    bot.on('rain', () => {
  3567.        if (bot.isRaining) {
  3568.            console.log('It started raining.')
  3569.            //bot.chat('It started raining.')
  3570.        } else {
  3571.            console.log('It stopped raining.')
  3572.            //bot.chat('It stopped raining.')
  3573.        }
  3574.    })
  3575.  
  3576.    bot.on('noteHeard', (block, instrument, pitch) => {
  3577.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  3578.    })
  3579.  
  3580.    bot.on('chestLidMove', (block, isOpen) => {
  3581.        const action = isOpen ? 'open' : 'close'
  3582.        bot.chat(`Hey, did someone just ${action} a chest?`)
  3583.    })
  3584.  
  3585.    bot.on('pistonMove', (block, isPulling, direction) => {
  3586.        const action = isPulling ? 'pulling' : 'pushing'
  3587.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  3588.    })
  3589.  
  3590.    bot.on('playerJoined', (player) => {
  3591.        if (player.username !== bot.username) {
  3592.            console.log(`${player.username}! Joined the server.`)
  3593.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  3594.        }
  3595.    })
  3596.  
  3597.    bot.on('playerLeft', (player) => {
  3598.        if (player.username === bot.username) return
  3599.        console.log(`${player.username} left the server`)
  3600.        // bot.chat(`Bye ${player.username}`)
  3601.    })
  3602.    /*
  3603.    bot.on('playerCollect', (collector, collected) => {
  3604.        if (collector.type === 'player' && collected.type === 'object') {
  3605.            const rawItem = collected.metadata[10]
  3606.            const item = mineflayer.Item.fromNotch(rawItem)
  3607.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  3608.        }
  3609.    })
  3610.    */
  3611.    /*    
  3612.    bot.on('entitySpawn', (entity) => {
  3613.        if (entity.type === 'mob') {
  3614.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  3615.        } else if (entity.type === 'player') {
  3616.            console.log(`Look who decided to show up: ${entity.username}`)
  3617.        } else if (entity.type === 'object') {
  3618.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  3619.        } else if (entity.type === 'global') {
  3620.            console.log('Ooh lightning!')
  3621.        } else if (entity.type === 'orb') {
  3622.            console.log('Gimme dat exp orb!')
  3623.        }
  3624.    })
  3625.    */    
  3626.  
  3627.    const target = bot.hawkEye.getPlayer()
  3628.    console.log(target)
  3629.    if (!target) {
  3630.        return false
  3631.    }
  3632.  
  3633.    function Start() {
  3634.        bot.hawkEye.autoAttack(target)
  3635.    }
  3636.  
  3637.    bot.on('entityHurt', (entity) => {
  3638.        if (entity.type === 'mob') {
  3639.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  3640.        } else if (entity.type === 'player') {
  3641.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  3642.        }
  3643.    })
  3644.  
  3645.    bot.on('entitySwingArm', (entity) => {
  3646.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  3647.    })
  3648.  
  3649.    bot.on('entityCrouch', (entity) => {
  3650.        bot.chat(`${entity.username}: you so sneaky.`)
  3651.    })
  3652.  
  3653.    bot.on('entityUncrouch', (entity) => {
  3654.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  3655.    })
  3656.  
  3657.    bot.on('entitySleep', (entity) => {
  3658.        bot.chat(`Good night, ${entity.username}`)
  3659.    })
  3660.  
  3661.    bot.on('entityWake', (entity) => {
  3662.        bot.chat(`Top of the morning, ${entity.username}`)
  3663.    })
  3664.  
  3665.    bot.on('entityEat', (entity) => {
  3666.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  3667.    })
  3668.  
  3669.    bot.on('entityAttach', (entity, vehicle) => {
  3670.        if (entity.type === 'player' && vehicle.type === 'object') {
  3671.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  3672.        }
  3673.    })
  3674.  
  3675.    bot.on('entityDetach', (entity, vehicle) => {
  3676.        if (entity.type === 'player' && vehicle.type === 'object') {
  3677.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  3678.        }
  3679.    })
  3680.  
  3681.    bot.on('entityEquipmentChange', (entity) => {
  3682.        console.log('entityEquipmentChange', entity)
  3683.    })
  3684.  
  3685.    bot.on('entityEffect', (entity, effect) => {
  3686.        console.log('entityEffect', entity, effect)
  3687.    })
  3688.  
  3689.    bot.on('entityEffectEnd', (entity, effect) => {
  3690.        console.log('entityEffectEnd', entity, effect)
  3691.    })
  3692.  
  3693.    function guardArea(pos) {
  3694.        guardPos = pos.clone()
  3695.        
  3696.        if (!bot.pvp.target) {
  3697.            moveToGuardPos()
  3698.        }
  3699.    }
  3700.    
  3701.    function stopGuarding() {
  3702.        guardPos = null
  3703.        bot.pvp.stop()
  3704.        bot.pathfinder.setGoal(null)
  3705.    }
  3706.    
  3707.    function moveToGuardPos() {
  3708.        const mcData = require('minecraft-data')(bot.version)
  3709.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  3710.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  3711.    }
  3712.    
  3713.    bot.on('stoppedAttacking', () => {
  3714.        if (guardPos) {
  3715.            moveToGuardPos()
  3716.        }
  3717.    })
  3718.    
  3719.    bot.on('physicTick', () => {
  3720.        if (bot.pvp.target) return
  3721.        if (bot.pathfinder.isMoving()) return
  3722.        
  3723.        const entity = bot.nearestEntity()
  3724.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  3725.    })
  3726.    
  3727.    bot.on('physicTick', () => {
  3728.        if (!guardPos) return
  3729.        
  3730.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  3731.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  3732.        
  3733.        const entity = bot.nearestEntity(filter)
  3734.        if (entity) {
  3735.            bot.pvp.attack(entity)
  3736.        }
  3737.    })
  3738.    /*
  3739.    bot.on('chat', (username, message) => {
  3740.        if (username === bot.username) return
  3741.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  3742.        if (result) {
  3743.            canSee(new Vec3(result[1], result[2], result[3]))
  3744.            return
  3745.        }
  3746.        switch (message) {
  3747.            case 'pos':
  3748.                console.log("pos command used")
  3749.                sayPosition(username)
  3750.                break
  3751.            case 'wearing':
  3752.                console.log("wearing command used")
  3753.                sayEquipment()
  3754.                break
  3755.            case 'nick':
  3756.                console.log("saynick command used")
  3757.                sayNick()
  3758.                break
  3759.            case 'spawn':
  3760.                console.log("spawn command used")
  3761.                saySpawnPoint()
  3762.                break
  3763.            case 'block':
  3764.                console.log("block command used")
  3765.                sayBlockUnder(username)
  3766.                break
  3767.            default:
  3768.                console.log("I am ready!")
  3769.                bot.chat("I am ready!")
  3770.    }
  3771.    */
  3772.  
  3773.    // text of bots username and help will give a list of bot commands
  3774.    bot.on('chat', (username, message) => { // work in progress....
  3775.        if (message === `${bot.player.displayName} help`)
  3776.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  3777.            bot.chat('pos, wearing, nick, spawn, block ')
  3778.            bot.chat('arch-start, Version.(wip not all commands work...)')
  3779.            bot.chat('Bot may just leave if it errors out.')
  3780.    })
  3781.  
  3782.    bot.on('chat', (username, message) => { // work in progress....
  3783.        if (message === 'Version') {
  3784.            console.log("Version command used just used")
  3785.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  3786.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  3787.            console.log("sayVersion command used")
  3788.            sayVersion(username)
  3789.            return
  3790.        }
  3791.    })
  3792.  
  3793.    bot.on('chat', (username, message) => {
  3794.        if (message === 'leave') {
  3795.                console.log("leave command used")
  3796.                bot.chat("Yes sir right away!")
  3797.                bot.quit(username)
  3798.                return
  3799.        }
  3800.    })
  3801.  
  3802.    bot.on('chat', (username, message) => {
  3803.        if (message === 'arch-start') {
  3804.            console.log("arch-start command used")
  3805.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  3806.            Start()
  3807.            return
  3808.        }
  3809.    })
  3810.  
  3811.    bot.on('chat', (username, message) => {
  3812.        if (message === 'guard') {          // if message guard do gaurd
  3813.            const player = bot.players[username]
  3814.  
  3815.            if (!player) {
  3816.                bot.chat("I can't see you.")
  3817.                return
  3818.            }
  3819.        bot.chat('I will guard that location.')
  3820.            guardArea(player.entity.position)
  3821.            }
  3822.  
  3823.            if (message === 'fight me') {
  3824.                const player = bot.players[username]
  3825.  
  3826.                if (!player) {
  3827.                    bot.chat("I can't see you.")
  3828.                    return
  3829.                }
  3830.  
  3831.            bot.chat('Prepare to fight!')
  3832.            bot.chat('5')
  3833.            bot.chat('4')
  3834.            bot.chat('3')
  3835.            bot.chat('2')
  3836.            bot.chat('1')
  3837.            bot.chat('GO!!!')
  3838.            bot.pvp.attack(player.entity)
  3839.            }
  3840.  
  3841.            if (message === 'stop') {
  3842.                bot.chat('I will stop!')
  3843.                bot.hawkEye.stop()
  3844.                stopGuarding()
  3845.            }
  3846.    })
  3847.  
  3848.    function not_busy() {
  3849.        guardPos = pos.clone()
  3850.  
  3851.        if (guardPos == null) {
  3852.            return false
  3853.        
  3854.        } else { (guardPos == !null)
  3855.                return true
  3856.            }
  3857.        }
  3858.    
  3859.    
  3860.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  3861.        if (busy == true) {
  3862.        console.log("I am busy!")
  3863.        bot.chat("I am busy!")
  3864.            } else { if (busy == false)
  3865.            console.log('I am ready!')
  3866.            bot.chat('I am ready!')
  3867.            }
  3868.    
  3869.    })
  3870.  
  3871.    bot.on('sleep', () => {
  3872.        bot.chat('Good night!')
  3873.    })
  3874.  
  3875.    bot.on('wake', () => {
  3876.        bot.chat('Good morning!')
  3877.    })
  3878.  
  3879.    function goToSleep() {
  3880.        const bed = bot.findBlock({
  3881.            matching: block => bot.isABed(block)
  3882.        })
  3883.        if (bed) {
  3884.            bot.sleep(bed, (err) => {
  3885.                if (err) {
  3886.                    bot.chat(`I can't sleep: ${err.message}`)
  3887.                } else {
  3888.                    bot.chat("I'm sleeping")
  3889.                }
  3890.            })
  3891.        } else {
  3892.            bot.chat('No nearby bed')
  3893.        }
  3894.    }
  3895.  
  3896.    function wakeUp() {
  3897.        bot.wake((err) => {
  3898.            if (err) {
  3899.                bot.chat(`I can't wake up: ${err.message}`)
  3900.             } else {
  3901.                 bot.chat('I woke up')
  3902.             }
  3903.         }
  3904.        
  3905.     )
  3906. }
  3907. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  3908. const Vec3 = require('vec3').Vec3
  3909. const fs = require('fs')
  3910. const { version } = require('os')
  3911. const pvp = require('mineflayer-pvp').plugin
  3912. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  3913. const armorManager = require('mineflayer-armor-manager')
  3914. const autoeat = require('mineflayer-auto-eat')
  3915. const minecraftHawkEye = require('minecrafthawkeye')
  3916.  
  3917. function jsonReader(filePath, cb) {
  3918.     fs.readFile(filePath, (err, fileData) => {
  3919.         if (err) {
  3920.             return cb && cb(err)
  3921.         }
  3922.         try {
  3923.             const object = JSON.parse(fileData)
  3924.             return cb && cb(null, object)
  3925.         } catch (err) {
  3926.             return cb && cb(err)
  3927.         }
  3928.     })
  3929. }
  3930.  
  3931. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  3932.     if (err) {
  3933.         console.log(err)
  3934.         return
  3935.     }
  3936.  
  3937.     const bot = mineflayer.createBot({
  3938.         version: mc_login_info.version,
  3939.         host: mc_login_info.host,
  3940.         port: mc_login_info.port,
  3941.         username: mc_login_info.username,
  3942.         password: mc_login_info.password,
  3943.         // give time for communication to hosts&client with longer ping times
  3944.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  3945.         logErrors: true
  3946.     })
  3947. })
  3948.  
  3949.     bot._client.on('custom_payload', (packet) => {
  3950.         // console.log(packet)
  3951.         if (packet.channel === "minecraft:brand") {
  3952.             let data = packet.data
  3953.             let brand = String.fromCharCode.apply(null, data)
  3954.             console.log(brand)
  3955.         }
  3956.     })
  3957.  
  3958.     bot.once('login', () => {
  3959.         console.log('logged in')
  3960.         console.log(`curent client version ${bot.version}`)
  3961.         // console.log(`curent server version is ${server.version}`)
  3962.     })
  3963.  
  3964.     bot.loadPlugin(autoeat)
  3965.     bot.loadPlugin(armorManager)
  3966.     bot.loadPlugin(minecraftHawkEye)
  3967.     bot.loadPlugin(pathfinder)
  3968.     bot.loadPlugin(pvp)
  3969.  
  3970.    
  3971.     bot.on('playerCollect', (collector, itemDrop) => {
  3972.         if (collector !== bot.entity) return
  3973.        
  3974.         setTimeout(() => {
  3975.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  3976.             if (sword) bot.equip(sword, 'hand')
  3977.         }, 150)
  3978.     })
  3979.    
  3980.     bot.on('playerCollect', (collector, itemDrop) => {
  3981.         if (collector !== bot.entity) return
  3982.        
  3983.         setTimeout(() => {
  3984.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  3985.             if (shield) bot.equip(shield, 'off-hand')
  3986.         }, 250)
  3987.     })
  3988.    
  3989.     let guardPos = null
  3990.     let busy = false
  3991.  
  3992.     bot.on('spawn', () => { // gives error when bot spawns
  3993.         console.log('spawned in server')
  3994.         bot.hawkEye.stop()
  3995.         stopGuarding()
  3996.         bot.chat('I spawned, watch out!')
  3997.     })
  3998.    
  3999.     function canSee(pos) {
  4000.         const block = bot.blockAt(pos)
  4001.         const r = bot.canSeeBlock(block)
  4002.         if (r) {
  4003.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  4004.         } else {
  4005.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  4006.         }
  4007.     }
  4008.    
  4009.     function sayPosition(username) {
  4010.         //bot.chat(`My puplic position is disabled`)
  4011.         bot.chat(`I am at ${bot.entity.position}`)
  4012.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  4013.         //bot.chat(`I don't know your position.`)
  4014.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  4015.    }
  4016.  
  4017.    function sayEquipment() {
  4018.        const eq = bot.players[username].entity.equipment
  4019.        const eqText = []
  4020.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  4021.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  4022.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  4023.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  4024.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  4025.        if (eqText.length) {
  4026.            bot.chat(`You are ${eqText.join(', ')}.`)
  4027.        } else {
  4028.            bot.chat('You are without armor!')
  4029.        }
  4030.    }
  4031.  
  4032.    function sayVersion() { // work in prograss not working yet
  4033.        bot.chat('/version')
  4034.        console.log(`${command.message} confermed ${brand}`)
  4035.    }
  4036.  
  4037.    function saySpawnPoint() {
  4038.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  4039.    }
  4040.  
  4041.    function sayBlockUnder() {
  4042.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  4043.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  4044.        console.log(block)
  4045.    }
  4046.  
  4047.    function quit(username) {
  4048.        console.log('quit command used')
  4049.        bot.quit(`${username} told me too`)
  4050.    }
  4051.  
  4052.    function sayNick() {
  4053.        bot.chat(`My name is ${bot.player.displayName}`)
  4054.    }
  4055.    
  4056.    // begin of autoeats paste
  4057.    bot.once('spawn', () => {
  4058.        bot.autoEat.options = {
  4059.            priority: 'foodPoints',
  4060.            startAt: 14,
  4061.            bannedFood: []
  4062.        }
  4063.    })
  4064.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  4065.    bot.on('autoeat_started', () => {
  4066.        console.log('Auto Eat started!')
  4067.    })
  4068.  
  4069.    bot.on('autoeat_stopped', () => {
  4070.        console.log('Auto Eat stopped!')
  4071.    })
  4072.  
  4073.    bot.on('health', () => {
  4074.        if (bot.food === 20) bot.autoEat.disable()
  4075.        // Disable the plugin if the bot is at 20 food points
  4076.        else bot.autoEat.enable() // Else enable the plugin again
  4077.    })
  4078.    // end of paste autoeat
  4079.  
  4080.    bot.on('whisper', (username, message, rawMessage) => {
  4081.        console.log(`I received a message from ${username}: ${message}`)
  4082.        bot.whisper(username, 'I can tell secrets too.')
  4083.    })
  4084.  
  4085.    bot.on('nonSpokenChat', (message) => {
  4086.        console.log(`Non spoken chat: ${message}`)
  4087.    })
  4088.    
  4089.    bot.on('login', () => {
  4090.        bot.chat('Hi everyone!')
  4091.    })
  4092.    
  4093.    bot.on('spawnReset', (message) => {
  4094.        console.log('spawnReset command used')
  4095.        stopGuarding()
  4096.        bot.hawkEye.stop()
  4097.        bot.chat('Oh noez! My bed is broken.')
  4098.    })
  4099.    
  4100.    bot.on('forcedMove', () => {
  4101.        console.log(`I have been forced to move to ${bot.entity.position}`)
  4102.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  4103.    })
  4104.    
  4105.    bot.on('health', () => {
  4106.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  4107.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  4108.    })
  4109.  
  4110.    bot.on('death', () => {
  4111.        console.log('I died, stopping and respawning')
  4112.        stopGuarding()
  4113.        bot.hawkEye.stop()
  4114.        bot.respawn
  4115.        bot.chat('I died x.x ugh!!')
  4116.        // need instructions to return to
  4117.        // what i was doing.
  4118.    })
  4119.  
  4120.    bot.on('kicked', (reason) => {
  4121.        console.log(`I got kicked for ${reason}`)
  4122.    })
  4123.    
  4124.    bot.on('rain', () => {
  4125.        if (bot.isRaining) {
  4126.            console.log('It started raining.')
  4127.            //bot.chat('It started raining.')
  4128.        } else {
  4129.            console.log('It stopped raining.')
  4130.            //bot.chat('It stopped raining.')
  4131.        }
  4132.    })
  4133.  
  4134.    bot.on('noteHeard', (block, instrument, pitch) => {
  4135.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  4136.    })
  4137.  
  4138.    bot.on('chestLidMove', (block, isOpen) => {
  4139.        const action = isOpen ? 'open' : 'close'
  4140.        bot.chat(`Hey, did someone just ${action} a chest?`)
  4141.    })
  4142.  
  4143.    bot.on('pistonMove', (block, isPulling, direction) => {
  4144.        const action = isPulling ? 'pulling' : 'pushing'
  4145.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  4146.    })
  4147.  
  4148.    bot.on('playerJoined', (player) => {
  4149.        if (player.username !== bot.username) {
  4150.            console.log(`${player.username}! Joined the server.`)
  4151.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  4152.        }
  4153.    })
  4154.  
  4155.    bot.on('playerLeft', (player) => {
  4156.        if (player.username === bot.username) return
  4157.        console.log(`${player.username} left the server`)
  4158.        // bot.chat(`Bye ${player.username}`)
  4159.    })
  4160.    /*
  4161.    bot.on('playerCollect', (collector, collected) => {
  4162.        if (collector.type === 'player' && collected.type === 'object') {
  4163.            const rawItem = collected.metadata[10]
  4164.            const item = mineflayer.Item.fromNotch(rawItem)
  4165.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  4166.        }
  4167.    })
  4168.    */
  4169.    /*    
  4170.    bot.on('entitySpawn', (entity) => {
  4171.        if (entity.type === 'mob') {
  4172.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  4173.        } else if (entity.type === 'player') {
  4174.            console.log(`Look who decided to show up: ${entity.username}`)
  4175.        } else if (entity.type === 'object') {
  4176.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  4177.        } else if (entity.type === 'global') {
  4178.            console.log('Ooh lightning!')
  4179.        } else if (entity.type === 'orb') {
  4180.            console.log('Gimme dat exp orb!')
  4181.        }
  4182.    })
  4183.    */    
  4184.  
  4185.    const target = bot.hawkEye.getPlayer()
  4186.    console.log(target)
  4187.    if (!target) {
  4188.        return false
  4189.    }
  4190.  
  4191.    function Start() {
  4192.        bot.hawkEye.autoAttack(target)
  4193.    }
  4194.  
  4195.    bot.on('entityHurt', (entity) => {
  4196.        if (entity.type === 'mob') {
  4197.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  4198.        } else if (entity.type === 'player') {
  4199.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  4200.        }
  4201.    })
  4202.  
  4203.    bot.on('entitySwingArm', (entity) => {
  4204.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  4205.    })
  4206.  
  4207.    bot.on('entityCrouch', (entity) => {
  4208.        bot.chat(`${entity.username}: you so sneaky.`)
  4209.    })
  4210.  
  4211.    bot.on('entityUncrouch', (entity) => {
  4212.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  4213.    })
  4214.  
  4215.    bot.on('entitySleep', (entity) => {
  4216.        bot.chat(`Good night, ${entity.username}`)
  4217.    })
  4218.  
  4219.    bot.on('entityWake', (entity) => {
  4220.        bot.chat(`Top of the morning, ${entity.username}`)
  4221.    })
  4222.  
  4223.    bot.on('entityEat', (entity) => {
  4224.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  4225.    })
  4226.  
  4227.    bot.on('entityAttach', (entity, vehicle) => {
  4228.        if (entity.type === 'player' && vehicle.type === 'object') {
  4229.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  4230.        }
  4231.    })
  4232.  
  4233.    bot.on('entityDetach', (entity, vehicle) => {
  4234.        if (entity.type === 'player' && vehicle.type === 'object') {
  4235.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  4236.        }
  4237.    })
  4238.  
  4239.    bot.on('entityEquipmentChange', (entity) => {
  4240.        console.log('entityEquipmentChange', entity)
  4241.    })
  4242.  
  4243.    bot.on('entityEffect', (entity, effect) => {
  4244.        console.log('entityEffect', entity, effect)
  4245.    })
  4246.  
  4247.    bot.on('entityEffectEnd', (entity, effect) => {
  4248.        console.log('entityEffectEnd', entity, effect)
  4249.    })
  4250.  
  4251.    function guardArea(pos) {
  4252.        guardPos = pos.clone()
  4253.        
  4254.        if (!bot.pvp.target) {
  4255.            moveToGuardPos()
  4256.        }
  4257.    }
  4258.    
  4259.    function stopGuarding() {
  4260.        guardPos = null
  4261.        bot.pvp.stop()
  4262.        bot.pathfinder.setGoal(null)
  4263.    }
  4264.    
  4265.    function moveToGuardPos() {
  4266.        const mcData = require('minecraft-data')(bot.version)
  4267.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  4268.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  4269.    }
  4270.    
  4271.    bot.on('stoppedAttacking', () => {
  4272.        if (guardPos) {
  4273.            moveToGuardPos()
  4274.        }
  4275.    })
  4276.    
  4277.    bot.on('physicTick', () => {
  4278.        if (bot.pvp.target) return
  4279.        if (bot.pathfinder.isMoving()) return
  4280.        
  4281.        const entity = bot.nearestEntity()
  4282.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  4283.    })
  4284.    
  4285.    bot.on('physicTick', () => {
  4286.        if (!guardPos) return
  4287.        
  4288.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  4289.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  4290.        
  4291.        const entity = bot.nearestEntity(filter)
  4292.        if (entity) {
  4293.            bot.pvp.attack(entity)
  4294.        }
  4295.    })
  4296.    /*
  4297.    bot.on('chat', (username, message) => {
  4298.        if (username === bot.username) return
  4299.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  4300.        if (result) {
  4301.            canSee(new Vec3(result[1], result[2], result[3]))
  4302.            return
  4303.        }
  4304.        switch (message) {
  4305.            case 'pos':
  4306.                console.log("pos command used")
  4307.                sayPosition(username)
  4308.                break
  4309.            case 'wearing':
  4310.                console.log("wearing command used")
  4311.                sayEquipment()
  4312.                break
  4313.            case 'nick':
  4314.                console.log("saynick command used")
  4315.                sayNick()
  4316.                break
  4317.            case 'spawn':
  4318.                console.log("spawn command used")
  4319.                saySpawnPoint()
  4320.                break
  4321.            case 'block':
  4322.                console.log("block command used")
  4323.                sayBlockUnder(username)
  4324.                break
  4325.            default:
  4326.                console.log("I am ready!")
  4327.                bot.chat("I am ready!")
  4328.    }
  4329.    */
  4330.  
  4331.    // text of bots username and help will give a list of bot commands
  4332.    bot.on('chat', (username, message) => { // work in progress....
  4333.        if (message === `${bot.player.displayName} help`)
  4334.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  4335.            bot.chat('pos, wearing, nick, spawn, block ')
  4336.            bot.chat('arch-start, Version.(wip not all commands work...)')
  4337.            bot.chat('Bot may just leave if it errors out.')
  4338.    })
  4339.  
  4340.    bot.on('chat', (username, message) => { // work in progress....
  4341.        if (message === 'Version') {
  4342.            console.log("Version command used just used")
  4343.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  4344.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  4345.            console.log("sayVersion command used")
  4346.            sayVersion(username)
  4347.            return
  4348.        }
  4349.    })
  4350.  
  4351.    bot.on('chat', (username, message) => {
  4352.        if (message === 'leave') {
  4353.                console.log("leave command used")
  4354.                bot.chat("Yes sir right away!")
  4355.                bot.quit(username)
  4356.                return
  4357.        }
  4358.    })
  4359.  
  4360.    bot.on('chat', (username, message) => {
  4361.        if (message === 'arch-start') {
  4362.            console.log("arch-start command used")
  4363.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  4364.            Start()
  4365.            return
  4366.        }
  4367.    })
  4368.  
  4369.    bot.on('chat', (username, message) => {
  4370.        if (message === 'guard') {          // if message guard do gaurd
  4371.            const player = bot.players[username]
  4372.  
  4373.            if (!player) {
  4374.                bot.chat("I can't see you.")
  4375.                return
  4376.            }
  4377.        bot.chat('I will guard that location.')
  4378.            guardArea(player.entity.position)
  4379.            }
  4380.  
  4381.            if (message === 'fight me') {
  4382.                const player = bot.players[username]
  4383.  
  4384.                if (!player) {
  4385.                    bot.chat("I can't see you.")
  4386.                    return
  4387.                }
  4388.  
  4389.            bot.chat('Prepare to fight!')
  4390.            bot.chat('5')
  4391.            bot.chat('4')
  4392.            bot.chat('3')
  4393.            bot.chat('2')
  4394.            bot.chat('1')
  4395.            bot.chat('GO!!!')
  4396.            bot.pvp.attack(player.entity)
  4397.            }
  4398.  
  4399.            if (message === 'stop') {
  4400.                bot.chat('I will stop!')
  4401.                bot.hawkEye.stop()
  4402.                stopGuarding()
  4403.            }
  4404.    })
  4405.  
  4406.    function not_busy() {
  4407.        guardPos = pos.clone()
  4408.  
  4409.        if (guardPos == null) {
  4410.            return false
  4411.        
  4412.        } else { (guardPos == !null)
  4413.                return true
  4414.            }
  4415.        }
  4416.    
  4417.    
  4418.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  4419.        if (busy == true) {
  4420.        console.log("I am busy!")
  4421.        bot.chat("I am busy!")
  4422.            } else { if (busy == false)
  4423.            console.log('I am ready!')
  4424.            bot.chat('I am ready!')
  4425.            }
  4426.    
  4427.    })
  4428.  
  4429.    bot.on('sleep', () => {
  4430.        bot.chat('Good night!')
  4431.    })
  4432.  
  4433.    bot.on('wake', () => {
  4434.        bot.chat('Good morning!')
  4435.    })
  4436.  
  4437.    function goToSleep() {
  4438.        const bed = bot.findBlock({
  4439.            matching: block => bot.isABed(block)
  4440.        })
  4441.        if (bed) {
  4442.            bot.sleep(bed, (err) => {
  4443.                if (err) {
  4444.                    bot.chat(`I can't sleep: ${err.message}`)
  4445.                } else {
  4446.                    bot.chat("I'm sleeping")
  4447.                }
  4448.            })
  4449.        } else {
  4450.            bot.chat('No nearby bed')
  4451.        }
  4452.    }
  4453.  
  4454.    function wakeUp() {
  4455.        bot.wake((err) => {
  4456.            if (err) {
  4457.                bot.chat(`I can't wake up: ${err.message}`)
  4458.             } else {
  4459.                 bot.chat('I woke up')
  4460.             }
  4461.         }
  4462.        
  4463.     )
  4464. }
  4465. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  4466. const Vec3 = require('vec3').Vec3
  4467. const fs = require('fs')
  4468. const { version } = require('os')
  4469. const pvp = require('mineflayer-pvp').plugin
  4470. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  4471. const armorManager = require('mineflayer-armor-manager')
  4472. const autoeat = require('mineflayer-auto-eat')
  4473. const minecraftHawkEye = require('minecrafthawkeye')
  4474.  
  4475. function jsonReader(filePath, cb) {
  4476.     fs.readFile(filePath, (err, fileData) => {
  4477.         if (err) {
  4478.             return cb && cb(err)
  4479.         }
  4480.         try {
  4481.             const object = JSON.parse(fileData)
  4482.             return cb && cb(null, object)
  4483.         } catch (err) {
  4484.             return cb && cb(err)
  4485.         }
  4486.     })
  4487. }
  4488.  
  4489. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  4490.     if (err) {
  4491.         console.log(err)
  4492.         return
  4493.     }
  4494.  
  4495.     const bot = mineflayer.createBot({
  4496.         version: mc_login_info.version,
  4497.         host: mc_login_info.host,
  4498.         port: mc_login_info.port,
  4499.         username: mc_login_info.username,
  4500.         password: mc_login_info.password,
  4501.         // give time for communication to hosts&client with longer ping times
  4502.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  4503.         logErrors: true
  4504.     })
  4505. })
  4506.  
  4507.     bot._client.on('custom_payload', (packet) => {
  4508.         // console.log(packet)
  4509.         if (packet.channel === "minecraft:brand") {
  4510.             let data = packet.data
  4511.             let brand = String.fromCharCode.apply(null, data)
  4512.             console.log(brand)
  4513.         }
  4514.     })
  4515.  
  4516.     bot.once('login', () => {
  4517.         console.log('logged in')
  4518.         console.log(`curent client version ${bot.version}`)
  4519.         // console.log(`curent server version is ${server.version}`)
  4520.     })
  4521.  
  4522.     bot.loadPlugin(autoeat)
  4523.     bot.loadPlugin(armorManager)
  4524.     bot.loadPlugin(minecraftHawkEye)
  4525.     bot.loadPlugin(pathfinder)
  4526.     bot.loadPlugin(pvp)
  4527.  
  4528.    
  4529.     bot.on('playerCollect', (collector, itemDrop) => {
  4530.         if (collector !== bot.entity) return
  4531.        
  4532.         setTimeout(() => {
  4533.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  4534.             if (sword) bot.equip(sword, 'hand')
  4535.         }, 150)
  4536.     })
  4537.    
  4538.     bot.on('playerCollect', (collector, itemDrop) => {
  4539.         if (collector !== bot.entity) return
  4540.        
  4541.         setTimeout(() => {
  4542.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  4543.             if (shield) bot.equip(shield, 'off-hand')
  4544.         }, 250)
  4545.     })
  4546.    
  4547.     let guardPos = null
  4548.     let busy = false
  4549.  
  4550.     bot.on('spawn', () => { // gives error when bot spawns
  4551.         console.log('spawned in server')
  4552.         bot.hawkEye.stop()
  4553.         stopGuarding()
  4554.         bot.chat('I spawned, watch out!')
  4555.     })
  4556.    
  4557.     function canSee(pos) {
  4558.         const block = bot.blockAt(pos)
  4559.         const r = bot.canSeeBlock(block)
  4560.         if (r) {
  4561.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  4562.         } else {
  4563.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  4564.         }
  4565.     }
  4566.    
  4567.     function sayPosition(username) {
  4568.         //bot.chat(`My puplic position is disabled`)
  4569.         bot.chat(`I am at ${bot.entity.position}`)
  4570.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  4571.         //bot.chat(`I don't know your position.`)
  4572.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  4573.    }
  4574.  
  4575.    function sayEquipment() {
  4576.        const eq = bot.players[username].entity.equipment
  4577.        const eqText = []
  4578.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  4579.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  4580.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  4581.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  4582.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  4583.        if (eqText.length) {
  4584.            bot.chat(`You are ${eqText.join(', ')}.`)
  4585.        } else {
  4586.            bot.chat('You are without armor!')
  4587.        }
  4588.    }
  4589.  
  4590.    function sayVersion() { // work in prograss not working yet
  4591.        bot.chat('/version')
  4592.        console.log(`${command.message} confermed ${brand}`)
  4593.    }
  4594.  
  4595.    function saySpawnPoint() {
  4596.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  4597.    }
  4598.  
  4599.    function sayBlockUnder() {
  4600.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  4601.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  4602.        console.log(block)
  4603.    }
  4604.  
  4605.    function quit(username) {
  4606.        console.log('quit command used')
  4607.        bot.quit(`${username} told me too`)
  4608.    }
  4609.  
  4610.    function sayNick() {
  4611.        bot.chat(`My name is ${bot.player.displayName}`)
  4612.    }
  4613.    
  4614.    // begin of autoeats paste
  4615.    bot.once('spawn', () => {
  4616.        bot.autoEat.options = {
  4617.            priority: 'foodPoints',
  4618.            startAt: 14,
  4619.            bannedFood: []
  4620.        }
  4621.    })
  4622.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  4623.    bot.on('autoeat_started', () => {
  4624.        console.log('Auto Eat started!')
  4625.    })
  4626.  
  4627.    bot.on('autoeat_stopped', () => {
  4628.        console.log('Auto Eat stopped!')
  4629.    })
  4630.  
  4631.    bot.on('health', () => {
  4632.        if (bot.food === 20) bot.autoEat.disable()
  4633.        // Disable the plugin if the bot is at 20 food points
  4634.        else bot.autoEat.enable() // Else enable the plugin again
  4635.    })
  4636.    // end of paste autoeat
  4637.  
  4638.    bot.on('whisper', (username, message, rawMessage) => {
  4639.        console.log(`I received a message from ${username}: ${message}`)
  4640.        bot.whisper(username, 'I can tell secrets too.')
  4641.    })
  4642.  
  4643.    bot.on('nonSpokenChat', (message) => {
  4644.        console.log(`Non spoken chat: ${message}`)
  4645.    })
  4646.    
  4647.    bot.on('login', () => {
  4648.        bot.chat('Hi everyone!')
  4649.    })
  4650.    
  4651.    bot.on('spawnReset', (message) => {
  4652.        console.log('spawnReset command used')
  4653.        stopGuarding()
  4654.        bot.hawkEye.stop()
  4655.        bot.chat('Oh noez! My bed is broken.')
  4656.    })
  4657.    
  4658.    bot.on('forcedMove', () => {
  4659.        console.log(`I have been forced to move to ${bot.entity.position}`)
  4660.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  4661.    })
  4662.    
  4663.    bot.on('health', () => {
  4664.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  4665.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  4666.    })
  4667.  
  4668.    bot.on('death', () => {
  4669.        console.log('I died, stopping and respawning')
  4670.        stopGuarding()
  4671.        bot.hawkEye.stop()
  4672.        bot.respawn
  4673.        bot.chat('I died x.x ugh!!')
  4674.        // need instructions to return to
  4675.        // what i was doing.
  4676.    })
  4677.  
  4678.    bot.on('kicked', (reason) => {
  4679.        console.log(`I got kicked for ${reason}`)
  4680.    })
  4681.    
  4682.    bot.on('rain', () => {
  4683.        if (bot.isRaining) {
  4684.            console.log('It started raining.')
  4685.            //bot.chat('It started raining.')
  4686.        } else {
  4687.            console.log('It stopped raining.')
  4688.            //bot.chat('It stopped raining.')
  4689.        }
  4690.    })
  4691.  
  4692.    bot.on('noteHeard', (block, instrument, pitch) => {
  4693.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  4694.    })
  4695.  
  4696.    bot.on('chestLidMove', (block, isOpen) => {
  4697.        const action = isOpen ? 'open' : 'close'
  4698.        bot.chat(`Hey, did someone just ${action} a chest?`)
  4699.    })
  4700.  
  4701.    bot.on('pistonMove', (block, isPulling, direction) => {
  4702.        const action = isPulling ? 'pulling' : 'pushing'
  4703.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  4704.    })
  4705.  
  4706.    bot.on('playerJoined', (player) => {
  4707.        if (player.username !== bot.username) {
  4708.            console.log(`${player.username}! Joined the server.`)
  4709.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  4710.        }
  4711.    })
  4712.  
  4713.    bot.on('playerLeft', (player) => {
  4714.        if (player.username === bot.username) return
  4715.        console.log(`${player.username} left the server`)
  4716.        // bot.chat(`Bye ${player.username}`)
  4717.    })
  4718.    /*
  4719.    bot.on('playerCollect', (collector, collected) => {
  4720.        if (collector.type === 'player' && collected.type === 'object') {
  4721.            const rawItem = collected.metadata[10]
  4722.            const item = mineflayer.Item.fromNotch(rawItem)
  4723.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  4724.        }
  4725.    })
  4726.    */
  4727.    /*    
  4728.    bot.on('entitySpawn', (entity) => {
  4729.        if (entity.type === 'mob') {
  4730.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  4731.        } else if (entity.type === 'player') {
  4732.            console.log(`Look who decided to show up: ${entity.username}`)
  4733.        } else if (entity.type === 'object') {
  4734.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  4735.        } else if (entity.type === 'global') {
  4736.            console.log('Ooh lightning!')
  4737.        } else if (entity.type === 'orb') {
  4738.            console.log('Gimme dat exp orb!')
  4739.        }
  4740.    })
  4741.    */    
  4742.  
  4743.    const target = bot.hawkEye.getPlayer()
  4744.    console.log(target)
  4745.    if (!target) {
  4746.        return false
  4747.    }
  4748.  
  4749.    function Start() {
  4750.        bot.hawkEye.autoAttack(target)
  4751.    }
  4752.  
  4753.    bot.on('entityHurt', (entity) => {
  4754.        if (entity.type === 'mob') {
  4755.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  4756.        } else if (entity.type === 'player') {
  4757.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  4758.        }
  4759.    })
  4760.  
  4761.    bot.on('entitySwingArm', (entity) => {
  4762.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  4763.    })
  4764.  
  4765.    bot.on('entityCrouch', (entity) => {
  4766.        bot.chat(`${entity.username}: you so sneaky.`)
  4767.    })
  4768.  
  4769.    bot.on('entityUncrouch', (entity) => {
  4770.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  4771.    })
  4772.  
  4773.    bot.on('entitySleep', (entity) => {
  4774.        bot.chat(`Good night, ${entity.username}`)
  4775.    })
  4776.  
  4777.    bot.on('entityWake', (entity) => {
  4778.        bot.chat(`Top of the morning, ${entity.username}`)
  4779.    })
  4780.  
  4781.    bot.on('entityEat', (entity) => {
  4782.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  4783.    })
  4784.  
  4785.    bot.on('entityAttach', (entity, vehicle) => {
  4786.        if (entity.type === 'player' && vehicle.type === 'object') {
  4787.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  4788.        }
  4789.    })
  4790.  
  4791.    bot.on('entityDetach', (entity, vehicle) => {
  4792.        if (entity.type === 'player' && vehicle.type === 'object') {
  4793.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  4794.        }
  4795.    })
  4796.  
  4797.    bot.on('entityEquipmentChange', (entity) => {
  4798.        console.log('entityEquipmentChange', entity)
  4799.    })
  4800.  
  4801.    bot.on('entityEffect', (entity, effect) => {
  4802.        console.log('entityEffect', entity, effect)
  4803.    })
  4804.  
  4805.    bot.on('entityEffectEnd', (entity, effect) => {
  4806.        console.log('entityEffectEnd', entity, effect)
  4807.    })
  4808.  
  4809.    function guardArea(pos) {
  4810.        guardPos = pos.clone()
  4811.        
  4812.        if (!bot.pvp.target) {
  4813.            moveToGuardPos()
  4814.        }
  4815.    }
  4816.    
  4817.    function stopGuarding() {
  4818.        guardPos = null
  4819.        bot.pvp.stop()
  4820.        bot.pathfinder.setGoal(null)
  4821.    }
  4822.    
  4823.    function moveToGuardPos() {
  4824.        const mcData = require('minecraft-data')(bot.version)
  4825.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  4826.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  4827.    }
  4828.    
  4829.    bot.on('stoppedAttacking', () => {
  4830.        if (guardPos) {
  4831.            moveToGuardPos()
  4832.        }
  4833.    })
  4834.    
  4835.    bot.on('physicTick', () => {
  4836.        if (bot.pvp.target) return
  4837.        if (bot.pathfinder.isMoving()) return
  4838.        
  4839.        const entity = bot.nearestEntity()
  4840.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  4841.    })
  4842.    
  4843.    bot.on('physicTick', () => {
  4844.        if (!guardPos) return
  4845.        
  4846.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  4847.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  4848.        
  4849.        const entity = bot.nearestEntity(filter)
  4850.        if (entity) {
  4851.            bot.pvp.attack(entity)
  4852.        }
  4853.    })
  4854.    /*
  4855.    bot.on('chat', (username, message) => {
  4856.        if (username === bot.username) return
  4857.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  4858.        if (result) {
  4859.            canSee(new Vec3(result[1], result[2], result[3]))
  4860.            return
  4861.        }
  4862.        switch (message) {
  4863.            case 'pos':
  4864.                console.log("pos command used")
  4865.                sayPosition(username)
  4866.                break
  4867.            case 'wearing':
  4868.                console.log("wearing command used")
  4869.                sayEquipment()
  4870.                break
  4871.            case 'nick':
  4872.                console.log("saynick command used")
  4873.                sayNick()
  4874.                break
  4875.            case 'spawn':
  4876.                console.log("spawn command used")
  4877.                saySpawnPoint()
  4878.                break
  4879.            case 'block':
  4880.                console.log("block command used")
  4881.                sayBlockUnder(username)
  4882.                break
  4883.            default:
  4884.                console.log("I am ready!")
  4885.                bot.chat("I am ready!")
  4886.    }
  4887.    */
  4888.  
  4889.    // text of bots username and help will give a list of bot commands
  4890.    bot.on('chat', (username, message) => { // work in progress....
  4891.        if (message === `${bot.player.displayName} help`)
  4892.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  4893.            bot.chat('pos, wearing, nick, spawn, block ')
  4894.            bot.chat('arch-start, Version.(wip not all commands work...)')
  4895.            bot.chat('Bot may just leave if it errors out.')
  4896.    })
  4897.  
  4898.    bot.on('chat', (username, message) => { // work in progress....
  4899.        if (message === 'Version') {
  4900.            console.log("Version command used just used")
  4901.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  4902.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  4903.            console.log("sayVersion command used")
  4904.            sayVersion(username)
  4905.            return
  4906.        }
  4907.    })
  4908.  
  4909.    bot.on('chat', (username, message) => {
  4910.        if (message === 'leave') {
  4911.                console.log("leave command used")
  4912.                bot.chat("Yes sir right away!")
  4913.                bot.quit(username)
  4914.                return
  4915.        }
  4916.    })
  4917.  
  4918.    bot.on('chat', (username, message) => {
  4919.        if (message === 'arch-start') {
  4920.            console.log("arch-start command used")
  4921.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  4922.            Start()
  4923.            return
  4924.        }
  4925.    })
  4926.  
  4927.    bot.on('chat', (username, message) => {
  4928.        if (message === 'guard') {          // if message guard do gaurd
  4929.            const player = bot.players[username]
  4930.  
  4931.            if (!player) {
  4932.                bot.chat("I can't see you.")
  4933.                return
  4934.            }
  4935.        bot.chat('I will guard that location.')
  4936.            guardArea(player.entity.position)
  4937.            }
  4938.  
  4939.            if (message === 'fight me') {
  4940.                const player = bot.players[username]
  4941.  
  4942.                if (!player) {
  4943.                    bot.chat("I can't see you.")
  4944.                    return
  4945.                }
  4946.  
  4947.            bot.chat('Prepare to fight!')
  4948.            bot.chat('5')
  4949.            bot.chat('4')
  4950.            bot.chat('3')
  4951.            bot.chat('2')
  4952.            bot.chat('1')
  4953.            bot.chat('GO!!!')
  4954.            bot.pvp.attack(player.entity)
  4955.            }
  4956.  
  4957.            if (message === 'stop') {
  4958.                bot.chat('I will stop!')
  4959.                bot.hawkEye.stop()
  4960.                stopGuarding()
  4961.            }
  4962.    })
  4963.  
  4964.    function not_busy() {
  4965.        guardPos = pos.clone()
  4966.  
  4967.        if (guardPos == null) {
  4968.            return false
  4969.        
  4970.        } else { (guardPos == !null)
  4971.                return true
  4972.            }
  4973.        }
  4974.    
  4975.    
  4976.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  4977.        if (busy == true) {
  4978.        console.log("I am busy!")
  4979.        bot.chat("I am busy!")
  4980.            } else { if (busy == false)
  4981.            console.log('I am ready!')
  4982.            bot.chat('I am ready!')
  4983.            }
  4984.    
  4985.    })
  4986.  
  4987.    bot.on('sleep', () => {
  4988.        bot.chat('Good night!')
  4989.    })
  4990.  
  4991.    bot.on('wake', () => {
  4992.        bot.chat('Good morning!')
  4993.    })
  4994.  
  4995.    function goToSleep() {
  4996.        const bed = bot.findBlock({
  4997.            matching: block => bot.isABed(block)
  4998.        })
  4999.        if (bed) {
  5000.            bot.sleep(bed, (err) => {
  5001.                if (err) {
  5002.                    bot.chat(`I can't sleep: ${err.message}`)
  5003.                } else {
  5004.                    bot.chat("I'm sleeping")
  5005.                }
  5006.            })
  5007.        } else {
  5008.            bot.chat('No nearby bed')
  5009.        }
  5010.    }
  5011.  
  5012.    function wakeUp() {
  5013.        bot.wake((err) => {
  5014.            if (err) {
  5015.                bot.chat(`I can't wake up: ${err.message}`)
  5016.             } else {
  5017.                 bot.chat('I woke up')
  5018.             }
  5019.         }
  5020.        
  5021.     )
  5022. }
  5023. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  5024. const Vec3 = require('vec3').Vec3
  5025. const fs = require('fs')
  5026. const { version } = require('os')
  5027. const pvp = require('mineflayer-pvp').plugin
  5028. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  5029. const armorManager = require('mineflayer-armor-manager')
  5030. const autoeat = require('mineflayer-auto-eat')
  5031. const minecraftHawkEye = require('minecrafthawkeye')
  5032.  
  5033. function jsonReader(filePath, cb) {
  5034.     fs.readFile(filePath, (err, fileData) => {
  5035.         if (err) {
  5036.             return cb && cb(err)
  5037.         }
  5038.         try {
  5039.             const object = JSON.parse(fileData)
  5040.             return cb && cb(null, object)
  5041.         } catch (err) {
  5042.             return cb && cb(err)
  5043.         }
  5044.     })
  5045. }
  5046.  
  5047. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  5048.     if (err) {
  5049.         console.log(err)
  5050.         return
  5051.     }
  5052.  
  5053.     const bot = mineflayer.createBot({
  5054.         version: mc_login_info.version,
  5055.         host: mc_login_info.host,
  5056.         port: mc_login_info.port,
  5057.         username: mc_login_info.username,
  5058.         password: mc_login_info.password,
  5059.         // give time for communication to hosts&client with longer ping times
  5060.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  5061.         logErrors: true
  5062.     })
  5063. })
  5064.  
  5065.     bot._client.on('custom_payload', (packet) => {
  5066.         // console.log(packet)
  5067.         if (packet.channel === "minecraft:brand") {
  5068.             let data = packet.data
  5069.             let brand = String.fromCharCode.apply(null, data)
  5070.             console.log(brand)
  5071.         }
  5072.     })
  5073.  
  5074.     bot.once('login', () => {
  5075.         console.log('logged in')
  5076.         console.log(`curent client version ${bot.version}`)
  5077.         // console.log(`curent server version is ${server.version}`)
  5078.     })
  5079.  
  5080.     bot.loadPlugin(autoeat)
  5081.     bot.loadPlugin(armorManager)
  5082.     bot.loadPlugin(minecraftHawkEye)
  5083.     bot.loadPlugin(pathfinder)
  5084.     bot.loadPlugin(pvp)
  5085.  
  5086.    
  5087.     bot.on('playerCollect', (collector, itemDrop) => {
  5088.         if (collector !== bot.entity) return
  5089.        
  5090.         setTimeout(() => {
  5091.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  5092.             if (sword) bot.equip(sword, 'hand')
  5093.         }, 150)
  5094.     })
  5095.    
  5096.     bot.on('playerCollect', (collector, itemDrop) => {
  5097.         if (collector !== bot.entity) return
  5098.        
  5099.         setTimeout(() => {
  5100.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  5101.             if (shield) bot.equip(shield, 'off-hand')
  5102.         }, 250)
  5103.     })
  5104.    
  5105.     let guardPos = null
  5106.     let busy = false
  5107.  
  5108.     bot.on('spawn', () => { // gives error when bot spawns
  5109.         console.log('spawned in server')
  5110.         bot.hawkEye.stop()
  5111.         stopGuarding()
  5112.         bot.chat('I spawned, watch out!')
  5113.     })
  5114.    
  5115.     function canSee(pos) {
  5116.         const block = bot.blockAt(pos)
  5117.         const r = bot.canSeeBlock(block)
  5118.         if (r) {
  5119.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  5120.         } else {
  5121.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  5122.         }
  5123.     }
  5124.    
  5125.     function sayPosition(username) {
  5126.         //bot.chat(`My puplic position is disabled`)
  5127.         bot.chat(`I am at ${bot.entity.position}`)
  5128.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  5129.         //bot.chat(`I don't know your position.`)
  5130.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  5131.    }
  5132.  
  5133.    function sayEquipment() {
  5134.        const eq = bot.players[username].entity.equipment
  5135.        const eqText = []
  5136.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  5137.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  5138.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  5139.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  5140.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  5141.        if (eqText.length) {
  5142.            bot.chat(`You are ${eqText.join(', ')}.`)
  5143.        } else {
  5144.            bot.chat('You are without armor!')
  5145.        }
  5146.    }
  5147.  
  5148.    function sayVersion() { // work in prograss not working yet
  5149.        bot.chat('/version')
  5150.        console.log(`${command.message} confermed ${brand}`)
  5151.    }
  5152.  
  5153.    function saySpawnPoint() {
  5154.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  5155.    }
  5156.  
  5157.    function sayBlockUnder() {
  5158.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  5159.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  5160.        console.log(block)
  5161.    }
  5162.  
  5163.    function quit(username) {
  5164.        console.log('quit command used')
  5165.        bot.quit(`${username} told me too`)
  5166.    }
  5167.  
  5168.    function sayNick() {
  5169.        bot.chat(`My name is ${bot.player.displayName}`)
  5170.    }
  5171.    
  5172.    // begin of autoeats paste
  5173.    bot.once('spawn', () => {
  5174.        bot.autoEat.options = {
  5175.            priority: 'foodPoints',
  5176.            startAt: 14,
  5177.            bannedFood: []
  5178.        }
  5179.    })
  5180.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  5181.    bot.on('autoeat_started', () => {
  5182.        console.log('Auto Eat started!')
  5183.    })
  5184.  
  5185.    bot.on('autoeat_stopped', () => {
  5186.        console.log('Auto Eat stopped!')
  5187.    })
  5188.  
  5189.    bot.on('health', () => {
  5190.        if (bot.food === 20) bot.autoEat.disable()
  5191.        // Disable the plugin if the bot is at 20 food points
  5192.        else bot.autoEat.enable() // Else enable the plugin again
  5193.    })
  5194.    // end of paste autoeat
  5195.  
  5196.    bot.on('whisper', (username, message, rawMessage) => {
  5197.        console.log(`I received a message from ${username}: ${message}`)
  5198.        bot.whisper(username, 'I can tell secrets too.')
  5199.    })
  5200.  
  5201.    bot.on('nonSpokenChat', (message) => {
  5202.        console.log(`Non spoken chat: ${message}`)
  5203.    })
  5204.    
  5205.    bot.on('login', () => {
  5206.        bot.chat('Hi everyone!')
  5207.    })
  5208.    
  5209.    bot.on('spawnReset', (message) => {
  5210.        console.log('spawnReset command used')
  5211.        stopGuarding()
  5212.        bot.hawkEye.stop()
  5213.        bot.chat('Oh noez! My bed is broken.')
  5214.    })
  5215.    
  5216.    bot.on('forcedMove', () => {
  5217.        console.log(`I have been forced to move to ${bot.entity.position}`)
  5218.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  5219.    })
  5220.    
  5221.    bot.on('health', () => {
  5222.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  5223.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  5224.    })
  5225.  
  5226.    bot.on('death', () => {
  5227.        console.log('I died, stopping and respawning')
  5228.        stopGuarding()
  5229.        bot.hawkEye.stop()
  5230.        bot.respawn
  5231.        bot.chat('I died x.x ugh!!')
  5232.        // need instructions to return to
  5233.        // what i was doing.
  5234.    })
  5235.  
  5236.    bot.on('kicked', (reason) => {
  5237.        console.log(`I got kicked for ${reason}`)
  5238.    })
  5239.    
  5240.    bot.on('rain', () => {
  5241.        if (bot.isRaining) {
  5242.            console.log('It started raining.')
  5243.            //bot.chat('It started raining.')
  5244.        } else {
  5245.            console.log('It stopped raining.')
  5246.            //bot.chat('It stopped raining.')
  5247.        }
  5248.    })
  5249.  
  5250.    bot.on('noteHeard', (block, instrument, pitch) => {
  5251.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  5252.    })
  5253.  
  5254.    bot.on('chestLidMove', (block, isOpen) => {
  5255.        const action = isOpen ? 'open' : 'close'
  5256.        bot.chat(`Hey, did someone just ${action} a chest?`)
  5257.    })
  5258.  
  5259.    bot.on('pistonMove', (block, isPulling, direction) => {
  5260.        const action = isPulling ? 'pulling' : 'pushing'
  5261.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  5262.    })
  5263.  
  5264.    bot.on('playerJoined', (player) => {
  5265.        if (player.username !== bot.username) {
  5266.            console.log(`${player.username}! Joined the server.`)
  5267.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  5268.        }
  5269.    })
  5270.  
  5271.    bot.on('playerLeft', (player) => {
  5272.        if (player.username === bot.username) return
  5273.        console.log(`${player.username} left the server`)
  5274.        // bot.chat(`Bye ${player.username}`)
  5275.    })
  5276.    /*
  5277.    bot.on('playerCollect', (collector, collected) => {
  5278.        if (collector.type === 'player' && collected.type === 'object') {
  5279.            const rawItem = collected.metadata[10]
  5280.            const item = mineflayer.Item.fromNotch(rawItem)
  5281.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  5282.        }
  5283.    })
  5284.    */
  5285.    /*    
  5286.    bot.on('entitySpawn', (entity) => {
  5287.        if (entity.type === 'mob') {
  5288.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  5289.        } else if (entity.type === 'player') {
  5290.            console.log(`Look who decided to show up: ${entity.username}`)
  5291.        } else if (entity.type === 'object') {
  5292.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  5293.        } else if (entity.type === 'global') {
  5294.            console.log('Ooh lightning!')
  5295.        } else if (entity.type === 'orb') {
  5296.            console.log('Gimme dat exp orb!')
  5297.        }
  5298.    })
  5299.    */    
  5300.  
  5301.    const target = bot.hawkEye.getPlayer()
  5302.    console.log(target)
  5303.    if (!target) {
  5304.        return false
  5305.    }
  5306.  
  5307.    function Start() {
  5308.        bot.hawkEye.autoAttack(target)
  5309.    }
  5310.  
  5311.    bot.on('entityHurt', (entity) => {
  5312.        if (entity.type === 'mob') {
  5313.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  5314.        } else if (entity.type === 'player') {
  5315.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  5316.        }
  5317.    })
  5318.  
  5319.    bot.on('entitySwingArm', (entity) => {
  5320.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  5321.    })
  5322.  
  5323.    bot.on('entityCrouch', (entity) => {
  5324.        bot.chat(`${entity.username}: you so sneaky.`)
  5325.    })
  5326.  
  5327.    bot.on('entityUncrouch', (entity) => {
  5328.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  5329.    })
  5330.  
  5331.    bot.on('entitySleep', (entity) => {
  5332.        bot.chat(`Good night, ${entity.username}`)
  5333.    })
  5334.  
  5335.    bot.on('entityWake', (entity) => {
  5336.        bot.chat(`Top of the morning, ${entity.username}`)
  5337.    })
  5338.  
  5339.    bot.on('entityEat', (entity) => {
  5340.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  5341.    })
  5342.  
  5343.    bot.on('entityAttach', (entity, vehicle) => {
  5344.        if (entity.type === 'player' && vehicle.type === 'object') {
  5345.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  5346.        }
  5347.    })
  5348.  
  5349.    bot.on('entityDetach', (entity, vehicle) => {
  5350.        if (entity.type === 'player' && vehicle.type === 'object') {
  5351.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  5352.        }
  5353.    })
  5354.  
  5355.    bot.on('entityEquipmentChange', (entity) => {
  5356.        console.log('entityEquipmentChange', entity)
  5357.    })
  5358.  
  5359.    bot.on('entityEffect', (entity, effect) => {
  5360.        console.log('entityEffect', entity, effect)
  5361.    })
  5362.  
  5363.    bot.on('entityEffectEnd', (entity, effect) => {
  5364.        console.log('entityEffectEnd', entity, effect)
  5365.    })
  5366.  
  5367.    function guardArea(pos) {
  5368.        guardPos = pos.clone()
  5369.        
  5370.        if (!bot.pvp.target) {
  5371.            moveToGuardPos()
  5372.        }
  5373.    }
  5374.    
  5375.    function stopGuarding() {
  5376.        guardPos = null
  5377.        bot.pvp.stop()
  5378.        bot.pathfinder.setGoal(null)
  5379.    }
  5380.    
  5381.    function moveToGuardPos() {
  5382.        const mcData = require('minecraft-data')(bot.version)
  5383.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  5384.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  5385.    }
  5386.    
  5387.    bot.on('stoppedAttacking', () => {
  5388.        if (guardPos) {
  5389.            moveToGuardPos()
  5390.        }
  5391.    })
  5392.    
  5393.    bot.on('physicTick', () => {
  5394.        if (bot.pvp.target) return
  5395.        if (bot.pathfinder.isMoving()) return
  5396.        
  5397.        const entity = bot.nearestEntity()
  5398.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  5399.    })
  5400.    
  5401.    bot.on('physicTick', () => {
  5402.        if (!guardPos) return
  5403.        
  5404.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  5405.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  5406.        
  5407.        const entity = bot.nearestEntity(filter)
  5408.        if (entity) {
  5409.            bot.pvp.attack(entity)
  5410.        }
  5411.    })
  5412.    /*
  5413.    bot.on('chat', (username, message) => {
  5414.        if (username === bot.username) return
  5415.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  5416.        if (result) {
  5417.            canSee(new Vec3(result[1], result[2], result[3]))
  5418.            return
  5419.        }
  5420.        switch (message) {
  5421.            case 'pos':
  5422.                console.log("pos command used")
  5423.                sayPosition(username)
  5424.                break
  5425.            case 'wearing':
  5426.                console.log("wearing command used")
  5427.                sayEquipment()
  5428.                break
  5429.            case 'nick':
  5430.                console.log("saynick command used")
  5431.                sayNick()
  5432.                break
  5433.            case 'spawn':
  5434.                console.log("spawn command used")
  5435.                saySpawnPoint()
  5436.                break
  5437.            case 'block':
  5438.                console.log("block command used")
  5439.                sayBlockUnder(username)
  5440.                break
  5441.            default:
  5442.                console.log("I am ready!")
  5443.                bot.chat("I am ready!")
  5444.    }
  5445.    */
  5446.  
  5447.    // text of bots username and help will give a list of bot commands
  5448.    bot.on('chat', (username, message) => { // work in progress....
  5449.        if (message === `${bot.player.displayName} help`)
  5450.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  5451.            bot.chat('pos, wearing, nick, spawn, block ')
  5452.            bot.chat('arch-start, Version.(wip not all commands work...)')
  5453.            bot.chat('Bot may just leave if it errors out.')
  5454.    })
  5455.  
  5456.    bot.on('chat', (username, message) => { // work in progress....
  5457.        if (message === 'Version') {
  5458.            console.log("Version command used just used")
  5459.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  5460.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  5461.            console.log("sayVersion command used")
  5462.            sayVersion(username)
  5463.            return
  5464.        }
  5465.    })
  5466.  
  5467.    bot.on('chat', (username, message) => {
  5468.        if (message === 'leave') {
  5469.                console.log("leave command used")
  5470.                bot.chat("Yes sir right away!")
  5471.                bot.quit(username)
  5472.                return
  5473.        }
  5474.    })
  5475.  
  5476.    bot.on('chat', (username, message) => {
  5477.        if (message === 'arch-start') {
  5478.            console.log("arch-start command used")
  5479.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  5480.            Start()
  5481.            return
  5482.        }
  5483.    })
  5484.  
  5485.    bot.on('chat', (username, message) => {
  5486.        if (message === 'guard') {          // if message guard do gaurd
  5487.            const player = bot.players[username]
  5488.  
  5489.            if (!player) {
  5490.                bot.chat("I can't see you.")
  5491.                return
  5492.            }
  5493.        bot.chat('I will guard that location.')
  5494.            guardArea(player.entity.position)
  5495.            }
  5496.  
  5497.            if (message === 'fight me') {
  5498.                const player = bot.players[username]
  5499.  
  5500.                if (!player) {
  5501.                    bot.chat("I can't see you.")
  5502.                    return
  5503.                }
  5504.  
  5505.            bot.chat('Prepare to fight!')
  5506.            bot.chat('5')
  5507.            bot.chat('4')
  5508.            bot.chat('3')
  5509.            bot.chat('2')
  5510.            bot.chat('1')
  5511.            bot.chat('GO!!!')
  5512.            bot.pvp.attack(player.entity)
  5513.            }
  5514.  
  5515.            if (message === 'stop') {
  5516.                bot.chat('I will stop!')
  5517.                bot.hawkEye.stop()
  5518.                stopGuarding()
  5519.            }
  5520.    })
  5521.  
  5522.    function not_busy() {
  5523.        guardPos = pos.clone()
  5524.  
  5525.        if (guardPos == null) {
  5526.            return false
  5527.        
  5528.        } else { (guardPos == !null)
  5529.                return true
  5530.            }
  5531.        }
  5532.    
  5533.    
  5534.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  5535.        if (busy == true) {
  5536.        console.log("I am busy!")
  5537.        bot.chat("I am busy!")
  5538.            } else { if (busy == false)
  5539.            console.log('I am ready!')
  5540.            bot.chat('I am ready!')
  5541.            }
  5542.    
  5543.    })
  5544.  
  5545.    bot.on('sleep', () => {
  5546.        bot.chat('Good night!')
  5547.    })
  5548.  
  5549.    bot.on('wake', () => {
  5550.        bot.chat('Good morning!')
  5551.    })
  5552.  
  5553.    function goToSleep() {
  5554.        const bed = bot.findBlock({
  5555.            matching: block => bot.isABed(block)
  5556.        })
  5557.        if (bed) {
  5558.            bot.sleep(bed, (err) => {
  5559.                if (err) {
  5560.                    bot.chat(`I can't sleep: ${err.message}`)
  5561.                } else {
  5562.                    bot.chat("I'm sleeping")
  5563.                }
  5564.            })
  5565.        } else {
  5566.            bot.chat('No nearby bed')
  5567.        }
  5568.    }
  5569.  
  5570.    function wakeUp() {
  5571.        bot.wake((err) => {
  5572.            if (err) {
  5573.                bot.chat(`I can't wake up: ${err.message}`)
  5574.             } else {
  5575.                 bot.chat('I woke up')
  5576.             }
  5577.         }
  5578.        
  5579.     )
  5580. }
  5581. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  5582. const Vec3 = require('vec3').Vec3
  5583. const fs = require('fs')
  5584. const { version } = require('os')
  5585. const pvp = require('mineflayer-pvp').plugin
  5586. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  5587. const armorManager = require('mineflayer-armor-manager')
  5588. const autoeat = require('mineflayer-auto-eat')
  5589. const minecraftHawkEye = require('minecrafthawkeye')
  5590.  
  5591. function jsonReader(filePath, cb) {
  5592.     fs.readFile(filePath, (err, fileData) => {
  5593.         if (err) {
  5594.             return cb && cb(err)
  5595.         }
  5596.         try {
  5597.             const object = JSON.parse(fileData)
  5598.             return cb && cb(null, object)
  5599.         } catch (err) {
  5600.             return cb && cb(err)
  5601.         }
  5602.     })
  5603. }
  5604.  
  5605. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  5606.     if (err) {
  5607.         console.log(err)
  5608.         return
  5609.     }
  5610.  
  5611.     const bot = mineflayer.createBot({
  5612.         version: mc_login_info.version,
  5613.         host: mc_login_info.host,
  5614.         port: mc_login_info.port,
  5615.         username: mc_login_info.username,
  5616.         password: mc_login_info.password,
  5617.         // give time for communication to hosts&client with longer ping times
  5618.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  5619.         logErrors: true
  5620.     })
  5621. })
  5622.  
  5623.     bot._client.on('custom_payload', (packet) => {
  5624.         // console.log(packet)
  5625.         if (packet.channel === "minecraft:brand") {
  5626.             let data = packet.data
  5627.             let brand = String.fromCharCode.apply(null, data)
  5628.             console.log(brand)
  5629.         }
  5630.     })
  5631.  
  5632.     bot.once('login', () => {
  5633.         console.log('logged in')
  5634.         console.log(`curent client version ${bot.version}`)
  5635.         // console.log(`curent server version is ${server.version}`)
  5636.     })
  5637.  
  5638.     bot.loadPlugin(autoeat)
  5639.     bot.loadPlugin(armorManager)
  5640.     bot.loadPlugin(minecraftHawkEye)
  5641.     bot.loadPlugin(pathfinder)
  5642.     bot.loadPlugin(pvp)
  5643.  
  5644.    
  5645.     bot.on('playerCollect', (collector, itemDrop) => {
  5646.         if (collector !== bot.entity) return
  5647.        
  5648.         setTimeout(() => {
  5649.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  5650.             if (sword) bot.equip(sword, 'hand')
  5651.         }, 150)
  5652.     })
  5653.    
  5654.     bot.on('playerCollect', (collector, itemDrop) => {
  5655.         if (collector !== bot.entity) return
  5656.        
  5657.         setTimeout(() => {
  5658.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  5659.             if (shield) bot.equip(shield, 'off-hand')
  5660.         }, 250)
  5661.     })
  5662.    
  5663.     let guardPos = null
  5664.     let busy = false
  5665.  
  5666.     bot.on('spawn', () => { // gives error when bot spawns
  5667.         console.log('spawned in server')
  5668.         bot.hawkEye.stop()
  5669.         stopGuarding()
  5670.         bot.chat('I spawned, watch out!')
  5671.     })
  5672.    
  5673.     function canSee(pos) {
  5674.         const block = bot.blockAt(pos)
  5675.         const r = bot.canSeeBlock(block)
  5676.         if (r) {
  5677.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  5678.         } else {
  5679.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  5680.         }
  5681.     }
  5682.    
  5683.     function sayPosition(username) {
  5684.         //bot.chat(`My puplic position is disabled`)
  5685.         bot.chat(`I am at ${bot.entity.position}`)
  5686.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  5687.         //bot.chat(`I don't know your position.`)
  5688.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  5689.    }
  5690.  
  5691.    function sayEquipment() {
  5692.        const eq = bot.players[username].entity.equipment
  5693.        const eqText = []
  5694.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  5695.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  5696.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  5697.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  5698.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  5699.        if (eqText.length) {
  5700.            bot.chat(`You are ${eqText.join(', ')}.`)
  5701.        } else {
  5702.            bot.chat('You are without armor!')
  5703.        }
  5704.    }
  5705.  
  5706.    function sayVersion() { // work in prograss not working yet
  5707.        bot.chat('/version')
  5708.        console.log(`${command.message} confermed ${brand}`)
  5709.    }
  5710.  
  5711.    function saySpawnPoint() {
  5712.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  5713.    }
  5714.  
  5715.    function sayBlockUnder() {
  5716.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  5717.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  5718.        console.log(block)
  5719.    }
  5720.  
  5721.    function quit(username) {
  5722.        console.log('quit command used')
  5723.        bot.quit(`${username} told me too`)
  5724.    }
  5725.  
  5726.    function sayNick() {
  5727.        bot.chat(`My name is ${bot.player.displayName}`)
  5728.    }
  5729.    
  5730.    // begin of autoeats paste
  5731.    bot.once('spawn', () => {
  5732.        bot.autoEat.options = {
  5733.            priority: 'foodPoints',
  5734.            startAt: 14,
  5735.            bannedFood: []
  5736.        }
  5737.    })
  5738.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  5739.    bot.on('autoeat_started', () => {
  5740.        console.log('Auto Eat started!')
  5741.    })
  5742.  
  5743.    bot.on('autoeat_stopped', () => {
  5744.        console.log('Auto Eat stopped!')
  5745.    })
  5746.  
  5747.    bot.on('health', () => {
  5748.        if (bot.food === 20) bot.autoEat.disable()
  5749.        // Disable the plugin if the bot is at 20 food points
  5750.        else bot.autoEat.enable() // Else enable the plugin again
  5751.    })
  5752.    // end of paste autoeat
  5753.  
  5754.    bot.on('whisper', (username, message, rawMessage) => {
  5755.        console.log(`I received a message from ${username}: ${message}`)
  5756.        bot.whisper(username, 'I can tell secrets too.')
  5757.    })
  5758.  
  5759.    bot.on('nonSpokenChat', (message) => {
  5760.        console.log(`Non spoken chat: ${message}`)
  5761.    })
  5762.    
  5763.    bot.on('login', () => {
  5764.        bot.chat('Hi everyone!')
  5765.    })
  5766.    
  5767.    bot.on('spawnReset', (message) => {
  5768.        console.log('spawnReset command used')
  5769.        stopGuarding()
  5770.        bot.hawkEye.stop()
  5771.        bot.chat('Oh noez! My bed is broken.')
  5772.    })
  5773.    
  5774.    bot.on('forcedMove', () => {
  5775.        console.log(`I have been forced to move to ${bot.entity.position}`)
  5776.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  5777.    })
  5778.    
  5779.    bot.on('health', () => {
  5780.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  5781.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  5782.    })
  5783.  
  5784.    bot.on('death', () => {
  5785.        console.log('I died, stopping and respawning')
  5786.        stopGuarding()
  5787.        bot.hawkEye.stop()
  5788.        bot.respawn
  5789.        bot.chat('I died x.x ugh!!')
  5790.        // need instructions to return to
  5791.        // what i was doing.
  5792.    })
  5793.  
  5794.    bot.on('kicked', (reason) => {
  5795.        console.log(`I got kicked for ${reason}`)
  5796.    })
  5797.    
  5798.    bot.on('rain', () => {
  5799.        if (bot.isRaining) {
  5800.            console.log('It started raining.')
  5801.            //bot.chat('It started raining.')
  5802.        } else {
  5803.            console.log('It stopped raining.')
  5804.            //bot.chat('It stopped raining.')
  5805.        }
  5806.    })
  5807.  
  5808.    bot.on('noteHeard', (block, instrument, pitch) => {
  5809.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  5810.    })
  5811.  
  5812.    bot.on('chestLidMove', (block, isOpen) => {
  5813.        const action = isOpen ? 'open' : 'close'
  5814.        bot.chat(`Hey, did someone just ${action} a chest?`)
  5815.    })
  5816.  
  5817.    bot.on('pistonMove', (block, isPulling, direction) => {
  5818.        const action = isPulling ? 'pulling' : 'pushing'
  5819.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  5820.    })
  5821.  
  5822.    bot.on('playerJoined', (player) => {
  5823.        if (player.username !== bot.username) {
  5824.            console.log(`${player.username}! Joined the server.`)
  5825.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  5826.        }
  5827.    })
  5828.  
  5829.    bot.on('playerLeft', (player) => {
  5830.        if (player.username === bot.username) return
  5831.        console.log(`${player.username} left the server`)
  5832.        // bot.chat(`Bye ${player.username}`)
  5833.    })
  5834.    /*
  5835.    bot.on('playerCollect', (collector, collected) => {
  5836.        if (collector.type === 'player' && collected.type === 'object') {
  5837.            const rawItem = collected.metadata[10]
  5838.            const item = mineflayer.Item.fromNotch(rawItem)
  5839.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  5840.        }
  5841.    })
  5842.    */
  5843.    /*    
  5844.    bot.on('entitySpawn', (entity) => {
  5845.        if (entity.type === 'mob') {
  5846.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  5847.        } else if (entity.type === 'player') {
  5848.            console.log(`Look who decided to show up: ${entity.username}`)
  5849.        } else if (entity.type === 'object') {
  5850.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  5851.        } else if (entity.type === 'global') {
  5852.            console.log('Ooh lightning!')
  5853.        } else if (entity.type === 'orb') {
  5854.            console.log('Gimme dat exp orb!')
  5855.        }
  5856.    })
  5857.    */    
  5858.  
  5859.    const target = bot.hawkEye.getPlayer()
  5860.    console.log(target)
  5861.    if (!target) {
  5862.        return false
  5863.    }
  5864.  
  5865.    function Start() {
  5866.        bot.hawkEye.autoAttack(target)
  5867.    }
  5868.  
  5869.    bot.on('entityHurt', (entity) => {
  5870.        if (entity.type === 'mob') {
  5871.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  5872.        } else if (entity.type === 'player') {
  5873.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  5874.        }
  5875.    })
  5876.  
  5877.    bot.on('entitySwingArm', (entity) => {
  5878.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  5879.    })
  5880.  
  5881.    bot.on('entityCrouch', (entity) => {
  5882.        bot.chat(`${entity.username}: you so sneaky.`)
  5883.    })
  5884.  
  5885.    bot.on('entityUncrouch', (entity) => {
  5886.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  5887.    })
  5888.  
  5889.    bot.on('entitySleep', (entity) => {
  5890.        bot.chat(`Good night, ${entity.username}`)
  5891.    })
  5892.  
  5893.    bot.on('entityWake', (entity) => {
  5894.        bot.chat(`Top of the morning, ${entity.username}`)
  5895.    })
  5896.  
  5897.    bot.on('entityEat', (entity) => {
  5898.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  5899.    })
  5900.  
  5901.    bot.on('entityAttach', (entity, vehicle) => {
  5902.        if (entity.type === 'player' && vehicle.type === 'object') {
  5903.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  5904.        }
  5905.    })
  5906.  
  5907.    bot.on('entityDetach', (entity, vehicle) => {
  5908.        if (entity.type === 'player' && vehicle.type === 'object') {
  5909.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  5910.        }
  5911.    })
  5912.  
  5913.    bot.on('entityEquipmentChange', (entity) => {
  5914.        console.log('entityEquipmentChange', entity)
  5915.    })
  5916.  
  5917.    bot.on('entityEffect', (entity, effect) => {
  5918.        console.log('entityEffect', entity, effect)
  5919.    })
  5920.  
  5921.    bot.on('entityEffectEnd', (entity, effect) => {
  5922.        console.log('entityEffectEnd', entity, effect)
  5923.    })
  5924.  
  5925.    function guardArea(pos) {
  5926.        guardPos = pos.clone()
  5927.        
  5928.        if (!bot.pvp.target) {
  5929.            moveToGuardPos()
  5930.        }
  5931.    }
  5932.    
  5933.    function stopGuarding() {
  5934.        guardPos = null
  5935.        bot.pvp.stop()
  5936.        bot.pathfinder.setGoal(null)
  5937.    }
  5938.    
  5939.    function moveToGuardPos() {
  5940.        const mcData = require('minecraft-data')(bot.version)
  5941.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  5942.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  5943.    }
  5944.    
  5945.    bot.on('stoppedAttacking', () => {
  5946.        if (guardPos) {
  5947.            moveToGuardPos()
  5948.        }
  5949.    })
  5950.    
  5951.    bot.on('physicTick', () => {
  5952.        if (bot.pvp.target) return
  5953.        if (bot.pathfinder.isMoving()) return
  5954.        
  5955.        const entity = bot.nearestEntity()
  5956.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  5957.    })
  5958.    
  5959.    bot.on('physicTick', () => {
  5960.        if (!guardPos) return
  5961.        
  5962.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  5963.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  5964.        
  5965.        const entity = bot.nearestEntity(filter)
  5966.        if (entity) {
  5967.            bot.pvp.attack(entity)
  5968.        }
  5969.    })
  5970.    /*
  5971.    bot.on('chat', (username, message) => {
  5972.        if (username === bot.username) return
  5973.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  5974.        if (result) {
  5975.            canSee(new Vec3(result[1], result[2], result[3]))
  5976.            return
  5977.        }
  5978.        switch (message) {
  5979.            case 'pos':
  5980.                console.log("pos command used")
  5981.                sayPosition(username)
  5982.                break
  5983.            case 'wearing':
  5984.                console.log("wearing command used")
  5985.                sayEquipment()
  5986.                break
  5987.            case 'nick':
  5988.                console.log("saynick command used")
  5989.                sayNick()
  5990.                break
  5991.            case 'spawn':
  5992.                console.log("spawn command used")
  5993.                saySpawnPoint()
  5994.                break
  5995.            case 'block':
  5996.                console.log("block command used")
  5997.                sayBlockUnder(username)
  5998.                break
  5999.            default:
  6000.                console.log("I am ready!")
  6001.                bot.chat("I am ready!")
  6002.    }
  6003.    */
  6004.  
  6005.    // text of bots username and help will give a list of bot commands
  6006.    bot.on('chat', (username, message) => { // work in progress....
  6007.        if (message === `${bot.player.displayName} help`)
  6008.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  6009.            bot.chat('pos, wearing, nick, spawn, block ')
  6010.            bot.chat('arch-start, Version.(wip not all commands work...)')
  6011.            bot.chat('Bot may just leave if it errors out.')
  6012.    })
  6013.  
  6014.    bot.on('chat', (username, message) => { // work in progress....
  6015.        if (message === 'Version') {
  6016.            console.log("Version command used just used")
  6017.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  6018.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  6019.            console.log("sayVersion command used")
  6020.            sayVersion(username)
  6021.            return
  6022.        }
  6023.    })
  6024.  
  6025.    bot.on('chat', (username, message) => {
  6026.        if (message === 'leave') {
  6027.                console.log("leave command used")
  6028.                bot.chat("Yes sir right away!")
  6029.                bot.quit(username)
  6030.                return
  6031.        }
  6032.    })
  6033.  
  6034.    bot.on('chat', (username, message) => {
  6035.        if (message === 'arch-start') {
  6036.            console.log("arch-start command used")
  6037.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  6038.            Start()
  6039.            return
  6040.        }
  6041.    })
  6042.  
  6043.    bot.on('chat', (username, message) => {
  6044.        if (message === 'guard') {          // if message guard do gaurd
  6045.            const player = bot.players[username]
  6046.  
  6047.            if (!player) {
  6048.                bot.chat("I can't see you.")
  6049.                return
  6050.            }
  6051.        bot.chat('I will guard that location.')
  6052.            guardArea(player.entity.position)
  6053.            }
  6054.  
  6055.            if (message === 'fight me') {
  6056.                const player = bot.players[username]
  6057.  
  6058.                if (!player) {
  6059.                    bot.chat("I can't see you.")
  6060.                    return
  6061.                }
  6062.  
  6063.            bot.chat('Prepare to fight!')
  6064.            bot.chat('5')
  6065.            bot.chat('4')
  6066.            bot.chat('3')
  6067.            bot.chat('2')
  6068.            bot.chat('1')
  6069.            bot.chat('GO!!!')
  6070.            bot.pvp.attack(player.entity)
  6071.            }
  6072.  
  6073.            if (message === 'stop') {
  6074.                bot.chat('I will stop!')
  6075.                bot.hawkEye.stop()
  6076.                stopGuarding()
  6077.            }
  6078.    })
  6079.  
  6080.    function not_busy() {
  6081.        guardPos = pos.clone()
  6082.  
  6083.        if (guardPos == null) {
  6084.            return false
  6085.        
  6086.        } else { (guardPos == !null)
  6087.                return true
  6088.            }
  6089.        }
  6090.    
  6091.    
  6092.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  6093.        if (busy == true) {
  6094.        console.log("I am busy!")
  6095.        bot.chat("I am busy!")
  6096.            } else { if (busy == false)
  6097.            console.log('I am ready!')
  6098.            bot.chat('I am ready!')
  6099.            }
  6100.    
  6101.    })
  6102.  
  6103.    bot.on('sleep', () => {
  6104.        bot.chat('Good night!')
  6105.    })
  6106.  
  6107.    bot.on('wake', () => {
  6108.        bot.chat('Good morning!')
  6109.    })
  6110.  
  6111.    function goToSleep() {
  6112.        const bed = bot.findBlock({
  6113.            matching: block => bot.isABed(block)
  6114.        })
  6115.        if (bed) {
  6116.            bot.sleep(bed, (err) => {
  6117.                if (err) {
  6118.                    bot.chat(`I can't sleep: ${err.message}`)
  6119.                } else {
  6120.                    bot.chat("I'm sleeping")
  6121.                }
  6122.            })
  6123.        } else {
  6124.            bot.chat('No nearby bed')
  6125.        }
  6126.    }
  6127.  
  6128.    function wakeUp() {
  6129.        bot.wake((err) => {
  6130.            if (err) {
  6131.                bot.chat(`I can't wake up: ${err.message}`)
  6132.             } else {
  6133.                 bot.chat('I woke up')
  6134.             }
  6135.         }
  6136.        
  6137.     )
  6138. }
  6139. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  6140. const Vec3 = require('vec3').Vec3
  6141. const fs = require('fs')
  6142. const { version } = require('os')
  6143. const pvp = require('mineflayer-pvp').plugin
  6144. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  6145. const armorManager = require('mineflayer-armor-manager')
  6146. const autoeat = require('mineflayer-auto-eat')
  6147. const minecraftHawkEye = require('minecrafthawkeye')
  6148.  
  6149. function jsonReader(filePath, cb) {
  6150.     fs.readFile(filePath, (err, fileData) => {
  6151.         if (err) {
  6152.             return cb && cb(err)
  6153.         }
  6154.         try {
  6155.             const object = JSON.parse(fileData)
  6156.             return cb && cb(null, object)
  6157.         } catch (err) {
  6158.             return cb && cb(err)
  6159.         }
  6160.     })
  6161. }
  6162.  
  6163. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  6164.     if (err) {
  6165.         console.log(err)
  6166.         return
  6167.     }
  6168.  
  6169.     const bot = mineflayer.createBot({
  6170.         version: mc_login_info.version,
  6171.         host: mc_login_info.host,
  6172.         port: mc_login_info.port,
  6173.         username: mc_login_info.username,
  6174.         password: mc_login_info.password,
  6175.         // give time for communication to hosts&client with longer ping times
  6176.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  6177.         logErrors: true
  6178.     })
  6179. })
  6180.  
  6181.     bot._client.on('custom_payload', (packet) => {
  6182.         // console.log(packet)
  6183.         if (packet.channel === "minecraft:brand") {
  6184.             let data = packet.data
  6185.             let brand = String.fromCharCode.apply(null, data)
  6186.             console.log(brand)
  6187.         }
  6188.     })
  6189.  
  6190.     bot.once('login', () => {
  6191.         console.log('logged in')
  6192.         console.log(`curent client version ${bot.version}`)
  6193.         // console.log(`curent server version is ${server.version}`)
  6194.     })
  6195.  
  6196.     bot.loadPlugin(autoeat)
  6197.     bot.loadPlugin(armorManager)
  6198.     bot.loadPlugin(minecraftHawkEye)
  6199.     bot.loadPlugin(pathfinder)
  6200.     bot.loadPlugin(pvp)
  6201.  
  6202.    
  6203.     bot.on('playerCollect', (collector, itemDrop) => {
  6204.         if (collector !== bot.entity) return
  6205.        
  6206.         setTimeout(() => {
  6207.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  6208.             if (sword) bot.equip(sword, 'hand')
  6209.         }, 150)
  6210.     })
  6211.    
  6212.     bot.on('playerCollect', (collector, itemDrop) => {
  6213.         if (collector !== bot.entity) return
  6214.        
  6215.         setTimeout(() => {
  6216.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  6217.             if (shield) bot.equip(shield, 'off-hand')
  6218.         }, 250)
  6219.     })
  6220.    
  6221.     let guardPos = null
  6222.     let busy = false
  6223.  
  6224.     bot.on('spawn', () => { // gives error when bot spawns
  6225.         console.log('spawned in server')
  6226.         bot.hawkEye.stop()
  6227.         stopGuarding()
  6228.         bot.chat('I spawned, watch out!')
  6229.     })
  6230.    
  6231.     function canSee(pos) {
  6232.         const block = bot.blockAt(pos)
  6233.         const r = bot.canSeeBlock(block)
  6234.         if (r) {
  6235.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  6236.         } else {
  6237.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  6238.         }
  6239.     }
  6240.    
  6241.     function sayPosition(username) {
  6242.         //bot.chat(`My puplic position is disabled`)
  6243.         bot.chat(`I am at ${bot.entity.position}`)
  6244.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  6245.         //bot.chat(`I don't know your position.`)
  6246.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  6247.    }
  6248.  
  6249.    function sayEquipment() {
  6250.        const eq = bot.players[username].entity.equipment
  6251.        const eqText = []
  6252.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  6253.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  6254.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  6255.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  6256.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  6257.        if (eqText.length) {
  6258.            bot.chat(`You are ${eqText.join(', ')}.`)
  6259.        } else {
  6260.            bot.chat('You are without armor!')
  6261.        }
  6262.    }
  6263.  
  6264.    function sayVersion() { // work in prograss not working yet
  6265.        bot.chat('/version')
  6266.        console.log(`${command.message} confermed ${brand}`)
  6267.    }
  6268.  
  6269.    function saySpawnPoint() {
  6270.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  6271.    }
  6272.  
  6273.    function sayBlockUnder() {
  6274.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  6275.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  6276.        console.log(block)
  6277.    }
  6278.  
  6279.    function quit(username) {
  6280.        console.log('quit command used')
  6281.        bot.quit(`${username} told me too`)
  6282.    }
  6283.  
  6284.    function sayNick() {
  6285.        bot.chat(`My name is ${bot.player.displayName}`)
  6286.    }
  6287.    
  6288.    // begin of autoeats paste
  6289.    bot.once('spawn', () => {
  6290.        bot.autoEat.options = {
  6291.            priority: 'foodPoints',
  6292.            startAt: 14,
  6293.            bannedFood: []
  6294.        }
  6295.    })
  6296.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  6297.    bot.on('autoeat_started', () => {
  6298.        console.log('Auto Eat started!')
  6299.    })
  6300.  
  6301.    bot.on('autoeat_stopped', () => {
  6302.        console.log('Auto Eat stopped!')
  6303.    })
  6304.  
  6305.    bot.on('health', () => {
  6306.        if (bot.food === 20) bot.autoEat.disable()
  6307.        // Disable the plugin if the bot is at 20 food points
  6308.        else bot.autoEat.enable() // Else enable the plugin again
  6309.    })
  6310.    // end of paste autoeat
  6311.  
  6312.    bot.on('whisper', (username, message, rawMessage) => {
  6313.        console.log(`I received a message from ${username}: ${message}`)
  6314.        bot.whisper(username, 'I can tell secrets too.')
  6315.    })
  6316.  
  6317.    bot.on('nonSpokenChat', (message) => {
  6318.        console.log(`Non spoken chat: ${message}`)
  6319.    })
  6320.    
  6321.    bot.on('login', () => {
  6322.        bot.chat('Hi everyone!')
  6323.    })
  6324.    
  6325.    bot.on('spawnReset', (message) => {
  6326.        console.log('spawnReset command used')
  6327.        stopGuarding()
  6328.        bot.hawkEye.stop()
  6329.        bot.chat('Oh noez! My bed is broken.')
  6330.    })
  6331.    
  6332.    bot.on('forcedMove', () => {
  6333.        console.log(`I have been forced to move to ${bot.entity.position}`)
  6334.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  6335.    })
  6336.    
  6337.    bot.on('health', () => {
  6338.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  6339.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  6340.    })
  6341.  
  6342.    bot.on('death', () => {
  6343.        console.log('I died, stopping and respawning')
  6344.        stopGuarding()
  6345.        bot.hawkEye.stop()
  6346.        bot.respawn
  6347.        bot.chat('I died x.x ugh!!')
  6348.        // need instructions to return to
  6349.        // what i was doing.
  6350.    })
  6351.  
  6352.    bot.on('kicked', (reason) => {
  6353.        console.log(`I got kicked for ${reason}`)
  6354.    })
  6355.    
  6356.    bot.on('rain', () => {
  6357.        if (bot.isRaining) {
  6358.            console.log('It started raining.')
  6359.            //bot.chat('It started raining.')
  6360.        } else {
  6361.            console.log('It stopped raining.')
  6362.            //bot.chat('It stopped raining.')
  6363.        }
  6364.    })
  6365.  
  6366.    bot.on('noteHeard', (block, instrument, pitch) => {
  6367.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  6368.    })
  6369.  
  6370.    bot.on('chestLidMove', (block, isOpen) => {
  6371.        const action = isOpen ? 'open' : 'close'
  6372.        bot.chat(`Hey, did someone just ${action} a chest?`)
  6373.    })
  6374.  
  6375.    bot.on('pistonMove', (block, isPulling, direction) => {
  6376.        const action = isPulling ? 'pulling' : 'pushing'
  6377.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  6378.    })
  6379.  
  6380.    bot.on('playerJoined', (player) => {
  6381.        if (player.username !== bot.username) {
  6382.            console.log(`${player.username}! Joined the server.`)
  6383.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  6384.        }
  6385.    })
  6386.  
  6387.    bot.on('playerLeft', (player) => {
  6388.        if (player.username === bot.username) return
  6389.        console.log(`${player.username} left the server`)
  6390.        // bot.chat(`Bye ${player.username}`)
  6391.    })
  6392.    /*
  6393.    bot.on('playerCollect', (collector, collected) => {
  6394.        if (collector.type === 'player' && collected.type === 'object') {
  6395.            const rawItem = collected.metadata[10]
  6396.            const item = mineflayer.Item.fromNotch(rawItem)
  6397.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  6398.        }
  6399.    })
  6400.    */
  6401.    /*    
  6402.    bot.on('entitySpawn', (entity) => {
  6403.        if (entity.type === 'mob') {
  6404.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  6405.        } else if (entity.type === 'player') {
  6406.            console.log(`Look who decided to show up: ${entity.username}`)
  6407.        } else if (entity.type === 'object') {
  6408.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  6409.        } else if (entity.type === 'global') {
  6410.            console.log('Ooh lightning!')
  6411.        } else if (entity.type === 'orb') {
  6412.            console.log('Gimme dat exp orb!')
  6413.        }
  6414.    })
  6415.    */    
  6416.  
  6417.    const target = bot.hawkEye.getPlayer()
  6418.    console.log(target)
  6419.    if (!target) {
  6420.        return false
  6421.    }
  6422.  
  6423.    function Start() {
  6424.        bot.hawkEye.autoAttack(target)
  6425.    }
  6426.  
  6427.    bot.on('entityHurt', (entity) => {
  6428.        if (entity.type === 'mob') {
  6429.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  6430.        } else if (entity.type === 'player') {
  6431.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  6432.        }
  6433.    })
  6434.  
  6435.    bot.on('entitySwingArm', (entity) => {
  6436.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  6437.    })
  6438.  
  6439.    bot.on('entityCrouch', (entity) => {
  6440.        bot.chat(`${entity.username}: you so sneaky.`)
  6441.    })
  6442.  
  6443.    bot.on('entityUncrouch', (entity) => {
  6444.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  6445.    })
  6446.  
  6447.    bot.on('entitySleep', (entity) => {
  6448.        bot.chat(`Good night, ${entity.username}`)
  6449.    })
  6450.  
  6451.    bot.on('entityWake', (entity) => {
  6452.        bot.chat(`Top of the morning, ${entity.username}`)
  6453.    })
  6454.  
  6455.    bot.on('entityEat', (entity) => {
  6456.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  6457.    })
  6458.  
  6459.    bot.on('entityAttach', (entity, vehicle) => {
  6460.        if (entity.type === 'player' && vehicle.type === 'object') {
  6461.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  6462.        }
  6463.    })
  6464.  
  6465.    bot.on('entityDetach', (entity, vehicle) => {
  6466.        if (entity.type === 'player' && vehicle.type === 'object') {
  6467.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  6468.        }
  6469.    })
  6470.  
  6471.    bot.on('entityEquipmentChange', (entity) => {
  6472.        console.log('entityEquipmentChange', entity)
  6473.    })
  6474.  
  6475.    bot.on('entityEffect', (entity, effect) => {
  6476.        console.log('entityEffect', entity, effect)
  6477.    })
  6478.  
  6479.    bot.on('entityEffectEnd', (entity, effect) => {
  6480.        console.log('entityEffectEnd', entity, effect)
  6481.    })
  6482.  
  6483.    function guardArea(pos) {
  6484.        guardPos = pos.clone()
  6485.        
  6486.        if (!bot.pvp.target) {
  6487.            moveToGuardPos()
  6488.        }
  6489.    }
  6490.    
  6491.    function stopGuarding() {
  6492.        guardPos = null
  6493.        bot.pvp.stop()
  6494.        bot.pathfinder.setGoal(null)
  6495.    }
  6496.    
  6497.    function moveToGuardPos() {
  6498.        const mcData = require('minecraft-data')(bot.version)
  6499.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  6500.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  6501.    }
  6502.    
  6503.    bot.on('stoppedAttacking', () => {
  6504.        if (guardPos) {
  6505.            moveToGuardPos()
  6506.        }
  6507.    })
  6508.    
  6509.    bot.on('physicTick', () => {
  6510.        if (bot.pvp.target) return
  6511.        if (bot.pathfinder.isMoving()) return
  6512.        
  6513.        const entity = bot.nearestEntity()
  6514.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  6515.    })
  6516.    
  6517.    bot.on('physicTick', () => {
  6518.        if (!guardPos) return
  6519.        
  6520.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  6521.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  6522.        
  6523.        const entity = bot.nearestEntity(filter)
  6524.        if (entity) {
  6525.            bot.pvp.attack(entity)
  6526.        }
  6527.    })
  6528.    /*
  6529.    bot.on('chat', (username, message) => {
  6530.        if (username === bot.username) return
  6531.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  6532.        if (result) {
  6533.            canSee(new Vec3(result[1], result[2], result[3]))
  6534.            return
  6535.        }
  6536.        switch (message) {
  6537.            case 'pos':
  6538.                console.log("pos command used")
  6539.                sayPosition(username)
  6540.                break
  6541.            case 'wearing':
  6542.                console.log("wearing command used")
  6543.                sayEquipment()
  6544.                break
  6545.            case 'nick':
  6546.                console.log("saynick command used")
  6547.                sayNick()
  6548.                break
  6549.            case 'spawn':
  6550.                console.log("spawn command used")
  6551.                saySpawnPoint()
  6552.                break
  6553.            case 'block':
  6554.                console.log("block command used")
  6555.                sayBlockUnder(username)
  6556.                break
  6557.            default:
  6558.                console.log("I am ready!")
  6559.                bot.chat("I am ready!")
  6560.    }
  6561.    */
  6562.  
  6563.    // text of bots username and help will give a list of bot commands
  6564.    bot.on('chat', (username, message) => { // work in progress....
  6565.        if (message === `${bot.player.displayName} help`)
  6566.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  6567.            bot.chat('pos, wearing, nick, spawn, block ')
  6568.            bot.chat('arch-start, Version.(wip not all commands work...)')
  6569.            bot.chat('Bot may just leave if it errors out.')
  6570.    })
  6571.  
  6572.    bot.on('chat', (username, message) => { // work in progress....
  6573.        if (message === 'Version') {
  6574.            console.log("Version command used just used")
  6575.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  6576.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  6577.            console.log("sayVersion command used")
  6578.            sayVersion(username)
  6579.            return
  6580.        }
  6581.    })
  6582.  
  6583.    bot.on('chat', (username, message) => {
  6584.        if (message === 'leave') {
  6585.                console.log("leave command used")
  6586.                bot.chat("Yes sir right away!")
  6587.                bot.quit(username)
  6588.                return
  6589.        }
  6590.    })
  6591.  
  6592.    bot.on('chat', (username, message) => {
  6593.        if (message === 'arch-start') {
  6594.            console.log("arch-start command used")
  6595.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  6596.            Start()
  6597.            return
  6598.        }
  6599.    })
  6600.  
  6601.    bot.on('chat', (username, message) => {
  6602.        if (message === 'guard') {          // if message guard do gaurd
  6603.            const player = bot.players[username]
  6604.  
  6605.            if (!player) {
  6606.                bot.chat("I can't see you.")
  6607.                return
  6608.            }
  6609.        bot.chat('I will guard that location.')
  6610.            guardArea(player.entity.position)
  6611.            }
  6612.  
  6613.            if (message === 'fight me') {
  6614.                const player = bot.players[username]
  6615.  
  6616.                if (!player) {
  6617.                    bot.chat("I can't see you.")
  6618.                    return
  6619.                }
  6620.  
  6621.            bot.chat('Prepare to fight!')
  6622.            bot.chat('5')
  6623.            bot.chat('4')
  6624.            bot.chat('3')
  6625.            bot.chat('2')
  6626.            bot.chat('1')
  6627.            bot.chat('GO!!!')
  6628.            bot.pvp.attack(player.entity)
  6629.            }
  6630.  
  6631.            if (message === 'stop') {
  6632.                bot.chat('I will stop!')
  6633.                bot.hawkEye.stop()
  6634.                stopGuarding()
  6635.            }
  6636.    })
  6637.  
  6638.    function not_busy() {
  6639.        guardPos = pos.clone()
  6640.  
  6641.        if (guardPos == null) {
  6642.            return false
  6643.        
  6644.        } else { (guardPos == !null)
  6645.                return true
  6646.            }
  6647.        }
  6648.    
  6649.    
  6650.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  6651.        if (busy == true) {
  6652.        console.log("I am busy!")
  6653.        bot.chat("I am busy!")
  6654.            } else { if (busy == false)
  6655.            console.log('I am ready!')
  6656.            bot.chat('I am ready!')
  6657.            }
  6658.    
  6659.    })
  6660.  
  6661.    bot.on('sleep', () => {
  6662.        bot.chat('Good night!')
  6663.    })
  6664.  
  6665.    bot.on('wake', () => {
  6666.        bot.chat('Good morning!')
  6667.    })
  6668.  
  6669.    function goToSleep() {
  6670.        const bed = bot.findBlock({
  6671.            matching: block => bot.isABed(block)
  6672.        })
  6673.        if (bed) {
  6674.            bot.sleep(bed, (err) => {
  6675.                if (err) {
  6676.                    bot.chat(`I can't sleep: ${err.message}`)
  6677.                } else {
  6678.                    bot.chat("I'm sleeping")
  6679.                }
  6680.            })
  6681.        } else {
  6682.            bot.chat('No nearby bed')
  6683.        }
  6684.    }
  6685.  
  6686.    function wakeUp() {
  6687.        bot.wake((err) => {
  6688.            if (err) {
  6689.                bot.chat(`I can't wake up: ${err.message}`)
  6690.             } else {
  6691.                 bot.chat('I woke up')
  6692.             }
  6693.         }
  6694.        
  6695.     )
  6696. }
  6697. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  6698. const Vec3 = require('vec3').Vec3
  6699. const fs = require('fs')
  6700. const { version } = require('os')
  6701. const pvp = require('mineflayer-pvp').plugin
  6702. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  6703. const armorManager = require('mineflayer-armor-manager')
  6704. const autoeat = require('mineflayer-auto-eat')
  6705. const minecraftHawkEye = require('minecrafthawkeye')
  6706.  
  6707. function jsonReader(filePath, cb) {
  6708.     fs.readFile(filePath, (err, fileData) => {
  6709.         if (err) {
  6710.             return cb && cb(err)
  6711.         }
  6712.         try {
  6713.             const object = JSON.parse(fileData)
  6714.             return cb && cb(null, object)
  6715.         } catch (err) {
  6716.             return cb && cb(err)
  6717.         }
  6718.     })
  6719. }
  6720.  
  6721. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  6722.     if (err) {
  6723.         console.log(err)
  6724.         return
  6725.     }
  6726.  
  6727.     const bot = mineflayer.createBot({
  6728.         version: mc_login_info.version,
  6729.         host: mc_login_info.host,
  6730.         port: mc_login_info.port,
  6731.         username: mc_login_info.username,
  6732.         password: mc_login_info.password,
  6733.         // give time for communication to hosts&client with longer ping times
  6734.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  6735.         logErrors: true
  6736.     })
  6737. })
  6738.  
  6739.     bot._client.on('custom_payload', (packet) => {
  6740.         // console.log(packet)
  6741.         if (packet.channel === "minecraft:brand") {
  6742.             let data = packet.data
  6743.             let brand = String.fromCharCode.apply(null, data)
  6744.             console.log(brand)
  6745.         }
  6746.     })
  6747.  
  6748.     bot.once('login', () => {
  6749.         console.log('logged in')
  6750.         console.log(`curent client version ${bot.version}`)
  6751.         // console.log(`curent server version is ${server.version}`)
  6752.     })
  6753.  
  6754.     bot.loadPlugin(autoeat)
  6755.     bot.loadPlugin(armorManager)
  6756.     bot.loadPlugin(minecraftHawkEye)
  6757.     bot.loadPlugin(pathfinder)
  6758.     bot.loadPlugin(pvp)
  6759.  
  6760.    
  6761.     bot.on('playerCollect', (collector, itemDrop) => {
  6762.         if (collector !== bot.entity) return
  6763.        
  6764.         setTimeout(() => {
  6765.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  6766.             if (sword) bot.equip(sword, 'hand')
  6767.         }, 150)
  6768.     })
  6769.    
  6770.     bot.on('playerCollect', (collector, itemDrop) => {
  6771.         if (collector !== bot.entity) return
  6772.        
  6773.         setTimeout(() => {
  6774.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  6775.             if (shield) bot.equip(shield, 'off-hand')
  6776.         }, 250)
  6777.     })
  6778.    
  6779.     let guardPos = null
  6780.     let busy = false
  6781.  
  6782.     bot.on('spawn', () => { // gives error when bot spawns
  6783.         console.log('spawned in server')
  6784.         bot.hawkEye.stop()
  6785.         stopGuarding()
  6786.         bot.chat('I spawned, watch out!')
  6787.     })
  6788.    
  6789.     function canSee(pos) {
  6790.         const block = bot.blockAt(pos)
  6791.         const r = bot.canSeeBlock(block)
  6792.         if (r) {
  6793.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  6794.         } else {
  6795.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  6796.         }
  6797.     }
  6798.    
  6799.     function sayPosition(username) {
  6800.         //bot.chat(`My puplic position is disabled`)
  6801.         bot.chat(`I am at ${bot.entity.position}`)
  6802.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  6803.         //bot.chat(`I don't know your position.`)
  6804.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  6805.    }
  6806.  
  6807.    function sayEquipment() {
  6808.        const eq = bot.players[username].entity.equipment
  6809.        const eqText = []
  6810.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  6811.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  6812.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  6813.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  6814.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  6815.        if (eqText.length) {
  6816.            bot.chat(`You are ${eqText.join(', ')}.`)
  6817.        } else {
  6818.            bot.chat('You are without armor!')
  6819.        }
  6820.    }
  6821.  
  6822.    function sayVersion() { // work in prograss not working yet
  6823.        bot.chat('/version')
  6824.        console.log(`${command.message} confermed ${brand}`)
  6825.    }
  6826.  
  6827.    function saySpawnPoint() {
  6828.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  6829.    }
  6830.  
  6831.    function sayBlockUnder() {
  6832.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  6833.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  6834.        console.log(block)
  6835.    }
  6836.  
  6837.    function quit(username) {
  6838.        console.log('quit command used')
  6839.        bot.quit(`${username} told me too`)
  6840.    }
  6841.  
  6842.    function sayNick() {
  6843.        bot.chat(`My name is ${bot.player.displayName}`)
  6844.    }
  6845.    
  6846.    // begin of autoeats paste
  6847.    bot.once('spawn', () => {
  6848.        bot.autoEat.options = {
  6849.            priority: 'foodPoints',
  6850.            startAt: 14,
  6851.            bannedFood: []
  6852.        }
  6853.    })
  6854.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  6855.    bot.on('autoeat_started', () => {
  6856.        console.log('Auto Eat started!')
  6857.    })
  6858.  
  6859.    bot.on('autoeat_stopped', () => {
  6860.        console.log('Auto Eat stopped!')
  6861.    })
  6862.  
  6863.    bot.on('health', () => {
  6864.        if (bot.food === 20) bot.autoEat.disable()
  6865.        // Disable the plugin if the bot is at 20 food points
  6866.        else bot.autoEat.enable() // Else enable the plugin again
  6867.    })
  6868.    // end of paste autoeat
  6869.  
  6870.    bot.on('whisper', (username, message, rawMessage) => {
  6871.        console.log(`I received a message from ${username}: ${message}`)
  6872.        bot.whisper(username, 'I can tell secrets too.')
  6873.    })
  6874.  
  6875.    bot.on('nonSpokenChat', (message) => {
  6876.        console.log(`Non spoken chat: ${message}`)
  6877.    })
  6878.    
  6879.    bot.on('login', () => {
  6880.        bot.chat('Hi everyone!')
  6881.    })
  6882.    
  6883.    bot.on('spawnReset', (message) => {
  6884.        console.log('spawnReset command used')
  6885.        stopGuarding()
  6886.        bot.hawkEye.stop()
  6887.        bot.chat('Oh noez! My bed is broken.')
  6888.    })
  6889.    
  6890.    bot.on('forcedMove', () => {
  6891.        console.log(`I have been forced to move to ${bot.entity.position}`)
  6892.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  6893.    })
  6894.    
  6895.    bot.on('health', () => {
  6896.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  6897.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  6898.    })
  6899.  
  6900.    bot.on('death', () => {
  6901.        console.log('I died, stopping and respawning')
  6902.        stopGuarding()
  6903.        bot.hawkEye.stop()
  6904.        bot.respawn
  6905.        bot.chat('I died x.x ugh!!')
  6906.        // need instructions to return to
  6907.        // what i was doing.
  6908.    })
  6909.  
  6910.    bot.on('kicked', (reason) => {
  6911.        console.log(`I got kicked for ${reason}`)
  6912.    })
  6913.    
  6914.    bot.on('rain', () => {
  6915.        if (bot.isRaining) {
  6916.            console.log('It started raining.')
  6917.            //bot.chat('It started raining.')
  6918.        } else {
  6919.            console.log('It stopped raining.')
  6920.            //bot.chat('It stopped raining.')
  6921.        }
  6922.    })
  6923.  
  6924.    bot.on('noteHeard', (block, instrument, pitch) => {
  6925.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  6926.    })
  6927.  
  6928.    bot.on('chestLidMove', (block, isOpen) => {
  6929.        const action = isOpen ? 'open' : 'close'
  6930.        bot.chat(`Hey, did someone just ${action} a chest?`)
  6931.    })
  6932.  
  6933.    bot.on('pistonMove', (block, isPulling, direction) => {
  6934.        const action = isPulling ? 'pulling' : 'pushing'
  6935.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  6936.    })
  6937.  
  6938.    bot.on('playerJoined', (player) => {
  6939.        if (player.username !== bot.username) {
  6940.            console.log(`${player.username}! Joined the server.`)
  6941.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  6942.        }
  6943.    })
  6944.  
  6945.    bot.on('playerLeft', (player) => {
  6946.        if (player.username === bot.username) return
  6947.        console.log(`${player.username} left the server`)
  6948.        // bot.chat(`Bye ${player.username}`)
  6949.    })
  6950.    /*
  6951.    bot.on('playerCollect', (collector, collected) => {
  6952.        if (collector.type === 'player' && collected.type === 'object') {
  6953.            const rawItem = collected.metadata[10]
  6954.            const item = mineflayer.Item.fromNotch(rawItem)
  6955.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  6956.        }
  6957.    })
  6958.    */
  6959.    /*    
  6960.    bot.on('entitySpawn', (entity) => {
  6961.        if (entity.type === 'mob') {
  6962.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  6963.        } else if (entity.type === 'player') {
  6964.            console.log(`Look who decided to show up: ${entity.username}`)
  6965.        } else if (entity.type === 'object') {
  6966.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  6967.        } else if (entity.type === 'global') {
  6968.            console.log('Ooh lightning!')
  6969.        } else if (entity.type === 'orb') {
  6970.            console.log('Gimme dat exp orb!')
  6971.        }
  6972.    })
  6973.    */    
  6974.  
  6975.    const target = bot.hawkEye.getPlayer()
  6976.    console.log(target)
  6977.    if (!target) {
  6978.        return false
  6979.    }
  6980.  
  6981.    function Start() {
  6982.        bot.hawkEye.autoAttack(target)
  6983.    }
  6984.  
  6985.    bot.on('entityHurt', (entity) => {
  6986.        if (entity.type === 'mob') {
  6987.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  6988.        } else if (entity.type === 'player') {
  6989.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  6990.        }
  6991.    })
  6992.  
  6993.    bot.on('entitySwingArm', (entity) => {
  6994.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  6995.    })
  6996.  
  6997.    bot.on('entityCrouch', (entity) => {
  6998.        bot.chat(`${entity.username}: you so sneaky.`)
  6999.    })
  7000.  
  7001.    bot.on('entityUncrouch', (entity) => {
  7002.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  7003.    })
  7004.  
  7005.    bot.on('entitySleep', (entity) => {
  7006.        bot.chat(`Good night, ${entity.username}`)
  7007.    })
  7008.  
  7009.    bot.on('entityWake', (entity) => {
  7010.        bot.chat(`Top of the morning, ${entity.username}`)
  7011.    })
  7012.  
  7013.    bot.on('entityEat', (entity) => {
  7014.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  7015.    })
  7016.  
  7017.    bot.on('entityAttach', (entity, vehicle) => {
  7018.        if (entity.type === 'player' && vehicle.type === 'object') {
  7019.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  7020.        }
  7021.    })
  7022.  
  7023.    bot.on('entityDetach', (entity, vehicle) => {
  7024.        if (entity.type === 'player' && vehicle.type === 'object') {
  7025.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  7026.        }
  7027.    })
  7028.  
  7029.    bot.on('entityEquipmentChange', (entity) => {
  7030.        console.log('entityEquipmentChange', entity)
  7031.    })
  7032.  
  7033.    bot.on('entityEffect', (entity, effect) => {
  7034.        console.log('entityEffect', entity, effect)
  7035.    })
  7036.  
  7037.    bot.on('entityEffectEnd', (entity, effect) => {
  7038.        console.log('entityEffectEnd', entity, effect)
  7039.    })
  7040.  
  7041.    function guardArea(pos) {
  7042.        guardPos = pos.clone()
  7043.        
  7044.        if (!bot.pvp.target) {
  7045.            moveToGuardPos()
  7046.        }
  7047.    }
  7048.    
  7049.    function stopGuarding() {
  7050.        guardPos = null
  7051.        bot.pvp.stop()
  7052.        bot.pathfinder.setGoal(null)
  7053.    }
  7054.    
  7055.    function moveToGuardPos() {
  7056.        const mcData = require('minecraft-data')(bot.version)
  7057.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  7058.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  7059.    }
  7060.    
  7061.    bot.on('stoppedAttacking', () => {
  7062.        if (guardPos) {
  7063.            moveToGuardPos()
  7064.        }
  7065.    })
  7066.    
  7067.    bot.on('physicTick', () => {
  7068.        if (bot.pvp.target) return
  7069.        if (bot.pathfinder.isMoving()) return
  7070.        
  7071.        const entity = bot.nearestEntity()
  7072.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  7073.    })
  7074.    
  7075.    bot.on('physicTick', () => {
  7076.        if (!guardPos) return
  7077.        
  7078.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  7079.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  7080.        
  7081.        const entity = bot.nearestEntity(filter)
  7082.        if (entity) {
  7083.            bot.pvp.attack(entity)
  7084.        }
  7085.    })
  7086.    /*
  7087.    bot.on('chat', (username, message) => {
  7088.        if (username === bot.username) return
  7089.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  7090.        if (result) {
  7091.            canSee(new Vec3(result[1], result[2], result[3]))
  7092.            return
  7093.        }
  7094.        switch (message) {
  7095.            case 'pos':
  7096.                console.log("pos command used")
  7097.                sayPosition(username)
  7098.                break
  7099.            case 'wearing':
  7100.                console.log("wearing command used")
  7101.                sayEquipment()
  7102.                break
  7103.            case 'nick':
  7104.                console.log("saynick command used")
  7105.                sayNick()
  7106.                break
  7107.            case 'spawn':
  7108.                console.log("spawn command used")
  7109.                saySpawnPoint()
  7110.                break
  7111.            case 'block':
  7112.                console.log("block command used")
  7113.                sayBlockUnder(username)
  7114.                break
  7115.            default:
  7116.                console.log("I am ready!")
  7117.                bot.chat("I am ready!")
  7118.    }
  7119.    */
  7120.  
  7121.    // text of bots username and help will give a list of bot commands
  7122.    bot.on('chat', (username, message) => { // work in progress....
  7123.        if (message === `${bot.player.displayName} help`)
  7124.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  7125.            bot.chat('pos, wearing, nick, spawn, block ')
  7126.            bot.chat('arch-start, Version.(wip not all commands work...)')
  7127.            bot.chat('Bot may just leave if it errors out.')
  7128.    })
  7129.  
  7130.    bot.on('chat', (username, message) => { // work in progress....
  7131.        if (message === 'Version') {
  7132.            console.log("Version command used just used")
  7133.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  7134.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  7135.            console.log("sayVersion command used")
  7136.            sayVersion(username)
  7137.            return
  7138.        }
  7139.    })
  7140.  
  7141.    bot.on('chat', (username, message) => {
  7142.        if (message === 'leave') {
  7143.                console.log("leave command used")
  7144.                bot.chat("Yes sir right away!")
  7145.                bot.quit(username)
  7146.                return
  7147.        }
  7148.    })
  7149.  
  7150.    bot.on('chat', (username, message) => {
  7151.        if (message === 'arch-start') {
  7152.            console.log("arch-start command used")
  7153.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  7154.            Start()
  7155.            return
  7156.        }
  7157.    })
  7158.  
  7159.    bot.on('chat', (username, message) => {
  7160.        if (message === 'guard') {          // if message guard do gaurd
  7161.            const player = bot.players[username]
  7162.  
  7163.            if (!player) {
  7164.                bot.chat("I can't see you.")
  7165.                return
  7166.            }
  7167.        bot.chat('I will guard that location.')
  7168.            guardArea(player.entity.position)
  7169.            }
  7170.  
  7171.            if (message === 'fight me') {
  7172.                const player = bot.players[username]
  7173.  
  7174.                if (!player) {
  7175.                    bot.chat("I can't see you.")
  7176.                    return
  7177.                }
  7178.  
  7179.            bot.chat('Prepare to fight!')
  7180.            bot.chat('5')
  7181.            bot.chat('4')
  7182.            bot.chat('3')
  7183.            bot.chat('2')
  7184.            bot.chat('1')
  7185.            bot.chat('GO!!!')
  7186.            bot.pvp.attack(player.entity)
  7187.            }
  7188.  
  7189.            if (message === 'stop') {
  7190.                bot.chat('I will stop!')
  7191.                bot.hawkEye.stop()
  7192.                stopGuarding()
  7193.            }
  7194.    })
  7195.  
  7196.    function not_busy() {
  7197.        guardPos = pos.clone()
  7198.  
  7199.        if (guardPos == null) {
  7200.            return false
  7201.        
  7202.        } else { (guardPos == !null)
  7203.                return true
  7204.            }
  7205.        }
  7206.    
  7207.    
  7208.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  7209.        if (busy == true) {
  7210.        console.log("I am busy!")
  7211.        bot.chat("I am busy!")
  7212.            } else { if (busy == false)
  7213.            console.log('I am ready!')
  7214.            bot.chat('I am ready!')
  7215.            }
  7216.    
  7217.    })
  7218.  
  7219.    bot.on('sleep', () => {
  7220.        bot.chat('Good night!')
  7221.    })
  7222.  
  7223.    bot.on('wake', () => {
  7224.        bot.chat('Good morning!')
  7225.    })
  7226.  
  7227.    function goToSleep() {
  7228.        const bed = bot.findBlock({
  7229.            matching: block => bot.isABed(block)
  7230.        })
  7231.        if (bed) {
  7232.            bot.sleep(bed, (err) => {
  7233.                if (err) {
  7234.                    bot.chat(`I can't sleep: ${err.message}`)
  7235.                } else {
  7236.                    bot.chat("I'm sleeping")
  7237.                }
  7238.            })
  7239.        } else {
  7240.            bot.chat('No nearby bed')
  7241.        }
  7242.    }
  7243.  
  7244.    function wakeUp() {
  7245.        bot.wake((err) => {
  7246.            if (err) {
  7247.                bot.chat(`I can't wake up: ${err.message}`)
  7248.             } else {
  7249.                 bot.chat('I woke up')
  7250.             }
  7251.         }
  7252.        
  7253.     )
  7254. }
  7255. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  7256. const Vec3 = require('vec3').Vec3
  7257. const fs = require('fs')
  7258. const { version } = require('os')
  7259. const pvp = require('mineflayer-pvp').plugin
  7260. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  7261. const armorManager = require('mineflayer-armor-manager')
  7262. const autoeat = require('mineflayer-auto-eat')
  7263. const minecraftHawkEye = require('minecrafthawkeye')
  7264.  
  7265. function jsonReader(filePath, cb) {
  7266.     fs.readFile(filePath, (err, fileData) => {
  7267.         if (err) {
  7268.             return cb && cb(err)
  7269.         }
  7270.         try {
  7271.             const object = JSON.parse(fileData)
  7272.             return cb && cb(null, object)
  7273.         } catch (err) {
  7274.             return cb && cb(err)
  7275.         }
  7276.     })
  7277. }
  7278.  
  7279. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  7280.     if (err) {
  7281.         console.log(err)
  7282.         return
  7283.     }
  7284.  
  7285.     const bot = mineflayer.createBot({
  7286.         version: mc_login_info.version,
  7287.         host: mc_login_info.host,
  7288.         port: mc_login_info.port,
  7289.         username: mc_login_info.username,
  7290.         password: mc_login_info.password,
  7291.         // give time for communication to hosts&client with longer ping times
  7292.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  7293.         logErrors: true
  7294.     })
  7295. })
  7296.  
  7297.     bot._client.on('custom_payload', (packet) => {
  7298.         // console.log(packet)
  7299.         if (packet.channel === "minecraft:brand") {
  7300.             let data = packet.data
  7301.             let brand = String.fromCharCode.apply(null, data)
  7302.             console.log(brand)
  7303.         }
  7304.     })
  7305.  
  7306.     bot.once('login', () => {
  7307.         console.log('logged in')
  7308.         console.log(`curent client version ${bot.version}`)
  7309.         // console.log(`curent server version is ${server.version}`)
  7310.     })
  7311.  
  7312.     bot.loadPlugin(autoeat)
  7313.     bot.loadPlugin(armorManager)
  7314.     bot.loadPlugin(minecraftHawkEye)
  7315.     bot.loadPlugin(pathfinder)
  7316.     bot.loadPlugin(pvp)
  7317.  
  7318.    
  7319.     bot.on('playerCollect', (collector, itemDrop) => {
  7320.         if (collector !== bot.entity) return
  7321.        
  7322.         setTimeout(() => {
  7323.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  7324.             if (sword) bot.equip(sword, 'hand')
  7325.         }, 150)
  7326.     })
  7327.    
  7328.     bot.on('playerCollect', (collector, itemDrop) => {
  7329.         if (collector !== bot.entity) return
  7330.        
  7331.         setTimeout(() => {
  7332.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  7333.             if (shield) bot.equip(shield, 'off-hand')
  7334.         }, 250)
  7335.     })
  7336.    
  7337.     let guardPos = null
  7338.     let busy = false
  7339.  
  7340.     bot.on('spawn', () => { // gives error when bot spawns
  7341.         console.log('spawned in server')
  7342.         bot.hawkEye.stop()
  7343.         stopGuarding()
  7344.         bot.chat('I spawned, watch out!')
  7345.     })
  7346.    
  7347.     function canSee(pos) {
  7348.         const block = bot.blockAt(pos)
  7349.         const r = bot.canSeeBlock(block)
  7350.         if (r) {
  7351.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  7352.         } else {
  7353.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  7354.         }
  7355.     }
  7356.    
  7357.     function sayPosition(username) {
  7358.         //bot.chat(`My puplic position is disabled`)
  7359.         bot.chat(`I am at ${bot.entity.position}`)
  7360.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  7361.         //bot.chat(`I don't know your position.`)
  7362.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  7363.    }
  7364.  
  7365.    function sayEquipment() {
  7366.        const eq = bot.players[username].entity.equipment
  7367.        const eqText = []
  7368.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  7369.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  7370.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  7371.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  7372.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  7373.        if (eqText.length) {
  7374.            bot.chat(`You are ${eqText.join(', ')}.`)
  7375.        } else {
  7376.            bot.chat('You are without armor!')
  7377.        }
  7378.    }
  7379.  
  7380.    function sayVersion() { // work in prograss not working yet
  7381.        bot.chat('/version')
  7382.        console.log(`${command.message} confermed ${brand}`)
  7383.    }
  7384.  
  7385.    function saySpawnPoint() {
  7386.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  7387.    }
  7388.  
  7389.    function sayBlockUnder() {
  7390.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  7391.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  7392.        console.log(block)
  7393.    }
  7394.  
  7395.    function quit(username) {
  7396.        console.log('quit command used')
  7397.        bot.quit(`${username} told me too`)
  7398.    }
  7399.  
  7400.    function sayNick() {
  7401.        bot.chat(`My name is ${bot.player.displayName}`)
  7402.    }
  7403.    
  7404.    // begin of autoeats paste
  7405.    bot.once('spawn', () => {
  7406.        bot.autoEat.options = {
  7407.            priority: 'foodPoints',
  7408.            startAt: 14,
  7409.            bannedFood: []
  7410.        }
  7411.    })
  7412.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  7413.    bot.on('autoeat_started', () => {
  7414.        console.log('Auto Eat started!')
  7415.    })
  7416.  
  7417.    bot.on('autoeat_stopped', () => {
  7418.        console.log('Auto Eat stopped!')
  7419.    })
  7420.  
  7421.    bot.on('health', () => {
  7422.        if (bot.food === 20) bot.autoEat.disable()
  7423.        // Disable the plugin if the bot is at 20 food points
  7424.        else bot.autoEat.enable() // Else enable the plugin again
  7425.    })
  7426.    // end of paste autoeat
  7427.  
  7428.    bot.on('whisper', (username, message, rawMessage) => {
  7429.        console.log(`I received a message from ${username}: ${message}`)
  7430.        bot.whisper(username, 'I can tell secrets too.')
  7431.    })
  7432.  
  7433.    bot.on('nonSpokenChat', (message) => {
  7434.        console.log(`Non spoken chat: ${message}`)
  7435.    })
  7436.    
  7437.    bot.on('login', () => {
  7438.        bot.chat('Hi everyone!')
  7439.    })
  7440.    
  7441.    bot.on('spawnReset', (message) => {
  7442.        console.log('spawnReset command used')
  7443.        stopGuarding()
  7444.        bot.hawkEye.stop()
  7445.        bot.chat('Oh noez! My bed is broken.')
  7446.    })
  7447.    
  7448.    bot.on('forcedMove', () => {
  7449.        console.log(`I have been forced to move to ${bot.entity.position}`)
  7450.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  7451.    })
  7452.    
  7453.    bot.on('health', () => {
  7454.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  7455.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  7456.    })
  7457.  
  7458.    bot.on('death', () => {
  7459.        console.log('I died, stopping and respawning')
  7460.        stopGuarding()
  7461.        bot.hawkEye.stop()
  7462.        bot.respawn
  7463.        bot.chat('I died x.x ugh!!')
  7464.        // need instructions to return to
  7465.        // what i was doing.
  7466.    })
  7467.  
  7468.    bot.on('kicked', (reason) => {
  7469.        console.log(`I got kicked for ${reason}`)
  7470.    })
  7471.    
  7472.    bot.on('rain', () => {
  7473.        if (bot.isRaining) {
  7474.            console.log('It started raining.')
  7475.            //bot.chat('It started raining.')
  7476.        } else {
  7477.            console.log('It stopped raining.')
  7478.            //bot.chat('It stopped raining.')
  7479.        }
  7480.    })
  7481.  
  7482.    bot.on('noteHeard', (block, instrument, pitch) => {
  7483.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  7484.    })
  7485.  
  7486.    bot.on('chestLidMove', (block, isOpen) => {
  7487.        const action = isOpen ? 'open' : 'close'
  7488.        bot.chat(`Hey, did someone just ${action} a chest?`)
  7489.    })
  7490.  
  7491.    bot.on('pistonMove', (block, isPulling, direction) => {
  7492.        const action = isPulling ? 'pulling' : 'pushing'
  7493.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  7494.    })
  7495.  
  7496.    bot.on('playerJoined', (player) => {
  7497.        if (player.username !== bot.username) {
  7498.            console.log(`${player.username}! Joined the server.`)
  7499.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  7500.        }
  7501.    })
  7502.  
  7503.    bot.on('playerLeft', (player) => {
  7504.        if (player.username === bot.username) return
  7505.        console.log(`${player.username} left the server`)
  7506.        // bot.chat(`Bye ${player.username}`)
  7507.    })
  7508.    /*
  7509.    bot.on('playerCollect', (collector, collected) => {
  7510.        if (collector.type === 'player' && collected.type === 'object') {
  7511.            const rawItem = collected.metadata[10]
  7512.            const item = mineflayer.Item.fromNotch(rawItem)
  7513.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  7514.        }
  7515.    })
  7516.    */
  7517.    /*    
  7518.    bot.on('entitySpawn', (entity) => {
  7519.        if (entity.type === 'mob') {
  7520.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  7521.        } else if (entity.type === 'player') {
  7522.            console.log(`Look who decided to show up: ${entity.username}`)
  7523.        } else if (entity.type === 'object') {
  7524.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  7525.        } else if (entity.type === 'global') {
  7526.            console.log('Ooh lightning!')
  7527.        } else if (entity.type === 'orb') {
  7528.            console.log('Gimme dat exp orb!')
  7529.        }
  7530.    })
  7531.    */    
  7532.  
  7533.    const target = bot.hawkEye.getPlayer()
  7534.    console.log(target)
  7535.    if (!target) {
  7536.        return false
  7537.    }
  7538.  
  7539.    function Start() {
  7540.        bot.hawkEye.autoAttack(target)
  7541.    }
  7542.  
  7543.    bot.on('entityHurt', (entity) => {
  7544.        if (entity.type === 'mob') {
  7545.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  7546.        } else if (entity.type === 'player') {
  7547.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  7548.        }
  7549.    })
  7550.  
  7551.    bot.on('entitySwingArm', (entity) => {
  7552.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  7553.    })
  7554.  
  7555.    bot.on('entityCrouch', (entity) => {
  7556.        bot.chat(`${entity.username}: you so sneaky.`)
  7557.    })
  7558.  
  7559.    bot.on('entityUncrouch', (entity) => {
  7560.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  7561.    })
  7562.  
  7563.    bot.on('entitySleep', (entity) => {
  7564.        bot.chat(`Good night, ${entity.username}`)
  7565.    })
  7566.  
  7567.    bot.on('entityWake', (entity) => {
  7568.        bot.chat(`Top of the morning, ${entity.username}`)
  7569.    })
  7570.  
  7571.    bot.on('entityEat', (entity) => {
  7572.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  7573.    })
  7574.  
  7575.    bot.on('entityAttach', (entity, vehicle) => {
  7576.        if (entity.type === 'player' && vehicle.type === 'object') {
  7577.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  7578.        }
  7579.    })
  7580.  
  7581.    bot.on('entityDetach', (entity, vehicle) => {
  7582.        if (entity.type === 'player' && vehicle.type === 'object') {
  7583.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  7584.        }
  7585.    })
  7586.  
  7587.    bot.on('entityEquipmentChange', (entity) => {
  7588.        console.log('entityEquipmentChange', entity)
  7589.    })
  7590.  
  7591.    bot.on('entityEffect', (entity, effect) => {
  7592.        console.log('entityEffect', entity, effect)
  7593.    })
  7594.  
  7595.    bot.on('entityEffectEnd', (entity, effect) => {
  7596.        console.log('entityEffectEnd', entity, effect)
  7597.    })
  7598.  
  7599.    function guardArea(pos) {
  7600.        guardPos = pos.clone()
  7601.        
  7602.        if (!bot.pvp.target) {
  7603.            moveToGuardPos()
  7604.        }
  7605.    }
  7606.    
  7607.    function stopGuarding() {
  7608.        guardPos = null
  7609.        bot.pvp.stop()
  7610.        bot.pathfinder.setGoal(null)
  7611.    }
  7612.    
  7613.    function moveToGuardPos() {
  7614.        const mcData = require('minecraft-data')(bot.version)
  7615.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  7616.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  7617.    }
  7618.    
  7619.    bot.on('stoppedAttacking', () => {
  7620.        if (guardPos) {
  7621.            moveToGuardPos()
  7622.        }
  7623.    })
  7624.    
  7625.    bot.on('physicTick', () => {
  7626.        if (bot.pvp.target) return
  7627.        if (bot.pathfinder.isMoving()) return
  7628.        
  7629.        const entity = bot.nearestEntity()
  7630.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  7631.    })
  7632.    
  7633.    bot.on('physicTick', () => {
  7634.        if (!guardPos) return
  7635.        
  7636.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  7637.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  7638.        
  7639.        const entity = bot.nearestEntity(filter)
  7640.        if (entity) {
  7641.            bot.pvp.attack(entity)
  7642.        }
  7643.    })
  7644.    /*
  7645.    bot.on('chat', (username, message) => {
  7646.        if (username === bot.username) return
  7647.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  7648.        if (result) {
  7649.            canSee(new Vec3(result[1], result[2], result[3]))
  7650.            return
  7651.        }
  7652.        switch (message) {
  7653.            case 'pos':
  7654.                console.log("pos command used")
  7655.                sayPosition(username)
  7656.                break
  7657.            case 'wearing':
  7658.                console.log("wearing command used")
  7659.                sayEquipment()
  7660.                break
  7661.            case 'nick':
  7662.                console.log("saynick command used")
  7663.                sayNick()
  7664.                break
  7665.            case 'spawn':
  7666.                console.log("spawn command used")
  7667.                saySpawnPoint()
  7668.                break
  7669.            case 'block':
  7670.                console.log("block command used")
  7671.                sayBlockUnder(username)
  7672.                break
  7673.            default:
  7674.                console.log("I am ready!")
  7675.                bot.chat("I am ready!")
  7676.    }
  7677.    */
  7678.  
  7679.    // text of bots username and help will give a list of bot commands
  7680.    bot.on('chat', (username, message) => { // work in progress....
  7681.        if (message === `${bot.player.displayName} help`)
  7682.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  7683.            bot.chat('pos, wearing, nick, spawn, block ')
  7684.            bot.chat('arch-start, Version.(wip not all commands work...)')
  7685.            bot.chat('Bot may just leave if it errors out.')
  7686.    })
  7687.  
  7688.    bot.on('chat', (username, message) => { // work in progress....
  7689.        if (message === 'Version') {
  7690.            console.log("Version command used just used")
  7691.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  7692.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  7693.            console.log("sayVersion command used")
  7694.            sayVersion(username)
  7695.            return
  7696.        }
  7697.    })
  7698.  
  7699.    bot.on('chat', (username, message) => {
  7700.        if (message === 'leave') {
  7701.                console.log("leave command used")
  7702.                bot.chat("Yes sir right away!")
  7703.                bot.quit(username)
  7704.                return
  7705.        }
  7706.    })
  7707.  
  7708.    bot.on('chat', (username, message) => {
  7709.        if (message === 'arch-start') {
  7710.            console.log("arch-start command used")
  7711.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  7712.            Start()
  7713.            return
  7714.        }
  7715.    })
  7716.  
  7717.    bot.on('chat', (username, message) => {
  7718.        if (message === 'guard') {          // if message guard do gaurd
  7719.            const player = bot.players[username]
  7720.  
  7721.            if (!player) {
  7722.                bot.chat("I can't see you.")
  7723.                return
  7724.            }
  7725.        bot.chat('I will guard that location.')
  7726.            guardArea(player.entity.position)
  7727.            }
  7728.  
  7729.            if (message === 'fight me') {
  7730.                const player = bot.players[username]
  7731.  
  7732.                if (!player) {
  7733.                    bot.chat("I can't see you.")
  7734.                    return
  7735.                }
  7736.  
  7737.            bot.chat('Prepare to fight!')
  7738.            bot.chat('5')
  7739.            bot.chat('4')
  7740.            bot.chat('3')
  7741.            bot.chat('2')
  7742.            bot.chat('1')
  7743.            bot.chat('GO!!!')
  7744.            bot.pvp.attack(player.entity)
  7745.            }
  7746.  
  7747.            if (message === 'stop') {
  7748.                bot.chat('I will stop!')
  7749.                bot.hawkEye.stop()
  7750.                stopGuarding()
  7751.            }
  7752.    })
  7753.  
  7754.    function not_busy() {
  7755.        guardPos = pos.clone()
  7756.  
  7757.        if (guardPos == null) {
  7758.            return false
  7759.        
  7760.        } else { (guardPos == !null)
  7761.                return true
  7762.            }
  7763.        }
  7764.    
  7765.    
  7766.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  7767.        if (busy == true) {
  7768.        console.log("I am busy!")
  7769.        bot.chat("I am busy!")
  7770.            } else { if (busy == false)
  7771.            console.log('I am ready!')
  7772.            bot.chat('I am ready!')
  7773.            }
  7774.    
  7775.    })
  7776.  
  7777.    bot.on('sleep', () => {
  7778.        bot.chat('Good night!')
  7779.    })
  7780.  
  7781.    bot.on('wake', () => {
  7782.        bot.chat('Good morning!')
  7783.    })
  7784.  
  7785.    function goToSleep() {
  7786.        const bed = bot.findBlock({
  7787.            matching: block => bot.isABed(block)
  7788.        })
  7789.        if (bed) {
  7790.            bot.sleep(bed, (err) => {
  7791.                if (err) {
  7792.                    bot.chat(`I can't sleep: ${err.message}`)
  7793.                } else {
  7794.                    bot.chat("I'm sleeping")
  7795.                }
  7796.            })
  7797.        } else {
  7798.            bot.chat('No nearby bed')
  7799.        }
  7800.    }
  7801.  
  7802.    function wakeUp() {
  7803.        bot.wake((err) => {
  7804.            if (err) {
  7805.                bot.chat(`I can't wake up: ${err.message}`)
  7806.             } else {
  7807.                 bot.chat('I woke up')
  7808.             }
  7809.         }
  7810.        
  7811.     )
  7812. }
  7813. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  7814. const Vec3 = require('vec3').Vec3
  7815. const fs = require('fs')
  7816. const { version } = require('os')
  7817. const pvp = require('mineflayer-pvp').plugin
  7818. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  7819. const armorManager = require('mineflayer-armor-manager')
  7820. const autoeat = require('mineflayer-auto-eat')
  7821. const minecraftHawkEye = require('minecrafthawkeye')
  7822.  
  7823. function jsonReader(filePath, cb) {
  7824.     fs.readFile(filePath, (err, fileData) => {
  7825.         if (err) {
  7826.             return cb && cb(err)
  7827.         }
  7828.         try {
  7829.             const object = JSON.parse(fileData)
  7830.             return cb && cb(null, object)
  7831.         } catch (err) {
  7832.             return cb && cb(err)
  7833.         }
  7834.     })
  7835. }
  7836.  
  7837. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  7838.     if (err) {
  7839.         console.log(err)
  7840.         return
  7841.     }
  7842.  
  7843.     const bot = mineflayer.createBot({
  7844.         version: mc_login_info.version,
  7845.         host: mc_login_info.host,
  7846.         port: mc_login_info.port,
  7847.         username: mc_login_info.username,
  7848.         password: mc_login_info.password,
  7849.         // give time for communication to hosts&client with longer ping times
  7850.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  7851.         logErrors: true
  7852.     })
  7853. })
  7854.  
  7855.     bot._client.on('custom_payload', (packet) => {
  7856.         // console.log(packet)
  7857.         if (packet.channel === "minecraft:brand") {
  7858.             let data = packet.data
  7859.             let brand = String.fromCharCode.apply(null, data)
  7860.             console.log(brand)
  7861.         }
  7862.     })
  7863.  
  7864.     bot.once('login', () => {
  7865.         console.log('logged in')
  7866.         console.log(`curent client version ${bot.version}`)
  7867.         // console.log(`curent server version is ${server.version}`)
  7868.     })
  7869.  
  7870.     bot.loadPlugin(autoeat)
  7871.     bot.loadPlugin(armorManager)
  7872.     bot.loadPlugin(minecraftHawkEye)
  7873.     bot.loadPlugin(pathfinder)
  7874.     bot.loadPlugin(pvp)
  7875.  
  7876.    
  7877.     bot.on('playerCollect', (collector, itemDrop) => {
  7878.         if (collector !== bot.entity) return
  7879.        
  7880.         setTimeout(() => {
  7881.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  7882.             if (sword) bot.equip(sword, 'hand')
  7883.         }, 150)
  7884.     })
  7885.    
  7886.     bot.on('playerCollect', (collector, itemDrop) => {
  7887.         if (collector !== bot.entity) return
  7888.        
  7889.         setTimeout(() => {
  7890.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  7891.             if (shield) bot.equip(shield, 'off-hand')
  7892.         }, 250)
  7893.     })
  7894.    
  7895.     let guardPos = null
  7896.     let busy = false
  7897.  
  7898.     bot.on('spawn', () => { // gives error when bot spawns
  7899.         console.log('spawned in server')
  7900.         bot.hawkEye.stop()
  7901.         stopGuarding()
  7902.         bot.chat('I spawned, watch out!')
  7903.     })
  7904.    
  7905.     function canSee(pos) {
  7906.         const block = bot.blockAt(pos)
  7907.         const r = bot.canSeeBlock(block)
  7908.         if (r) {
  7909.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  7910.         } else {
  7911.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  7912.         }
  7913.     }
  7914.    
  7915.     function sayPosition(username) {
  7916.         //bot.chat(`My puplic position is disabled`)
  7917.         bot.chat(`I am at ${bot.entity.position}`)
  7918.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  7919.         //bot.chat(`I don't know your position.`)
  7920.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  7921.    }
  7922.  
  7923.    function sayEquipment() {
  7924.        const eq = bot.players[username].entity.equipment
  7925.        const eqText = []
  7926.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  7927.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  7928.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  7929.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  7930.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  7931.        if (eqText.length) {
  7932.            bot.chat(`You are ${eqText.join(', ')}.`)
  7933.        } else {
  7934.            bot.chat('You are without armor!')
  7935.        }
  7936.    }
  7937.  
  7938.    function sayVersion() { // work in prograss not working yet
  7939.        bot.chat('/version')
  7940.        console.log(`${command.message} confermed ${brand}`)
  7941.    }
  7942.  
  7943.    function saySpawnPoint() {
  7944.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  7945.    }
  7946.  
  7947.    function sayBlockUnder() {
  7948.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  7949.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  7950.        console.log(block)
  7951.    }
  7952.  
  7953.    function quit(username) {
  7954.        console.log('quit command used')
  7955.        bot.quit(`${username} told me too`)
  7956.    }
  7957.  
  7958.    function sayNick() {
  7959.        bot.chat(`My name is ${bot.player.displayName}`)
  7960.    }
  7961.    
  7962.    // begin of autoeats paste
  7963.    bot.once('spawn', () => {
  7964.        bot.autoEat.options = {
  7965.            priority: 'foodPoints',
  7966.            startAt: 14,
  7967.            bannedFood: []
  7968.        }
  7969.    })
  7970.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  7971.    bot.on('autoeat_started', () => {
  7972.        console.log('Auto Eat started!')
  7973.    })
  7974.  
  7975.    bot.on('autoeat_stopped', () => {
  7976.        console.log('Auto Eat stopped!')
  7977.    })
  7978.  
  7979.    bot.on('health', () => {
  7980.        if (bot.food === 20) bot.autoEat.disable()
  7981.        // Disable the plugin if the bot is at 20 food points
  7982.        else bot.autoEat.enable() // Else enable the plugin again
  7983.    })
  7984.    // end of paste autoeat
  7985.  
  7986.    bot.on('whisper', (username, message, rawMessage) => {
  7987.        console.log(`I received a message from ${username}: ${message}`)
  7988.        bot.whisper(username, 'I can tell secrets too.')
  7989.    })
  7990.  
  7991.    bot.on('nonSpokenChat', (message) => {
  7992.        console.log(`Non spoken chat: ${message}`)
  7993.    })
  7994.    
  7995.    bot.on('login', () => {
  7996.        bot.chat('Hi everyone!')
  7997.    })
  7998.    
  7999.    bot.on('spawnReset', (message) => {
  8000.        console.log('spawnReset command used')
  8001.        stopGuarding()
  8002.        bot.hawkEye.stop()
  8003.        bot.chat('Oh noez! My bed is broken.')
  8004.    })
  8005.    
  8006.    bot.on('forcedMove', () => {
  8007.        console.log(`I have been forced to move to ${bot.entity.position}`)
  8008.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  8009.    })
  8010.    
  8011.    bot.on('health', () => {
  8012.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  8013.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  8014.    })
  8015.  
  8016.    bot.on('death', () => {
  8017.        console.log('I died, stopping and respawning')
  8018.        stopGuarding()
  8019.        bot.hawkEye.stop()
  8020.        bot.respawn
  8021.        bot.chat('I died x.x ugh!!')
  8022.        // need instructions to return to
  8023.        // what i was doing.
  8024.    })
  8025.  
  8026.    bot.on('kicked', (reason) => {
  8027.        console.log(`I got kicked for ${reason}`)
  8028.    })
  8029.    
  8030.    bot.on('rain', () => {
  8031.        if (bot.isRaining) {
  8032.            console.log('It started raining.')
  8033.            //bot.chat('It started raining.')
  8034.        } else {
  8035.            console.log('It stopped raining.')
  8036.            //bot.chat('It stopped raining.')
  8037.        }
  8038.    })
  8039.  
  8040.    bot.on('noteHeard', (block, instrument, pitch) => {
  8041.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  8042.    })
  8043.  
  8044.    bot.on('chestLidMove', (block, isOpen) => {
  8045.        const action = isOpen ? 'open' : 'close'
  8046.        bot.chat(`Hey, did someone just ${action} a chest?`)
  8047.    })
  8048.  
  8049.    bot.on('pistonMove', (block, isPulling, direction) => {
  8050.        const action = isPulling ? 'pulling' : 'pushing'
  8051.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  8052.    })
  8053.  
  8054.    bot.on('playerJoined', (player) => {
  8055.        if (player.username !== bot.username) {
  8056.            console.log(`${player.username}! Joined the server.`)
  8057.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  8058.        }
  8059.    })
  8060.  
  8061.    bot.on('playerLeft', (player) => {
  8062.        if (player.username === bot.username) return
  8063.        console.log(`${player.username} left the server`)
  8064.        // bot.chat(`Bye ${player.username}`)
  8065.    })
  8066.    /*
  8067.    bot.on('playerCollect', (collector, collected) => {
  8068.        if (collector.type === 'player' && collected.type === 'object') {
  8069.            const rawItem = collected.metadata[10]
  8070.            const item = mineflayer.Item.fromNotch(rawItem)
  8071.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  8072.        }
  8073.    })
  8074.    */
  8075.    /*    
  8076.    bot.on('entitySpawn', (entity) => {
  8077.        if (entity.type === 'mob') {
  8078.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  8079.        } else if (entity.type === 'player') {
  8080.            console.log(`Look who decided to show up: ${entity.username}`)
  8081.        } else if (entity.type === 'object') {
  8082.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  8083.        } else if (entity.type === 'global') {
  8084.            console.log('Ooh lightning!')
  8085.        } else if (entity.type === 'orb') {
  8086.            console.log('Gimme dat exp orb!')
  8087.        }
  8088.    })
  8089.    */    
  8090.  
  8091.    const target = bot.hawkEye.getPlayer()
  8092.    console.log(target)
  8093.    if (!target) {
  8094.        return false
  8095.    }
  8096.  
  8097.    function Start() {
  8098.        bot.hawkEye.autoAttack(target)
  8099.    }
  8100.  
  8101.    bot.on('entityHurt', (entity) => {
  8102.        if (entity.type === 'mob') {
  8103.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  8104.        } else if (entity.type === 'player') {
  8105.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  8106.        }
  8107.    })
  8108.  
  8109.    bot.on('entitySwingArm', (entity) => {
  8110.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  8111.    })
  8112.  
  8113.    bot.on('entityCrouch', (entity) => {
  8114.        bot.chat(`${entity.username}: you so sneaky.`)
  8115.    })
  8116.  
  8117.    bot.on('entityUncrouch', (entity) => {
  8118.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  8119.    })
  8120.  
  8121.    bot.on('entitySleep', (entity) => {
  8122.        bot.chat(`Good night, ${entity.username}`)
  8123.    })
  8124.  
  8125.    bot.on('entityWake', (entity) => {
  8126.        bot.chat(`Top of the morning, ${entity.username}`)
  8127.    })
  8128.  
  8129.    bot.on('entityEat', (entity) => {
  8130.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  8131.    })
  8132.  
  8133.    bot.on('entityAttach', (entity, vehicle) => {
  8134.        if (entity.type === 'player' && vehicle.type === 'object') {
  8135.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  8136.        }
  8137.    })
  8138.  
  8139.    bot.on('entityDetach', (entity, vehicle) => {
  8140.        if (entity.type === 'player' && vehicle.type === 'object') {
  8141.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  8142.        }
  8143.    })
  8144.  
  8145.    bot.on('entityEquipmentChange', (entity) => {
  8146.        console.log('entityEquipmentChange', entity)
  8147.    })
  8148.  
  8149.    bot.on('entityEffect', (entity, effect) => {
  8150.        console.log('entityEffect', entity, effect)
  8151.    })
  8152.  
  8153.    bot.on('entityEffectEnd', (entity, effect) => {
  8154.        console.log('entityEffectEnd', entity, effect)
  8155.    })
  8156.  
  8157.    function guardArea(pos) {
  8158.        guardPos = pos.clone()
  8159.        
  8160.        if (!bot.pvp.target) {
  8161.            moveToGuardPos()
  8162.        }
  8163.    }
  8164.    
  8165.    function stopGuarding() {
  8166.        guardPos = null
  8167.        bot.pvp.stop()
  8168.        bot.pathfinder.setGoal(null)
  8169.    }
  8170.    
  8171.    function moveToGuardPos() {
  8172.        const mcData = require('minecraft-data')(bot.version)
  8173.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  8174.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  8175.    }
  8176.    
  8177.    bot.on('stoppedAttacking', () => {
  8178.        if (guardPos) {
  8179.            moveToGuardPos()
  8180.        }
  8181.    })
  8182.    
  8183.    bot.on('physicTick', () => {
  8184.        if (bot.pvp.target) return
  8185.        if (bot.pathfinder.isMoving()) return
  8186.        
  8187.        const entity = bot.nearestEntity()
  8188.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  8189.    })
  8190.    
  8191.    bot.on('physicTick', () => {
  8192.        if (!guardPos) return
  8193.        
  8194.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  8195.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  8196.        
  8197.        const entity = bot.nearestEntity(filter)
  8198.        if (entity) {
  8199.            bot.pvp.attack(entity)
  8200.        }
  8201.    })
  8202.    /*
  8203.    bot.on('chat', (username, message) => {
  8204.        if (username === bot.username) return
  8205.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  8206.        if (result) {
  8207.            canSee(new Vec3(result[1], result[2], result[3]))
  8208.            return
  8209.        }
  8210.        switch (message) {
  8211.            case 'pos':
  8212.                console.log("pos command used")
  8213.                sayPosition(username)
  8214.                break
  8215.            case 'wearing':
  8216.                console.log("wearing command used")
  8217.                sayEquipment()
  8218.                break
  8219.            case 'nick':
  8220.                console.log("saynick command used")
  8221.                sayNick()
  8222.                break
  8223.            case 'spawn':
  8224.                console.log("spawn command used")
  8225.                saySpawnPoint()
  8226.                break
  8227.            case 'block':
  8228.                console.log("block command used")
  8229.                sayBlockUnder(username)
  8230.                break
  8231.            default:
  8232.                console.log("I am ready!")
  8233.                bot.chat("I am ready!")
  8234.    }
  8235.    */
  8236.  
  8237.    // text of bots username and help will give a list of bot commands
  8238.    bot.on('chat', (username, message) => { // work in progress....
  8239.        if (message === `${bot.player.displayName} help`)
  8240.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  8241.            bot.chat('pos, wearing, nick, spawn, block ')
  8242.            bot.chat('arch-start, Version.(wip not all commands work...)')
  8243.            bot.chat('Bot may just leave if it errors out.')
  8244.    })
  8245.  
  8246.    bot.on('chat', (username, message) => { // work in progress....
  8247.        if (message === 'Version') {
  8248.            console.log("Version command used just used")
  8249.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  8250.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  8251.            console.log("sayVersion command used")
  8252.            sayVersion(username)
  8253.            return
  8254.        }
  8255.    })
  8256.  
  8257.    bot.on('chat', (username, message) => {
  8258.        if (message === 'leave') {
  8259.                console.log("leave command used")
  8260.                bot.chat("Yes sir right away!")
  8261.                bot.quit(username)
  8262.                return
  8263.        }
  8264.    })
  8265.  
  8266.    bot.on('chat', (username, message) => {
  8267.        if (message === 'arch-start') {
  8268.            console.log("arch-start command used")
  8269.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  8270.            Start()
  8271.            return
  8272.        }
  8273.    })
  8274.  
  8275.    bot.on('chat', (username, message) => {
  8276.        if (message === 'guard') {          // if message guard do gaurd
  8277.            const player = bot.players[username]
  8278.  
  8279.            if (!player) {
  8280.                bot.chat("I can't see you.")
  8281.                return
  8282.            }
  8283.        bot.chat('I will guard that location.')
  8284.            guardArea(player.entity.position)
  8285.            }
  8286.  
  8287.            if (message === 'fight me') {
  8288.                const player = bot.players[username]
  8289.  
  8290.                if (!player) {
  8291.                    bot.chat("I can't see you.")
  8292.                    return
  8293.                }
  8294.  
  8295.            bot.chat('Prepare to fight!')
  8296.            bot.chat('5')
  8297.            bot.chat('4')
  8298.            bot.chat('3')
  8299.            bot.chat('2')
  8300.            bot.chat('1')
  8301.            bot.chat('GO!!!')
  8302.            bot.pvp.attack(player.entity)
  8303.            }
  8304.  
  8305.            if (message === 'stop') {
  8306.                bot.chat('I will stop!')
  8307.                bot.hawkEye.stop()
  8308.                stopGuarding()
  8309.            }
  8310.    })
  8311.  
  8312.    function not_busy() {
  8313.        guardPos = pos.clone()
  8314.  
  8315.        if (guardPos == null) {
  8316.            return false
  8317.        
  8318.        } else { (guardPos == !null)
  8319.                return true
  8320.            }
  8321.        }
  8322.    
  8323.    
  8324.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  8325.        if (busy == true) {
  8326.        console.log("I am busy!")
  8327.        bot.chat("I am busy!")
  8328.            } else { if (busy == false)
  8329.            console.log('I am ready!')
  8330.            bot.chat('I am ready!')
  8331.            }
  8332.    
  8333.    })
  8334.  
  8335.    bot.on('sleep', () => {
  8336.        bot.chat('Good night!')
  8337.    })
  8338.  
  8339.    bot.on('wake', () => {
  8340.        bot.chat('Good morning!')
  8341.    })
  8342.  
  8343.    function goToSleep() {
  8344.        const bed = bot.findBlock({
  8345.            matching: block => bot.isABed(block)
  8346.        })
  8347.        if (bed) {
  8348.            bot.sleep(bed, (err) => {
  8349.                if (err) {
  8350.                    bot.chat(`I can't sleep: ${err.message}`)
  8351.                } else {
  8352.                    bot.chat("I'm sleeping")
  8353.                }
  8354.            })
  8355.        } else {
  8356.            bot.chat('No nearby bed')
  8357.        }
  8358.    }
  8359.  
  8360.    function wakeUp() {
  8361.        bot.wake((err) => {
  8362.            if (err) {
  8363.                bot.chat(`I can't wake up: ${err.message}`)
  8364.             } else {
  8365.                 bot.chat('I woke up')
  8366.             }
  8367.         }
  8368.        
  8369.     )
  8370. }
  8371. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  8372. const Vec3 = require('vec3').Vec3
  8373. const fs = require('fs')
  8374. const { version } = require('os')
  8375. const pvp = require('mineflayer-pvp').plugin
  8376. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  8377. const armorManager = require('mineflayer-armor-manager')
  8378. const autoeat = require('mineflayer-auto-eat')
  8379. const minecraftHawkEye = require('minecrafthawkeye')
  8380.  
  8381. function jsonReader(filePath, cb) {
  8382.     fs.readFile(filePath, (err, fileData) => {
  8383.         if (err) {
  8384.             return cb && cb(err)
  8385.         }
  8386.         try {
  8387.             const object = JSON.parse(fileData)
  8388.             return cb && cb(null, object)
  8389.         } catch (err) {
  8390.             return cb && cb(err)
  8391.         }
  8392.     })
  8393. }
  8394.  
  8395. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  8396.     if (err) {
  8397.         console.log(err)
  8398.         return
  8399.     }
  8400.  
  8401.     const bot = mineflayer.createBot({
  8402.         version: mc_login_info.version,
  8403.         host: mc_login_info.host,
  8404.         port: mc_login_info.port,
  8405.         username: mc_login_info.username,
  8406.         password: mc_login_info.password,
  8407.         // give time for communication to hosts&client with longer ping times
  8408.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  8409.         logErrors: true
  8410.     })
  8411. })
  8412.  
  8413.     bot._client.on('custom_payload', (packet) => {
  8414.         // console.log(packet)
  8415.         if (packet.channel === "minecraft:brand") {
  8416.             let data = packet.data
  8417.             let brand = String.fromCharCode.apply(null, data)
  8418.             console.log(brand)
  8419.         }
  8420.     })
  8421.  
  8422.     bot.once('login', () => {
  8423.         console.log('logged in')
  8424.         console.log(`curent client version ${bot.version}`)
  8425.         // console.log(`curent server version is ${server.version}`)
  8426.     })
  8427.  
  8428.     bot.loadPlugin(autoeat)
  8429.     bot.loadPlugin(armorManager)
  8430.     bot.loadPlugin(minecraftHawkEye)
  8431.     bot.loadPlugin(pathfinder)
  8432.     bot.loadPlugin(pvp)
  8433.  
  8434.    
  8435.     bot.on('playerCollect', (collector, itemDrop) => {
  8436.         if (collector !== bot.entity) return
  8437.        
  8438.         setTimeout(() => {
  8439.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  8440.             if (sword) bot.equip(sword, 'hand')
  8441.         }, 150)
  8442.     })
  8443.    
  8444.     bot.on('playerCollect', (collector, itemDrop) => {
  8445.         if (collector !== bot.entity) return
  8446.        
  8447.         setTimeout(() => {
  8448.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  8449.             if (shield) bot.equip(shield, 'off-hand')
  8450.         }, 250)
  8451.     })
  8452.    
  8453.     let guardPos = null
  8454.     let busy = false
  8455.  
  8456.     bot.on('spawn', () => { // gives error when bot spawns
  8457.         console.log('spawned in server')
  8458.         bot.hawkEye.stop()
  8459.         stopGuarding()
  8460.         bot.chat('I spawned, watch out!')
  8461.     })
  8462.    
  8463.     function canSee(pos) {
  8464.         const block = bot.blockAt(pos)
  8465.         const r = bot.canSeeBlock(block)
  8466.         if (r) {
  8467.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  8468.         } else {
  8469.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  8470.         }
  8471.     }
  8472.    
  8473.     function sayPosition(username) {
  8474.         //bot.chat(`My puplic position is disabled`)
  8475.         bot.chat(`I am at ${bot.entity.position}`)
  8476.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  8477.         //bot.chat(`I don't know your position.`)
  8478.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  8479.    }
  8480.  
  8481.    function sayEquipment() {
  8482.        const eq = bot.players[username].entity.equipment
  8483.        const eqText = []
  8484.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  8485.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  8486.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  8487.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  8488.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  8489.        if (eqText.length) {
  8490.            bot.chat(`You are ${eqText.join(', ')}.`)
  8491.        } else {
  8492.            bot.chat('You are without armor!')
  8493.        }
  8494.    }
  8495.  
  8496.    function sayVersion() { // work in prograss not working yet
  8497.        bot.chat('/version')
  8498.        console.log(`${command.message} confermed ${brand}`)
  8499.    }
  8500.  
  8501.    function saySpawnPoint() {
  8502.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  8503.    }
  8504.  
  8505.    function sayBlockUnder() {
  8506.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  8507.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  8508.        console.log(block)
  8509.    }
  8510.  
  8511.    function quit(username) {
  8512.        console.log('quit command used')
  8513.        bot.quit(`${username} told me too`)
  8514.    }
  8515.  
  8516.    function sayNick() {
  8517.        bot.chat(`My name is ${bot.player.displayName}`)
  8518.    }
  8519.    
  8520.    // begin of autoeats paste
  8521.    bot.once('spawn', () => {
  8522.        bot.autoEat.options = {
  8523.            priority: 'foodPoints',
  8524.            startAt: 14,
  8525.            bannedFood: []
  8526.        }
  8527.    })
  8528.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  8529.    bot.on('autoeat_started', () => {
  8530.        console.log('Auto Eat started!')
  8531.    })
  8532.  
  8533.    bot.on('autoeat_stopped', () => {
  8534.        console.log('Auto Eat stopped!')
  8535.    })
  8536.  
  8537.    bot.on('health', () => {
  8538.        if (bot.food === 20) bot.autoEat.disable()
  8539.        // Disable the plugin if the bot is at 20 food points
  8540.        else bot.autoEat.enable() // Else enable the plugin again
  8541.    })
  8542.    // end of paste autoeat
  8543.  
  8544.    bot.on('whisper', (username, message, rawMessage) => {
  8545.        console.log(`I received a message from ${username}: ${message}`)
  8546.        bot.whisper(username, 'I can tell secrets too.')
  8547.    })
  8548.  
  8549.    bot.on('nonSpokenChat', (message) => {
  8550.        console.log(`Non spoken chat: ${message}`)
  8551.    })
  8552.    
  8553.    bot.on('login', () => {
  8554.        bot.chat('Hi everyone!')
  8555.    })
  8556.    
  8557.    bot.on('spawnReset', (message) => {
  8558.        console.log('spawnReset command used')
  8559.        stopGuarding()
  8560.        bot.hawkEye.stop()
  8561.        bot.chat('Oh noez! My bed is broken.')
  8562.    })
  8563.    
  8564.    bot.on('forcedMove', () => {
  8565.        console.log(`I have been forced to move to ${bot.entity.position}`)
  8566.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  8567.    })
  8568.    
  8569.    bot.on('health', () => {
  8570.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  8571.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  8572.    })
  8573.  
  8574.    bot.on('death', () => {
  8575.        console.log('I died, stopping and respawning')
  8576.        stopGuarding()
  8577.        bot.hawkEye.stop()
  8578.        bot.respawn
  8579.        bot.chat('I died x.x ugh!!')
  8580.        // need instructions to return to
  8581.        // what i was doing.
  8582.    })
  8583.  
  8584.    bot.on('kicked', (reason) => {
  8585.        console.log(`I got kicked for ${reason}`)
  8586.    })
  8587.    
  8588.    bot.on('rain', () => {
  8589.        if (bot.isRaining) {
  8590.            console.log('It started raining.')
  8591.            //bot.chat('It started raining.')
  8592.        } else {
  8593.            console.log('It stopped raining.')
  8594.            //bot.chat('It stopped raining.')
  8595.        }
  8596.    })
  8597.  
  8598.    bot.on('noteHeard', (block, instrument, pitch) => {
  8599.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  8600.    })
  8601.  
  8602.    bot.on('chestLidMove', (block, isOpen) => {
  8603.        const action = isOpen ? 'open' : 'close'
  8604.        bot.chat(`Hey, did someone just ${action} a chest?`)
  8605.    })
  8606.  
  8607.    bot.on('pistonMove', (block, isPulling, direction) => {
  8608.        const action = isPulling ? 'pulling' : 'pushing'
  8609.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  8610.    })
  8611.  
  8612.    bot.on('playerJoined', (player) => {
  8613.        if (player.username !== bot.username) {
  8614.            console.log(`${player.username}! Joined the server.`)
  8615.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  8616.        }
  8617.    })
  8618.  
  8619.    bot.on('playerLeft', (player) => {
  8620.        if (player.username === bot.username) return
  8621.        console.log(`${player.username} left the server`)
  8622.        // bot.chat(`Bye ${player.username}`)
  8623.    })
  8624.    /*
  8625.    bot.on('playerCollect', (collector, collected) => {
  8626.        if (collector.type === 'player' && collected.type === 'object') {
  8627.            const rawItem = collected.metadata[10]
  8628.            const item = mineflayer.Item.fromNotch(rawItem)
  8629.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  8630.        }
  8631.    })
  8632.    */
  8633.    /*    
  8634.    bot.on('entitySpawn', (entity) => {
  8635.        if (entity.type === 'mob') {
  8636.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  8637.        } else if (entity.type === 'player') {
  8638.            console.log(`Look who decided to show up: ${entity.username}`)
  8639.        } else if (entity.type === 'object') {
  8640.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  8641.        } else if (entity.type === 'global') {
  8642.            console.log('Ooh lightning!')
  8643.        } else if (entity.type === 'orb') {
  8644.            console.log('Gimme dat exp orb!')
  8645.        }
  8646.    })
  8647.    */    
  8648.  
  8649.    const target = bot.hawkEye.getPlayer()
  8650.    console.log(target)
  8651.    if (!target) {
  8652.        return false
  8653.    }
  8654.  
  8655.    function Start() {
  8656.        bot.hawkEye.autoAttack(target)
  8657.    }
  8658.  
  8659.    bot.on('entityHurt', (entity) => {
  8660.        if (entity.type === 'mob') {
  8661.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  8662.        } else if (entity.type === 'player') {
  8663.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  8664.        }
  8665.    })
  8666.  
  8667.    bot.on('entitySwingArm', (entity) => {
  8668.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  8669.    })
  8670.  
  8671.    bot.on('entityCrouch', (entity) => {
  8672.        bot.chat(`${entity.username}: you so sneaky.`)
  8673.    })
  8674.  
  8675.    bot.on('entityUncrouch', (entity) => {
  8676.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  8677.    })
  8678.  
  8679.    bot.on('entitySleep', (entity) => {
  8680.        bot.chat(`Good night, ${entity.username}`)
  8681.    })
  8682.  
  8683.    bot.on('entityWake', (entity) => {
  8684.        bot.chat(`Top of the morning, ${entity.username}`)
  8685.    })
  8686.  
  8687.    bot.on('entityEat', (entity) => {
  8688.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  8689.    })
  8690.  
  8691.    bot.on('entityAttach', (entity, vehicle) => {
  8692.        if (entity.type === 'player' && vehicle.type === 'object') {
  8693.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  8694.        }
  8695.    })
  8696.  
  8697.    bot.on('entityDetach', (entity, vehicle) => {
  8698.        if (entity.type === 'player' && vehicle.type === 'object') {
  8699.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  8700.        }
  8701.    })
  8702.  
  8703.    bot.on('entityEquipmentChange', (entity) => {
  8704.        console.log('entityEquipmentChange', entity)
  8705.    })
  8706.  
  8707.    bot.on('entityEffect', (entity, effect) => {
  8708.        console.log('entityEffect', entity, effect)
  8709.    })
  8710.  
  8711.    bot.on('entityEffectEnd', (entity, effect) => {
  8712.        console.log('entityEffectEnd', entity, effect)
  8713.    })
  8714.  
  8715.    function guardArea(pos) {
  8716.        guardPos = pos.clone()
  8717.        
  8718.        if (!bot.pvp.target) {
  8719.            moveToGuardPos()
  8720.        }
  8721.    }
  8722.    
  8723.    function stopGuarding() {
  8724.        guardPos = null
  8725.        bot.pvp.stop()
  8726.        bot.pathfinder.setGoal(null)
  8727.    }
  8728.    
  8729.    function moveToGuardPos() {
  8730.        const mcData = require('minecraft-data')(bot.version)
  8731.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  8732.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  8733.    }
  8734.    
  8735.    bot.on('stoppedAttacking', () => {
  8736.        if (guardPos) {
  8737.            moveToGuardPos()
  8738.        }
  8739.    })
  8740.    
  8741.    bot.on('physicTick', () => {
  8742.        if (bot.pvp.target) return
  8743.        if (bot.pathfinder.isMoving()) return
  8744.        
  8745.        const entity = bot.nearestEntity()
  8746.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  8747.    })
  8748.    
  8749.    bot.on('physicTick', () => {
  8750.        if (!guardPos) return
  8751.        
  8752.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  8753.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  8754.        
  8755.        const entity = bot.nearestEntity(filter)
  8756.        if (entity) {
  8757.            bot.pvp.attack(entity)
  8758.        }
  8759.    })
  8760.    /*
  8761.    bot.on('chat', (username, message) => {
  8762.        if (username === bot.username) return
  8763.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  8764.        if (result) {
  8765.            canSee(new Vec3(result[1], result[2], result[3]))
  8766.            return
  8767.        }
  8768.        switch (message) {
  8769.            case 'pos':
  8770.                console.log("pos command used")
  8771.                sayPosition(username)
  8772.                break
  8773.            case 'wearing':
  8774.                console.log("wearing command used")
  8775.                sayEquipment()
  8776.                break
  8777.            case 'nick':
  8778.                console.log("saynick command used")
  8779.                sayNick()
  8780.                break
  8781.            case 'spawn':
  8782.                console.log("spawn command used")
  8783.                saySpawnPoint()
  8784.                break
  8785.            case 'block':
  8786.                console.log("block command used")
  8787.                sayBlockUnder(username)
  8788.                break
  8789.            default:
  8790.                console.log("I am ready!")
  8791.                bot.chat("I am ready!")
  8792.    }
  8793.    */
  8794.  
  8795.    // text of bots username and help will give a list of bot commands
  8796.    bot.on('chat', (username, message) => { // work in progress....
  8797.        if (message === `${bot.player.displayName} help`)
  8798.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  8799.            bot.chat('pos, wearing, nick, spawn, block ')
  8800.            bot.chat('arch-start, Version.(wip not all commands work...)')
  8801.            bot.chat('Bot may just leave if it errors out.')
  8802.    })
  8803.  
  8804.    bot.on('chat', (username, message) => { // work in progress....
  8805.        if (message === 'Version') {
  8806.            console.log("Version command used just used")
  8807.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  8808.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  8809.            console.log("sayVersion command used")
  8810.            sayVersion(username)
  8811.            return
  8812.        }
  8813.    })
  8814.  
  8815.    bot.on('chat', (username, message) => {
  8816.        if (message === 'leave') {
  8817.                console.log("leave command used")
  8818.                bot.chat("Yes sir right away!")
  8819.                bot.quit(username)
  8820.                return
  8821.        }
  8822.    })
  8823.  
  8824.    bot.on('chat', (username, message) => {
  8825.        if (message === 'arch-start') {
  8826.            console.log("arch-start command used")
  8827.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  8828.            Start()
  8829.            return
  8830.        }
  8831.    })
  8832.  
  8833.    bot.on('chat', (username, message) => {
  8834.        if (message === 'guard') {          // if message guard do gaurd
  8835.            const player = bot.players[username]
  8836.  
  8837.            if (!player) {
  8838.                bot.chat("I can't see you.")
  8839.                return
  8840.            }
  8841.        bot.chat('I will guard that location.')
  8842.            guardArea(player.entity.position)
  8843.            }
  8844.  
  8845.            if (message === 'fight me') {
  8846.                const player = bot.players[username]
  8847.  
  8848.                if (!player) {
  8849.                    bot.chat("I can't see you.")
  8850.                    return
  8851.                }
  8852.  
  8853.            bot.chat('Prepare to fight!')
  8854.            bot.chat('5')
  8855.            bot.chat('4')
  8856.            bot.chat('3')
  8857.            bot.chat('2')
  8858.            bot.chat('1')
  8859.            bot.chat('GO!!!')
  8860.            bot.pvp.attack(player.entity)
  8861.            }
  8862.  
  8863.            if (message === 'stop') {
  8864.                bot.chat('I will stop!')
  8865.                bot.hawkEye.stop()
  8866.                stopGuarding()
  8867.            }
  8868.    })
  8869.  
  8870.    function not_busy() {
  8871.        guardPos = pos.clone()
  8872.  
  8873.        if (guardPos == null) {
  8874.            return false
  8875.        
  8876.        } else { (guardPos == !null)
  8877.                return true
  8878.            }
  8879.        }
  8880.    
  8881.    
  8882.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  8883.        if (busy == true) {
  8884.        console.log("I am busy!")
  8885.        bot.chat("I am busy!")
  8886.            } else { if (busy == false)
  8887.            console.log('I am ready!')
  8888.            bot.chat('I am ready!')
  8889.            }
  8890.    
  8891.    })
  8892.  
  8893.    bot.on('sleep', () => {
  8894.        bot.chat('Good night!')
  8895.    })
  8896.  
  8897.    bot.on('wake', () => {
  8898.        bot.chat('Good morning!')
  8899.    })
  8900.  
  8901.    function goToSleep() {
  8902.        const bed = bot.findBlock({
  8903.            matching: block => bot.isABed(block)
  8904.        })
  8905.        if (bed) {
  8906.            bot.sleep(bed, (err) => {
  8907.                if (err) {
  8908.                    bot.chat(`I can't sleep: ${err.message}`)
  8909.                } else {
  8910.                    bot.chat("I'm sleeping")
  8911.                }
  8912.            })
  8913.        } else {
  8914.            bot.chat('No nearby bed')
  8915.        }
  8916.    }
  8917.  
  8918.    function wakeUp() {
  8919.        bot.wake((err) => {
  8920.            if (err) {
  8921.                bot.chat(`I can't wake up: ${err.message}`)
  8922.             } else {
  8923.                 bot.chat('I woke up')
  8924.             }
  8925.         }
  8926.        
  8927.     )
  8928. }
  8929. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  8930. const Vec3 = require('vec3').Vec3
  8931. const fs = require('fs')
  8932. const { version } = require('os')
  8933. const pvp = require('mineflayer-pvp').plugin
  8934. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  8935. const armorManager = require('mineflayer-armor-manager')
  8936. const autoeat = require('mineflayer-auto-eat')
  8937. const minecraftHawkEye = require('minecrafthawkeye')
  8938.  
  8939. function jsonReader(filePath, cb) {
  8940.     fs.readFile(filePath, (err, fileData) => {
  8941.         if (err) {
  8942.             return cb && cb(err)
  8943.         }
  8944.         try {
  8945.             const object = JSON.parse(fileData)
  8946.             return cb && cb(null, object)
  8947.         } catch (err) {
  8948.             return cb && cb(err)
  8949.         }
  8950.     })
  8951. }
  8952.  
  8953. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  8954.     if (err) {
  8955.         console.log(err)
  8956.         return
  8957.     }
  8958.  
  8959.     const bot = mineflayer.createBot({
  8960.         version: mc_login_info.version,
  8961.         host: mc_login_info.host,
  8962.         port: mc_login_info.port,
  8963.         username: mc_login_info.username,
  8964.         password: mc_login_info.password,
  8965.         // give time for communication to hosts&client with longer ping times
  8966.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  8967.         logErrors: true
  8968.     })
  8969. })
  8970.  
  8971.     bot._client.on('custom_payload', (packet) => {
  8972.         // console.log(packet)
  8973.         if (packet.channel === "minecraft:brand") {
  8974.             let data = packet.data
  8975.             let brand = String.fromCharCode.apply(null, data)
  8976.             console.log(brand)
  8977.         }
  8978.     })
  8979.  
  8980.     bot.once('login', () => {
  8981.         console.log('logged in')
  8982.         console.log(`curent client version ${bot.version}`)
  8983.         // console.log(`curent server version is ${server.version}`)
  8984.     })
  8985.  
  8986.     bot.loadPlugin(autoeat)
  8987.     bot.loadPlugin(armorManager)
  8988.     bot.loadPlugin(minecraftHawkEye)
  8989.     bot.loadPlugin(pathfinder)
  8990.     bot.loadPlugin(pvp)
  8991.  
  8992.    
  8993.     bot.on('playerCollect', (collector, itemDrop) => {
  8994.         if (collector !== bot.entity) return
  8995.        
  8996.         setTimeout(() => {
  8997.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  8998.             if (sword) bot.equip(sword, 'hand')
  8999.         }, 150)
  9000.     })
  9001.    
  9002.     bot.on('playerCollect', (collector, itemDrop) => {
  9003.         if (collector !== bot.entity) return
  9004.        
  9005.         setTimeout(() => {
  9006.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  9007.             if (shield) bot.equip(shield, 'off-hand')
  9008.         }, 250)
  9009.     })
  9010.    
  9011.     let guardPos = null
  9012.     let busy = false
  9013.  
  9014.     bot.on('spawn', () => { // gives error when bot spawns
  9015.         console.log('spawned in server')
  9016.         bot.hawkEye.stop()
  9017.         stopGuarding()
  9018.         bot.chat('I spawned, watch out!')
  9019.     })
  9020.    
  9021.     function canSee(pos) {
  9022.         const block = bot.blockAt(pos)
  9023.         const r = bot.canSeeBlock(block)
  9024.         if (r) {
  9025.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  9026.         } else {
  9027.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  9028.         }
  9029.     }
  9030.    
  9031.     function sayPosition(username) {
  9032.         //bot.chat(`My puplic position is disabled`)
  9033.         bot.chat(`I am at ${bot.entity.position}`)
  9034.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  9035.         //bot.chat(`I don't know your position.`)
  9036.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  9037.    }
  9038.  
  9039.    function sayEquipment() {
  9040.        const eq = bot.players[username].entity.equipment
  9041.        const eqText = []
  9042.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  9043.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  9044.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  9045.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  9046.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  9047.        if (eqText.length) {
  9048.            bot.chat(`You are ${eqText.join(', ')}.`)
  9049.        } else {
  9050.            bot.chat('You are without armor!')
  9051.        }
  9052.    }
  9053.  
  9054.    function sayVersion() { // work in prograss not working yet
  9055.        bot.chat('/version')
  9056.        console.log(`${command.message} confermed ${brand}`)
  9057.    }
  9058.  
  9059.    function saySpawnPoint() {
  9060.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  9061.    }
  9062.  
  9063.    function sayBlockUnder() {
  9064.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  9065.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  9066.        console.log(block)
  9067.    }
  9068.  
  9069.    function quit(username) {
  9070.        console.log('quit command used')
  9071.        bot.quit(`${username} told me too`)
  9072.    }
  9073.  
  9074.    function sayNick() {
  9075.        bot.chat(`My name is ${bot.player.displayName}`)
  9076.    }
  9077.    
  9078.    // begin of autoeats paste
  9079.    bot.once('spawn', () => {
  9080.        bot.autoEat.options = {
  9081.            priority: 'foodPoints',
  9082.            startAt: 14,
  9083.            bannedFood: []
  9084.        }
  9085.    })
  9086.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  9087.    bot.on('autoeat_started', () => {
  9088.        console.log('Auto Eat started!')
  9089.    })
  9090.  
  9091.    bot.on('autoeat_stopped', () => {
  9092.        console.log('Auto Eat stopped!')
  9093.    })
  9094.  
  9095.    bot.on('health', () => {
  9096.        if (bot.food === 20) bot.autoEat.disable()
  9097.        // Disable the plugin if the bot is at 20 food points
  9098.        else bot.autoEat.enable() // Else enable the plugin again
  9099.    })
  9100.    // end of paste autoeat
  9101.  
  9102.    bot.on('whisper', (username, message, rawMessage) => {
  9103.        console.log(`I received a message from ${username}: ${message}`)
  9104.        bot.whisper(username, 'I can tell secrets too.')
  9105.    })
  9106.  
  9107.    bot.on('nonSpokenChat', (message) => {
  9108.        console.log(`Non spoken chat: ${message}`)
  9109.    })
  9110.    
  9111.    bot.on('login', () => {
  9112.        bot.chat('Hi everyone!')
  9113.    })
  9114.    
  9115.    bot.on('spawnReset', (message) => {
  9116.        console.log('spawnReset command used')
  9117.        stopGuarding()
  9118.        bot.hawkEye.stop()
  9119.        bot.chat('Oh noez! My bed is broken.')
  9120.    })
  9121.    
  9122.    bot.on('forcedMove', () => {
  9123.        console.log(`I have been forced to move to ${bot.entity.position}`)
  9124.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  9125.    })
  9126.    
  9127.    bot.on('health', () => {
  9128.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  9129.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  9130.    })
  9131.  
  9132.    bot.on('death', () => {
  9133.        console.log('I died, stopping and respawning')
  9134.        stopGuarding()
  9135.        bot.hawkEye.stop()
  9136.        bot.respawn
  9137.        bot.chat('I died x.x ugh!!')
  9138.        // need instructions to return to
  9139.        // what i was doing.
  9140.    })
  9141.  
  9142.    bot.on('kicked', (reason) => {
  9143.        console.log(`I got kicked for ${reason}`)
  9144.    })
  9145.    
  9146.    bot.on('rain', () => {
  9147.        if (bot.isRaining) {
  9148.            console.log('It started raining.')
  9149.            //bot.chat('It started raining.')
  9150.        } else {
  9151.            console.log('It stopped raining.')
  9152.            //bot.chat('It stopped raining.')
  9153.        }
  9154.    })
  9155.  
  9156.    bot.on('noteHeard', (block, instrument, pitch) => {
  9157.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  9158.    })
  9159.  
  9160.    bot.on('chestLidMove', (block, isOpen) => {
  9161.        const action = isOpen ? 'open' : 'close'
  9162.        bot.chat(`Hey, did someone just ${action} a chest?`)
  9163.    })
  9164.  
  9165.    bot.on('pistonMove', (block, isPulling, direction) => {
  9166.        const action = isPulling ? 'pulling' : 'pushing'
  9167.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  9168.    })
  9169.  
  9170.    bot.on('playerJoined', (player) => {
  9171.        if (player.username !== bot.username) {
  9172.            console.log(`${player.username}! Joined the server.`)
  9173.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  9174.        }
  9175.    })
  9176.  
  9177.    bot.on('playerLeft', (player) => {
  9178.        if (player.username === bot.username) return
  9179.        console.log(`${player.username} left the server`)
  9180.        // bot.chat(`Bye ${player.username}`)
  9181.    })
  9182.    /*
  9183.    bot.on('playerCollect', (collector, collected) => {
  9184.        if (collector.type === 'player' && collected.type === 'object') {
  9185.            const rawItem = collected.metadata[10]
  9186.            const item = mineflayer.Item.fromNotch(rawItem)
  9187.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  9188.        }
  9189.    })
  9190.    */
  9191.    /*    
  9192.    bot.on('entitySpawn', (entity) => {
  9193.        if (entity.type === 'mob') {
  9194.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  9195.        } else if (entity.type === 'player') {
  9196.            console.log(`Look who decided to show up: ${entity.username}`)
  9197.        } else if (entity.type === 'object') {
  9198.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  9199.        } else if (entity.type === 'global') {
  9200.            console.log('Ooh lightning!')
  9201.        } else if (entity.type === 'orb') {
  9202.            console.log('Gimme dat exp orb!')
  9203.        }
  9204.    })
  9205.    */    
  9206.  
  9207.    const target = bot.hawkEye.getPlayer()
  9208.    console.log(target)
  9209.    if (!target) {
  9210.        return false
  9211.    }
  9212.  
  9213.    function Start() {
  9214.        bot.hawkEye.autoAttack(target)
  9215.    }
  9216.  
  9217.    bot.on('entityHurt', (entity) => {
  9218.        if (entity.type === 'mob') {
  9219.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  9220.        } else if (entity.type === 'player') {
  9221.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  9222.        }
  9223.    })
  9224.  
  9225.    bot.on('entitySwingArm', (entity) => {
  9226.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  9227.    })
  9228.  
  9229.    bot.on('entityCrouch', (entity) => {
  9230.        bot.chat(`${entity.username}: you so sneaky.`)
  9231.    })
  9232.  
  9233.    bot.on('entityUncrouch', (entity) => {
  9234.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  9235.    })
  9236.  
  9237.    bot.on('entitySleep', (entity) => {
  9238.        bot.chat(`Good night, ${entity.username}`)
  9239.    })
  9240.  
  9241.    bot.on('entityWake', (entity) => {
  9242.        bot.chat(`Top of the morning, ${entity.username}`)
  9243.    })
  9244.  
  9245.    bot.on('entityEat', (entity) => {
  9246.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  9247.    })
  9248.  
  9249.    bot.on('entityAttach', (entity, vehicle) => {
  9250.        if (entity.type === 'player' && vehicle.type === 'object') {
  9251.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  9252.        }
  9253.    })
  9254.  
  9255.    bot.on('entityDetach', (entity, vehicle) => {
  9256.        if (entity.type === 'player' && vehicle.type === 'object') {
  9257.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  9258.        }
  9259.    })
  9260.  
  9261.    bot.on('entityEquipmentChange', (entity) => {
  9262.        console.log('entityEquipmentChange', entity)
  9263.    })
  9264.  
  9265.    bot.on('entityEffect', (entity, effect) => {
  9266.        console.log('entityEffect', entity, effect)
  9267.    })
  9268.  
  9269.    bot.on('entityEffectEnd', (entity, effect) => {
  9270.        console.log('entityEffectEnd', entity, effect)
  9271.    })
  9272.  
  9273.    function guardArea(pos) {
  9274.        guardPos = pos.clone()
  9275.        
  9276.        if (!bot.pvp.target) {
  9277.            moveToGuardPos()
  9278.        }
  9279.    }
  9280.    
  9281.    function stopGuarding() {
  9282.        guardPos = null
  9283.        bot.pvp.stop()
  9284.        bot.pathfinder.setGoal(null)
  9285.    }
  9286.    
  9287.    function moveToGuardPos() {
  9288.        const mcData = require('minecraft-data')(bot.version)
  9289.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  9290.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  9291.    }
  9292.    
  9293.    bot.on('stoppedAttacking', () => {
  9294.        if (guardPos) {
  9295.            moveToGuardPos()
  9296.        }
  9297.    })
  9298.    
  9299.    bot.on('physicTick', () => {
  9300.        if (bot.pvp.target) return
  9301.        if (bot.pathfinder.isMoving()) return
  9302.        
  9303.        const entity = bot.nearestEntity()
  9304.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  9305.    })
  9306.    
  9307.    bot.on('physicTick', () => {
  9308.        if (!guardPos) return
  9309.        
  9310.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  9311.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  9312.        
  9313.        const entity = bot.nearestEntity(filter)
  9314.        if (entity) {
  9315.            bot.pvp.attack(entity)
  9316.        }
  9317.    })
  9318.    /*
  9319.    bot.on('chat', (username, message) => {
  9320.        if (username === bot.username) return
  9321.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  9322.        if (result) {
  9323.            canSee(new Vec3(result[1], result[2], result[3]))
  9324.            return
  9325.        }
  9326.        switch (message) {
  9327.            case 'pos':
  9328.                console.log("pos command used")
  9329.                sayPosition(username)
  9330.                break
  9331.            case 'wearing':
  9332.                console.log("wearing command used")
  9333.                sayEquipment()
  9334.                break
  9335.            case 'nick':
  9336.                console.log("saynick command used")
  9337.                sayNick()
  9338.                break
  9339.            case 'spawn':
  9340.                console.log("spawn command used")
  9341.                saySpawnPoint()
  9342.                break
  9343.            case 'block':
  9344.                console.log("block command used")
  9345.                sayBlockUnder(username)
  9346.                break
  9347.            default:
  9348.                console.log("I am ready!")
  9349.                bot.chat("I am ready!")
  9350.    }
  9351.    */
  9352.  
  9353.    // text of bots username and help will give a list of bot commands
  9354.    bot.on('chat', (username, message) => { // work in progress....
  9355.        if (message === `${bot.player.displayName} help`)
  9356.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  9357.            bot.chat('pos, wearing, nick, spawn, block ')
  9358.            bot.chat('arch-start, Version.(wip not all commands work...)')
  9359.            bot.chat('Bot may just leave if it errors out.')
  9360.    })
  9361.  
  9362.    bot.on('chat', (username, message) => { // work in progress....
  9363.        if (message === 'Version') {
  9364.            console.log("Version command used just used")
  9365.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  9366.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  9367.            console.log("sayVersion command used")
  9368.            sayVersion(username)
  9369.            return
  9370.        }
  9371.    })
  9372.  
  9373.    bot.on('chat', (username, message) => {
  9374.        if (message === 'leave') {
  9375.                console.log("leave command used")
  9376.                bot.chat("Yes sir right away!")
  9377.                bot.quit(username)
  9378.                return
  9379.        }
  9380.    })
  9381.  
  9382.    bot.on('chat', (username, message) => {
  9383.        if (message === 'arch-start') {
  9384.            console.log("arch-start command used")
  9385.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  9386.            Start()
  9387.            return
  9388.        }
  9389.    })
  9390.  
  9391.    bot.on('chat', (username, message) => {
  9392.        if (message === 'guard') {          // if message guard do gaurd
  9393.            const player = bot.players[username]
  9394.  
  9395.            if (!player) {
  9396.                bot.chat("I can't see you.")
  9397.                return
  9398.            }
  9399.        bot.chat('I will guard that location.')
  9400.            guardArea(player.entity.position)
  9401.            }
  9402.  
  9403.            if (message === 'fight me') {
  9404.                const player = bot.players[username]
  9405.  
  9406.                if (!player) {
  9407.                    bot.chat("I can't see you.")
  9408.                    return
  9409.                }
  9410.  
  9411.            bot.chat('Prepare to fight!')
  9412.            bot.chat('5')
  9413.            bot.chat('4')
  9414.            bot.chat('3')
  9415.            bot.chat('2')
  9416.            bot.chat('1')
  9417.            bot.chat('GO!!!')
  9418.            bot.pvp.attack(player.entity)
  9419.            }
  9420.  
  9421.            if (message === 'stop') {
  9422.                bot.chat('I will stop!')
  9423.                bot.hawkEye.stop()
  9424.                stopGuarding()
  9425.            }
  9426.    })
  9427.  
  9428.    function not_busy() {
  9429.        guardPos = pos.clone()
  9430.  
  9431.        if (guardPos == null) {
  9432.            return false
  9433.        
  9434.        } else { (guardPos == !null)
  9435.                return true
  9436.            }
  9437.        }
  9438.    
  9439.    
  9440.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  9441.        if (busy == true) {
  9442.        console.log("I am busy!")
  9443.        bot.chat("I am busy!")
  9444.            } else { if (busy == false)
  9445.            console.log('I am ready!')
  9446.            bot.chat('I am ready!')
  9447.            }
  9448.    
  9449.    })
  9450.  
  9451.    bot.on('sleep', () => {
  9452.        bot.chat('Good night!')
  9453.    })
  9454.  
  9455.    bot.on('wake', () => {
  9456.        bot.chat('Good morning!')
  9457.    })
  9458.  
  9459.    function goToSleep() {
  9460.        const bed = bot.findBlock({
  9461.            matching: block => bot.isABed(block)
  9462.        })
  9463.        if (bed) {
  9464.            bot.sleep(bed, (err) => {
  9465.                if (err) {
  9466.                    bot.chat(`I can't sleep: ${err.message}`)
  9467.                } else {
  9468.                    bot.chat("I'm sleeping")
  9469.                }
  9470.            })
  9471.        } else {
  9472.            bot.chat('No nearby bed')
  9473.        }
  9474.    }
  9475.  
  9476.    function wakeUp() {
  9477.        bot.wake((err) => {
  9478.            if (err) {
  9479.                bot.chat(`I can't wake up: ${err.message}`)
  9480.             } else {
  9481.                 bot.chat('I woke up')
  9482.             }
  9483.         }
  9484.        
  9485.     )
  9486. }
  9487. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  9488. const Vec3 = require('vec3').Vec3
  9489. const fs = require('fs')
  9490. const { version } = require('os')
  9491. const pvp = require('mineflayer-pvp').plugin
  9492. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  9493. const armorManager = require('mineflayer-armor-manager')
  9494. const autoeat = require('mineflayer-auto-eat')
  9495. const minecraftHawkEye = require('minecrafthawkeye')
  9496.  
  9497. function jsonReader(filePath, cb) {
  9498.     fs.readFile(filePath, (err, fileData) => {
  9499.         if (err) {
  9500.             return cb && cb(err)
  9501.         }
  9502.         try {
  9503.             const object = JSON.parse(fileData)
  9504.             return cb && cb(null, object)
  9505.         } catch (err) {
  9506.             return cb && cb(err)
  9507.         }
  9508.     })
  9509. }
  9510.  
  9511. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  9512.     if (err) {
  9513.         console.log(err)
  9514.         return
  9515.     }
  9516.  
  9517.     const bot = mineflayer.createBot({
  9518.         version: mc_login_info.version,
  9519.         host: mc_login_info.host,
  9520.         port: mc_login_info.port,
  9521.         username: mc_login_info.username,
  9522.         password: mc_login_info.password,
  9523.         // give time for communication to hosts&client with longer ping times
  9524.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  9525.         logErrors: true
  9526.     })
  9527. })
  9528.  
  9529.     bot._client.on('custom_payload', (packet) => {
  9530.         // console.log(packet)
  9531.         if (packet.channel === "minecraft:brand") {
  9532.             let data = packet.data
  9533.             let brand = String.fromCharCode.apply(null, data)
  9534.             console.log(brand)
  9535.         }
  9536.     })
  9537.  
  9538.     bot.once('login', () => {
  9539.         console.log('logged in')
  9540.         console.log(`curent client version ${bot.version}`)
  9541.         // console.log(`curent server version is ${server.version}`)
  9542.     })
  9543.  
  9544.     bot.loadPlugin(autoeat)
  9545.     bot.loadPlugin(armorManager)
  9546.     bot.loadPlugin(minecraftHawkEye)
  9547.     bot.loadPlugin(pathfinder)
  9548.     bot.loadPlugin(pvp)
  9549.  
  9550.    
  9551.     bot.on('playerCollect', (collector, itemDrop) => {
  9552.         if (collector !== bot.entity) return
  9553.        
  9554.         setTimeout(() => {
  9555.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  9556.             if (sword) bot.equip(sword, 'hand')
  9557.         }, 150)
  9558.     })
  9559.    
  9560.     bot.on('playerCollect', (collector, itemDrop) => {
  9561.         if (collector !== bot.entity) return
  9562.        
  9563.         setTimeout(() => {
  9564.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  9565.             if (shield) bot.equip(shield, 'off-hand')
  9566.         }, 250)
  9567.     })
  9568.    
  9569.     let guardPos = null
  9570.     let busy = false
  9571.  
  9572.     bot.on('spawn', () => { // gives error when bot spawns
  9573.         console.log('spawned in server')
  9574.         bot.hawkEye.stop()
  9575.         stopGuarding()
  9576.         bot.chat('I spawned, watch out!')
  9577.     })
  9578.    
  9579.     function canSee(pos) {
  9580.         const block = bot.blockAt(pos)
  9581.         const r = bot.canSeeBlock(block)
  9582.         if (r) {
  9583.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  9584.         } else {
  9585.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  9586.         }
  9587.     }
  9588.    
  9589.     function sayPosition(username) {
  9590.         //bot.chat(`My puplic position is disabled`)
  9591.         bot.chat(`I am at ${bot.entity.position}`)
  9592.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  9593.         //bot.chat(`I don't know your position.`)
  9594.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  9595.    }
  9596.  
  9597.    function sayEquipment() {
  9598.        const eq = bot.players[username].entity.equipment
  9599.        const eqText = []
  9600.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  9601.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  9602.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  9603.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  9604.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  9605.        if (eqText.length) {
  9606.            bot.chat(`You are ${eqText.join(', ')}.`)
  9607.        } else {
  9608.            bot.chat('You are without armor!')
  9609.        }
  9610.    }
  9611.  
  9612.    function sayVersion() { // work in prograss not working yet
  9613.        bot.chat('/version')
  9614.        console.log(`${command.message} confermed ${brand}`)
  9615.    }
  9616.  
  9617.    function saySpawnPoint() {
  9618.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  9619.    }
  9620.  
  9621.    function sayBlockUnder() {
  9622.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  9623.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  9624.        console.log(block)
  9625.    }
  9626.  
  9627.    function quit(username) {
  9628.        console.log('quit command used')
  9629.        bot.quit(`${username} told me too`)
  9630.    }
  9631.  
  9632.    function sayNick() {
  9633.        bot.chat(`My name is ${bot.player.displayName}`)
  9634.    }
  9635.    
  9636.    // begin of autoeats paste
  9637.    bot.once('spawn', () => {
  9638.        bot.autoEat.options = {
  9639.            priority: 'foodPoints',
  9640.            startAt: 14,
  9641.            bannedFood: []
  9642.        }
  9643.    })
  9644.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  9645.    bot.on('autoeat_started', () => {
  9646.        console.log('Auto Eat started!')
  9647.    })
  9648.  
  9649.    bot.on('autoeat_stopped', () => {
  9650.        console.log('Auto Eat stopped!')
  9651.    })
  9652.  
  9653.    bot.on('health', () => {
  9654.        if (bot.food === 20) bot.autoEat.disable()
  9655.        // Disable the plugin if the bot is at 20 food points
  9656.        else bot.autoEat.enable() // Else enable the plugin again
  9657.    })
  9658.    // end of paste autoeat
  9659.  
  9660.    bot.on('whisper', (username, message, rawMessage) => {
  9661.        console.log(`I received a message from ${username}: ${message}`)
  9662.        bot.whisper(username, 'I can tell secrets too.')
  9663.    })
  9664.  
  9665.    bot.on('nonSpokenChat', (message) => {
  9666.        console.log(`Non spoken chat: ${message}`)
  9667.    })
  9668.    
  9669.    bot.on('login', () => {
  9670.        bot.chat('Hi everyone!')
  9671.    })
  9672.    
  9673.    bot.on('spawnReset', (message) => {
  9674.        console.log('spawnReset command used')
  9675.        stopGuarding()
  9676.        bot.hawkEye.stop()
  9677.        bot.chat('Oh noez! My bed is broken.')
  9678.    })
  9679.    
  9680.    bot.on('forcedMove', () => {
  9681.        console.log(`I have been forced to move to ${bot.entity.position}`)
  9682.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  9683.    })
  9684.    
  9685.    bot.on('health', () => {
  9686.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  9687.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  9688.    })
  9689.  
  9690.    bot.on('death', () => {
  9691.        console.log('I died, stopping and respawning')
  9692.        stopGuarding()
  9693.        bot.hawkEye.stop()
  9694.        bot.respawn
  9695.        bot.chat('I died x.x ugh!!')
  9696.        // need instructions to return to
  9697.        // what i was doing.
  9698.    })
  9699.  
  9700.    bot.on('kicked', (reason) => {
  9701.        console.log(`I got kicked for ${reason}`)
  9702.    })
  9703.    
  9704.    bot.on('rain', () => {
  9705.        if (bot.isRaining) {
  9706.            console.log('It started raining.')
  9707.            //bot.chat('It started raining.')
  9708.        } else {
  9709.            console.log('It stopped raining.')
  9710.            //bot.chat('It stopped raining.')
  9711.        }
  9712.    })
  9713.  
  9714.    bot.on('noteHeard', (block, instrument, pitch) => {
  9715.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  9716.    })
  9717.  
  9718.    bot.on('chestLidMove', (block, isOpen) => {
  9719.        const action = isOpen ? 'open' : 'close'
  9720.        bot.chat(`Hey, did someone just ${action} a chest?`)
  9721.    })
  9722.  
  9723.    bot.on('pistonMove', (block, isPulling, direction) => {
  9724.        const action = isPulling ? 'pulling' : 'pushing'
  9725.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  9726.    })
  9727.  
  9728.    bot.on('playerJoined', (player) => {
  9729.        if (player.username !== bot.username) {
  9730.            console.log(`${player.username}! Joined the server.`)
  9731.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  9732.        }
  9733.    })
  9734.  
  9735.    bot.on('playerLeft', (player) => {
  9736.        if (player.username === bot.username) return
  9737.        console.log(`${player.username} left the server`)
  9738.        // bot.chat(`Bye ${player.username}`)
  9739.    })
  9740.    /*
  9741.    bot.on('playerCollect', (collector, collected) => {
  9742.        if (collector.type === 'player' && collected.type === 'object') {
  9743.            const rawItem = collected.metadata[10]
  9744.            const item = mineflayer.Item.fromNotch(rawItem)
  9745.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  9746.        }
  9747.    })
  9748.    */
  9749.    /*    
  9750.    bot.on('entitySpawn', (entity) => {
  9751.        if (entity.type === 'mob') {
  9752.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  9753.        } else if (entity.type === 'player') {
  9754.            console.log(`Look who decided to show up: ${entity.username}`)
  9755.        } else if (entity.type === 'object') {
  9756.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  9757.        } else if (entity.type === 'global') {
  9758.            console.log('Ooh lightning!')
  9759.        } else if (entity.type === 'orb') {
  9760.            console.log('Gimme dat exp orb!')
  9761.        }
  9762.    })
  9763.    */    
  9764.  
  9765.    const target = bot.hawkEye.getPlayer()
  9766.    console.log(target)
  9767.    if (!target) {
  9768.        return false
  9769.    }
  9770.  
  9771.    function Start() {
  9772.        bot.hawkEye.autoAttack(target)
  9773.    }
  9774.  
  9775.    bot.on('entityHurt', (entity) => {
  9776.        if (entity.type === 'mob') {
  9777.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  9778.        } else if (entity.type === 'player') {
  9779.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  9780.        }
  9781.    })
  9782.  
  9783.    bot.on('entitySwingArm', (entity) => {
  9784.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  9785.    })
  9786.  
  9787.    bot.on('entityCrouch', (entity) => {
  9788.        bot.chat(`${entity.username}: you so sneaky.`)
  9789.    })
  9790.  
  9791.    bot.on('entityUncrouch', (entity) => {
  9792.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  9793.    })
  9794.  
  9795.    bot.on('entitySleep', (entity) => {
  9796.        bot.chat(`Good night, ${entity.username}`)
  9797.    })
  9798.  
  9799.    bot.on('entityWake', (entity) => {
  9800.        bot.chat(`Top of the morning, ${entity.username}`)
  9801.    })
  9802.  
  9803.    bot.on('entityEat', (entity) => {
  9804.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  9805.    })
  9806.  
  9807.    bot.on('entityAttach', (entity, vehicle) => {
  9808.        if (entity.type === 'player' && vehicle.type === 'object') {
  9809.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  9810.        }
  9811.    })
  9812.  
  9813.    bot.on('entityDetach', (entity, vehicle) => {
  9814.        if (entity.type === 'player' && vehicle.type === 'object') {
  9815.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  9816.        }
  9817.    })
  9818.  
  9819.    bot.on('entityEquipmentChange', (entity) => {
  9820.        console.log('entityEquipmentChange', entity)
  9821.    })
  9822.  
  9823.    bot.on('entityEffect', (entity, effect) => {
  9824.        console.log('entityEffect', entity, effect)
  9825.    })
  9826.  
  9827.    bot.on('entityEffectEnd', (entity, effect) => {
  9828.        console.log('entityEffectEnd', entity, effect)
  9829.    })
  9830.  
  9831.    function guardArea(pos) {
  9832.        guardPos = pos.clone()
  9833.        
  9834.        if (!bot.pvp.target) {
  9835.            moveToGuardPos()
  9836.        }
  9837.    }
  9838.    
  9839.    function stopGuarding() {
  9840.        guardPos = null
  9841.        bot.pvp.stop()
  9842.        bot.pathfinder.setGoal(null)
  9843.    }
  9844.    
  9845.    function moveToGuardPos() {
  9846.        const mcData = require('minecraft-data')(bot.version)
  9847.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  9848.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  9849.    }
  9850.    
  9851.    bot.on('stoppedAttacking', () => {
  9852.        if (guardPos) {
  9853.            moveToGuardPos()
  9854.        }
  9855.    })
  9856.    
  9857.    bot.on('physicTick', () => {
  9858.        if (bot.pvp.target) return
  9859.        if (bot.pathfinder.isMoving()) return
  9860.        
  9861.        const entity = bot.nearestEntity()
  9862.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  9863.    })
  9864.    
  9865.    bot.on('physicTick', () => {
  9866.        if (!guardPos) return
  9867.        
  9868.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  9869.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  9870.        
  9871.        const entity = bot.nearestEntity(filter)
  9872.        if (entity) {
  9873.            bot.pvp.attack(entity)
  9874.        }
  9875.    })
  9876.    /*
  9877.    bot.on('chat', (username, message) => {
  9878.        if (username === bot.username) return
  9879.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  9880.        if (result) {
  9881.            canSee(new Vec3(result[1], result[2], result[3]))
  9882.            return
  9883.        }
  9884.        switch (message) {
  9885.            case 'pos':
  9886.                console.log("pos command used")
  9887.                sayPosition(username)
  9888.                break
  9889.            case 'wearing':
  9890.                console.log("wearing command used")
  9891.                sayEquipment()
  9892.                break
  9893.            case 'nick':
  9894.                console.log("saynick command used")
  9895.                sayNick()
  9896.                break
  9897.            case 'spawn':
  9898.                console.log("spawn command used")
  9899.                saySpawnPoint()
  9900.                break
  9901.            case 'block':
  9902.                console.log("block command used")
  9903.                sayBlockUnder(username)
  9904.                break
  9905.            default:
  9906.                console.log("I am ready!")
  9907.                bot.chat("I am ready!")
  9908.    }
  9909.    */
  9910.  
  9911.    // text of bots username and help will give a list of bot commands
  9912.    bot.on('chat', (username, message) => { // work in progress....
  9913.        if (message === `${bot.player.displayName} help`)
  9914.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  9915.            bot.chat('pos, wearing, nick, spawn, block ')
  9916.            bot.chat('arch-start, Version.(wip not all commands work...)')
  9917.            bot.chat('Bot may just leave if it errors out.')
  9918.    })
  9919.  
  9920.    bot.on('chat', (username, message) => { // work in progress....
  9921.        if (message === 'Version') {
  9922.            console.log("Version command used just used")
  9923.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  9924.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  9925.            console.log("sayVersion command used")
  9926.            sayVersion(username)
  9927.            return
  9928.        }
  9929.    })
  9930.  
  9931.    bot.on('chat', (username, message) => {
  9932.        if (message === 'leave') {
  9933.                console.log("leave command used")
  9934.                bot.chat("Yes sir right away!")
  9935.                bot.quit(username)
  9936.                return
  9937.        }
  9938.    })
  9939.  
  9940.    bot.on('chat', (username, message) => {
  9941.        if (message === 'arch-start') {
  9942.            console.log("arch-start command used")
  9943.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  9944.            Start()
  9945.            return
  9946.        }
  9947.    })
  9948.  
  9949.    bot.on('chat', (username, message) => {
  9950.        if (message === 'guard') {          // if message guard do gaurd
  9951.            const player = bot.players[username]
  9952.  
  9953.            if (!player) {
  9954.                bot.chat("I can't see you.")
  9955.                return
  9956.            }
  9957.        bot.chat('I will guard that location.')
  9958.            guardArea(player.entity.position)
  9959.            }
  9960.  
  9961.            if (message === 'fight me') {
  9962.                const player = bot.players[username]
  9963.  
  9964.                if (!player) {
  9965.                    bot.chat("I can't see you.")
  9966.                    return
  9967.                }
  9968.  
  9969.            bot.chat('Prepare to fight!')
  9970.            bot.chat('5')
  9971.            bot.chat('4')
  9972.            bot.chat('3')
  9973.            bot.chat('2')
  9974.            bot.chat('1')
  9975.            bot.chat('GO!!!')
  9976.            bot.pvp.attack(player.entity)
  9977.            }
  9978.  
  9979.            if (message === 'stop') {
  9980.                bot.chat('I will stop!')
  9981.                bot.hawkEye.stop()
  9982.                stopGuarding()
  9983.            }
  9984.    })
  9985.  
  9986.    function not_busy() {
  9987.        guardPos = pos.clone()
  9988.  
  9989.        if (guardPos == null) {
  9990.            return false
  9991.        
  9992.        } else { (guardPos == !null)
  9993.                return true
  9994.            }
  9995.        }
  9996.    
  9997.    
  9998.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  9999.        if (busy == true) {
  10000.        console.log("I am busy!")
  10001.        bot.chat("I am busy!")
  10002.            } else { if (busy == false)
  10003.            console.log('I am ready!')
  10004.            bot.chat('I am ready!')
  10005.            }
  10006.    
  10007.    })
  10008.  
  10009.    bot.on('sleep', () => {
  10010.        bot.chat('Good night!')
  10011.    })
  10012.  
  10013.    bot.on('wake', () => {
  10014.        bot.chat('Good morning!')
  10015.    })
  10016.  
  10017.    function goToSleep() {
  10018.        const bed = bot.findBlock({
  10019.            matching: block => bot.isABed(block)
  10020.        })
  10021.        if (bed) {
  10022.            bot.sleep(bed, (err) => {
  10023.                if (err) {
  10024.                    bot.chat(`I can't sleep: ${err.message}`)
  10025.                } else {
  10026.                    bot.chat("I'm sleeping")
  10027.                }
  10028.            })
  10029.        } else {
  10030.            bot.chat('No nearby bed')
  10031.        }
  10032.    }
  10033.  
  10034.    function wakeUp() {
  10035.        bot.wake((err) => {
  10036.            if (err) {
  10037.                bot.chat(`I can't wake up: ${err.message}`)
  10038.             } else {
  10039.                 bot.chat('I woke up')
  10040.             }
  10041.         }
  10042.        
  10043.     )
  10044. }
  10045. // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
  10046. const Vec3 = require('vec3').Vec3
  10047. const fs = require('fs')
  10048. const { version } = require('os')
  10049. const pvp = require('mineflayer-pvp').plugin
  10050. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  10051. const armorManager = require('mineflayer-armor-manager')
  10052. const autoeat = require('mineflayer-auto-eat')
  10053. const minecraftHawkEye = require('minecrafthawkeye')
  10054.  
  10055. function jsonReader(filePath, cb) {
  10056.     fs.readFile(filePath, (err, fileData) => {
  10057.         if (err) {
  10058.             return cb && cb(err)
  10059.         }
  10060.         try {
  10061.             const object = JSON.parse(fileData)
  10062.             return cb && cb(null, object)
  10063.         } catch (err) {
  10064.             return cb && cb(err)
  10065.         }
  10066.     })
  10067. }
  10068.  
  10069. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  10070.     if (err) {
  10071.         console.log(err)
  10072.         return
  10073.     }
  10074.  
  10075.     const bot = mineflayer.createBot({
  10076.         version: mc_login_info.version,
  10077.         host: mc_login_info.host,
  10078.         port: mc_login_info.port,
  10079.         username: mc_login_info.username,
  10080.         password: mc_login_info.password,
  10081.         // give time for communication to hosts&client with longer ping times
  10082.         checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  10083.         logErrors: true
  10084.     })
  10085. })
  10086.  
  10087.     bot._client.on('custom_payload', (packet) => {
  10088.         // console.log(packet)
  10089.         if (packet.channel === "minecraft:brand") {
  10090.             let data = packet.data
  10091.             let brand = String.fromCharCode.apply(null, data)
  10092.             console.log(brand)
  10093.         }
  10094.     })
  10095.  
  10096.     bot.once('login', () => {
  10097.         console.log('logged in')
  10098.         console.log(`curent client version ${bot.version}`)
  10099.         // console.log(`curent server version is ${server.version}`)
  10100.     })
  10101.  
  10102.     bot.loadPlugin(autoeat)
  10103.     bot.loadPlugin(armorManager)
  10104.     bot.loadPlugin(minecraftHawkEye)
  10105.     bot.loadPlugin(pathfinder)
  10106.     bot.loadPlugin(pvp)
  10107.  
  10108.    
  10109.     bot.on('playerCollect', (collector, itemDrop) => {
  10110.         if (collector !== bot.entity) return
  10111.        
  10112.         setTimeout(() => {
  10113.             const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  10114.             if (sword) bot.equip(sword, 'hand')
  10115.         }, 150)
  10116.     })
  10117.    
  10118.     bot.on('playerCollect', (collector, itemDrop) => {
  10119.         if (collector !== bot.entity) return
  10120.        
  10121.         setTimeout(() => {
  10122.             const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  10123.             if (shield) bot.equip(shield, 'off-hand')
  10124.         }, 250)
  10125.     })
  10126.    
  10127.     let guardPos = null
  10128.     let busy = false
  10129.  
  10130.     bot.on('spawn', () => { // gives error when bot spawns
  10131.         console.log('spawned in server')
  10132.         bot.hawkEye.stop()
  10133.         stopGuarding()
  10134.         bot.chat('I spawned, watch out!')
  10135.     })
  10136.    
  10137.     function canSee(pos) {
  10138.         const block = bot.blockAt(pos)
  10139.         const r = bot.canSeeBlock(block)
  10140.         if (r) {
  10141.             bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  10142.         } else {
  10143.             bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  10144.         }
  10145.     }
  10146.    
  10147.     function sayPosition(username) {
  10148.         //bot.chat(`My puplic position is disabled`)
  10149.         bot.chat(`I am at ${bot.entity.position}`)
  10150.         //bot.chat(`You are at ${bot.players[username].entity.position}`)
  10151.         //bot.chat(`I don't know your position.`)
  10152.        bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  10153.    }
  10154.  
  10155.    function sayEquipment() {
  10156.        const eq = bot.players[username].entity.equipment
  10157.        const eqText = []
  10158.        if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  10159.        if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  10160.        if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  10161.        if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  10162.        if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  10163.        if (eqText.length) {
  10164.            bot.chat(`You are ${eqText.join(', ')}.`)
  10165.        } else {
  10166.            bot.chat('You are without armor!')
  10167.        }
  10168.    }
  10169.  
  10170.    function sayVersion() { // work in prograss not working yet
  10171.        bot.chat('/version')
  10172.        console.log(`${command.message} confermed ${brand}`)
  10173.    }
  10174.  
  10175.    function saySpawnPoint() {
  10176.        bot.chat(`Spawn is at ${bot.spawnPoint}`)
  10177.    }
  10178.  
  10179.    function sayBlockUnder() {
  10180.        const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  10181.        bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  10182.        console.log(block)
  10183.    }
  10184.  
  10185.    function quit(username) {
  10186.        console.log('quit command used')
  10187.        bot.quit(`${username} told me too`)
  10188.    }
  10189.  
  10190.    function sayNick() {
  10191.        bot.chat(`My name is ${bot.player.displayName}`)
  10192.    }
  10193.    
  10194.    // begin of autoeats paste
  10195.    bot.once('spawn', () => {
  10196.        bot.autoEat.options = {
  10197.            priority: 'foodPoints',
  10198.            startAt: 14,
  10199.            bannedFood: []
  10200.        }
  10201.    })
  10202.    // The bot eats food automatically and emits these events when it starts eating and stops eating.
  10203.    bot.on('autoeat_started', () => {
  10204.        console.log('Auto Eat started!')
  10205.    })
  10206.  
  10207.    bot.on('autoeat_stopped', () => {
  10208.        console.log('Auto Eat stopped!')
  10209.    })
  10210.  
  10211.    bot.on('health', () => {
  10212.        if (bot.food === 20) bot.autoEat.disable()
  10213.        // Disable the plugin if the bot is at 20 food points
  10214.        else bot.autoEat.enable() // Else enable the plugin again
  10215.    })
  10216.    // end of paste autoeat
  10217.  
  10218.    bot.on('whisper', (username, message, rawMessage) => {
  10219.        console.log(`I received a message from ${username}: ${message}`)
  10220.        bot.whisper(username, 'I can tell secrets too.')
  10221.    })
  10222.  
  10223.    bot.on('nonSpokenChat', (message) => {
  10224.        console.log(`Non spoken chat: ${message}`)
  10225.    })
  10226.    
  10227.    bot.on('login', () => {
  10228.        bot.chat('Hi everyone!')
  10229.    })
  10230.    
  10231.    bot.on('spawnReset', (message) => {
  10232.        console.log('spawnReset command used')
  10233.        stopGuarding()
  10234.        bot.hawkEye.stop()
  10235.        bot.chat('Oh noez! My bed is broken.')
  10236.    })
  10237.    
  10238.    bot.on('forcedMove', () => {
  10239.        console.log(`I have been forced to move to ${bot.entity.position}`)
  10240.        bot.chat(`I have been forced to move to ${bot.entity.position}`)
  10241.    })
  10242.    
  10243.    bot.on('health', () => {
  10244.        console.log(`I have ${bot.health} health and ${bot.food} food`)
  10245.        bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  10246.    })
  10247.  
  10248.    bot.on('death', () => {
  10249.        console.log('I died, stopping and respawning')
  10250.        stopGuarding()
  10251.        bot.hawkEye.stop()
  10252.        bot.respawn
  10253.        bot.chat('I died x.x ugh!!')
  10254.        // need instructions to return to
  10255.        // what i was doing.
  10256.    })
  10257.  
  10258.    bot.on('kicked', (reason) => {
  10259.        console.log(`I got kicked for ${reason}`)
  10260.    })
  10261.    
  10262.    bot.on('rain', () => {
  10263.        if (bot.isRaining) {
  10264.            console.log('It started raining.')
  10265.            //bot.chat('It started raining.')
  10266.        } else {
  10267.            console.log('It stopped raining.')
  10268.            //bot.chat('It stopped raining.')
  10269.        }
  10270.    })
  10271.  
  10272.    bot.on('noteHeard', (block, instrument, pitch) => {
  10273.        bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  10274.    })
  10275.  
  10276.    bot.on('chestLidMove', (block, isOpen) => {
  10277.        const action = isOpen ? 'open' : 'close'
  10278.        bot.chat(`Hey, did someone just ${action} a chest?`)
  10279.    })
  10280.  
  10281.    bot.on('pistonMove', (block, isPulling, direction) => {
  10282.        const action = isPulling ? 'pulling' : 'pushing'
  10283.        bot.chat(`A piston is ${action} near me, i can hear it.`)
  10284.    })
  10285.  
  10286.    bot.on('playerJoined', (player) => {
  10287.        if (player.username !== bot.username) {
  10288.            console.log(`${player.username}! Joined the server.`)
  10289.            //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  10290.        }
  10291.    })
  10292.  
  10293.    bot.on('playerLeft', (player) => {
  10294.        if (player.username === bot.username) return
  10295.        console.log(`${player.username} left the server`)
  10296.        // bot.chat(`Bye ${player.username}`)
  10297.    })
  10298.    /*
  10299.    bot.on('playerCollect', (collector, collected) => {
  10300.        if (collector.type === 'player' && collected.type === 'object') {
  10301.            const rawItem = collected.metadata[10]
  10302.            const item = mineflayer.Item.fromNotch(rawItem)
  10303.            bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  10304.        }
  10305.    })
  10306.    */
  10307.    /*    
  10308.    bot.on('entitySpawn', (entity) => {
  10309.        if (entity.type === 'mob') {
  10310.            console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  10311.        } else if (entity.type === 'player') {
  10312.            console.log(`Look who decided to show up: ${entity.username}`)
  10313.        } else if (entity.type === 'object') {
  10314.            console.log(`There's a ${entity.objectType} at ${entity.position}`)
  10315.        } else if (entity.type === 'global') {
  10316.            console.log('Ooh lightning!')
  10317.        } else if (entity.type === 'orb') {
  10318.            console.log('Gimme dat exp orb!')
  10319.        }
  10320.    })
  10321.    */    
  10322.  
  10323.    const target = bot.hawkEye.getPlayer()
  10324.    console.log(target)
  10325.    if (!target) {
  10326.        return false
  10327.    }
  10328.  
  10329.    function Start() {
  10330.        bot.hawkEye.autoAttack(target)
  10331.    }
  10332.  
  10333.    bot.on('entityHurt', (entity) => {
  10334.        if (entity.type === 'mob') {
  10335.            bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  10336.        } else if (entity.type === 'player') {
  10337.            bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  10338.        }
  10339.    })
  10340.  
  10341.    bot.on('entitySwingArm', (entity) => {
  10342.        bot.chat(`${entity.username}, I see that your arm is working fine.`)
  10343.    })
  10344.  
  10345.    bot.on('entityCrouch', (entity) => {
  10346.        bot.chat(`${entity.username}: you so sneaky.`)
  10347.    })
  10348.  
  10349.    bot.on('entityUncrouch', (entity) => {
  10350.        bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  10351.    })
  10352.  
  10353.    bot.on('entitySleep', (entity) => {
  10354.        bot.chat(`Good night, ${entity.username}`)
  10355.    })
  10356.  
  10357.    bot.on('entityWake', (entity) => {
  10358.        bot.chat(`Top of the morning, ${entity.username}`)
  10359.    })
  10360.  
  10361.    bot.on('entityEat', (entity) => {
  10362.        bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  10363.    })
  10364.  
  10365.    bot.on('entityAttach', (entity, vehicle) => {
  10366.        if (entity.type === 'player' && vehicle.type === 'object') {
  10367.            bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  10368.        }
  10369.    })
  10370.  
  10371.    bot.on('entityDetach', (entity, vehicle) => {
  10372.        if (entity.type === 'player' && vehicle.type === 'object') {
  10373.            bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  10374.        }
  10375.    })
  10376.  
  10377.    bot.on('entityEquipmentChange', (entity) => {
  10378.        console.log('entityEquipmentChange', entity)
  10379.    })
  10380.  
  10381.    bot.on('entityEffect', (entity, effect) => {
  10382.        console.log('entityEffect', entity, effect)
  10383.    })
  10384.  
  10385.    bot.on('entityEffectEnd', (entity, effect) => {
  10386.        console.log('entityEffectEnd', entity, effect)
  10387.    })
  10388.  
  10389.    function guardArea(pos) {
  10390.        guardPos = pos.clone()
  10391.        
  10392.        if (!bot.pvp.target) {
  10393.            moveToGuardPos()
  10394.        }
  10395.    }
  10396.    
  10397.    function stopGuarding() {
  10398.        guardPos = null
  10399.        bot.pvp.stop()
  10400.        bot.pathfinder.setGoal(null)
  10401.    }
  10402.    
  10403.    function moveToGuardPos() {
  10404.        const mcData = require('minecraft-data')(bot.version)
  10405.        bot.pathfinder.setMovements(new Movements(bot, mcData))
  10406.        bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  10407.    }
  10408.    
  10409.    bot.on('stoppedAttacking', () => {
  10410.        if (guardPos) {
  10411.            moveToGuardPos()
  10412.        }
  10413.    })
  10414.    
  10415.    bot.on('physicTick', () => {
  10416.        if (bot.pvp.target) return
  10417.        if (bot.pathfinder.isMoving()) return
  10418.        
  10419.        const entity = bot.nearestEntity()
  10420.        if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  10421.    })
  10422.    
  10423.    bot.on('physicTick', () => {
  10424.        if (!guardPos) return
  10425.        
  10426.        const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  10427.        e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  10428.        
  10429.        const entity = bot.nearestEntity(filter)
  10430.        if (entity) {
  10431.            bot.pvp.attack(entity)
  10432.        }
  10433.    })
  10434.    /*
  10435.    bot.on('chat', (username, message) => {
  10436.        if (username === bot.username) return
  10437.        const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  10438.        if (result) {
  10439.            canSee(new Vec3(result[1], result[2], result[3]))
  10440.            return
  10441.        }
  10442.        switch (message) {
  10443.            case 'pos':
  10444.                console.log("pos command used")
  10445.                sayPosition(username)
  10446.                break
  10447.            case 'wearing':
  10448.                console.log("wearing command used")
  10449.                sayEquipment()
  10450.                break
  10451.            case 'nick':
  10452.                console.log("saynick command used")
  10453.                sayNick()
  10454.                break
  10455.            case 'spawn':
  10456.                console.log("spawn command used")
  10457.                saySpawnPoint()
  10458.                break
  10459.            case 'block':
  10460.                console.log("block command used")
  10461.                sayBlockUnder(username)
  10462.                break
  10463.            default:
  10464.                console.log("I am ready!")
  10465.                bot.chat("I am ready!")
  10466.    }
  10467.    */
  10468.  
  10469.    // text of bots username and help will give a list of bot commands
  10470.    bot.on('chat', (username, message) => { // work in progress....
  10471.        if (message === `${bot.player.displayName} help`)
  10472.            bot.chat('command reminders are:  stop, leave, fight me, guard, ')
  10473.            bot.chat('pos, wearing, nick, spawn, block ')
  10474.            bot.chat('arch-start, Version.(wip not all commands work...)')
  10475.            bot.chat('Bot may just leave if it errors out.')
  10476.    })
  10477.  
  10478.    bot.on('chat', (username, message) => { // work in progress....
  10479.        if (message === 'Version') {
  10480.            console.log("Version command used just used")
  10481.            console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  10482.            bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  10483.            console.log("sayVersion command used")
  10484.            sayVersion(username)
  10485.            return
  10486.        }
  10487.    })
  10488.  
  10489.    bot.on('chat', (username, message) => {
  10490.        if (message === 'leave') {
  10491.                console.log("leave command used")
  10492.                bot.chat("Yes sir right away!")
  10493.                bot.quit(username)
  10494.                return
  10495.        }
  10496.    })
  10497.  
  10498.    bot.on('chat', (username, message) => {
  10499.        if (message === 'arch-start') {
  10500.            console.log("arch-start command used")
  10501.            bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  10502.            Start()
  10503.            return
  10504.        }
  10505.    })
  10506.  
  10507.    bot.on('chat', (username, message) => {
  10508.        if (message === 'guard') {          // if message guard do gaurd
  10509.            const player = bot.players[username]
  10510.  
  10511.            if (!player) {
  10512.                bot.chat("I can't see you.")
  10513.                return
  10514.            }
  10515.        bot.chat('I will guard that location.')
  10516.            guardArea(player.entity.position)
  10517.            }
  10518.  
  10519.            if (message === 'fight me') {
  10520.                const player = bot.players[username]
  10521.  
  10522.                if (!player) {
  10523.                    bot.chat("I can't see you.")
  10524.                    return
  10525.                }
  10526.  
  10527.            bot.chat('Prepare to fight!')
  10528.            bot.chat('5')
  10529.            bot.chat('4')
  10530.            bot.chat('3')
  10531.            bot.chat('2')
  10532.            bot.chat('1')
  10533.            bot.chat('GO!!!')
  10534.            bot.pvp.attack(player.entity)
  10535.            }
  10536.  
  10537.            if (message === 'stop') {
  10538.                bot.chat('I will stop!')
  10539.                bot.hawkEye.stop()
  10540.                stopGuarding()
  10541.            }
  10542.    })
  10543.  
  10544.    function not_busy() {
  10545.        guardPos = pos.clone()
  10546.  
  10547.        if (guardPos == null) {
  10548.            return false
  10549.        
  10550.        } else { (guardPos == !null)
  10551.                return true
  10552.            }
  10553.        }
  10554.    
  10555.    
  10556.    bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  10557.        if (busy == true) {
  10558.        console.log("I am busy!")
  10559.        bot.chat("I am busy!")
  10560.            } else { if (busy == false)
  10561.            console.log('I am ready!')
  10562.            bot.chat('I am ready!')
  10563.            }
  10564.    
  10565.    })
  10566.  
  10567.    bot.on('sleep', () => {
  10568.        bot.chat('Good night!')
  10569.    })
  10570.  
  10571.    bot.on('wake', () => {
  10572.        bot.chat('Good morning!')
  10573.    })
  10574.  
  10575.    function goToSleep() {
  10576.        const bed = bot.findBlock({
  10577.            matching: block => bot.isABed(block)
  10578.        })
  10579.        if (bed) {
  10580.            bot.sleep(bed, (err) => {
  10581.                if (err) {
  10582.                    bot.chat(`I can't sleep: ${err.message}`)
  10583.                } else {
  10584.                    bot.chat("I'm sleeping")
  10585.                }
  10586.            })
  10587.        } else {
  10588.            bot.chat('No nearby bed')
  10589.        }
  10590.    }
  10591.  
  10592.    function wakeUp() {
  10593.        bot.wake((err) => {
  10594.            if (err) {
  10595.                bot.chat(`I can't wake up: ${err.message}`)
  10596.             } else {
  10597.                 bot.chat('I woke up')
  10598.             }
  10599.         }
  10600.        
  10601.     )
  10602. }
  10603. // syntax, syntax, syntax ???
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement