Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???const mineflayer = require('mineflayer', 'minecraft-protocol')
- const Vec3 = require('vec3').Vec3
- const fs = require('fs')
- const { version } = require('os')
- const pvp = require('mineflayer-pvp').plugin
- const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
- const armorManager = require('mineflayer-armor-manager')
- const autoeat = require('mineflayer-auto-eat')
- const minecraftHawkEye = require('minecrafthawkeye')
- function jsonReader(filePath, cb) {
- fs.readFile(filePath, (err, fileData) => {
- if (err) {
- return cb && cb(err)
- }
- try {
- const object = JSON.parse(fileData)
- return cb && cb(null, object)
- } catch (err) {
- return cb && cb(err)
- }
- })
- }
- jsonReader('./mc_login_info.json', (err, mc_login_info) => {
- if (err) {
- console.log(err)
- return
- }
- const bot = mineflayer.createBot({
- version: mc_login_info.version,
- host: mc_login_info.host,
- port: mc_login_info.port,
- username: mc_login_info.username,
- password: mc_login_info.password,
- // give time for communication to hosts&client with longer ping times
- checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
- logErrors: true
- })
- })
- bot._client.on('custom_payload', (packet) => {
- // console.log(packet)
- if (packet.channel === "minecraft:brand") {
- let data = packet.data
- let brand = String.fromCharCode.apply(null, data)
- console.log(brand)
- }
- })
- bot.once('login', () => {
- console.log('logged in')
- console.log(`curent client version ${bot.version}`)
- // console.log(`curent server version is ${server.version}`)
- })
- bot.loadPlugin(autoeat)
- bot.loadPlugin(armorManager)
- bot.loadPlugin(minecraftHawkEye)
- bot.loadPlugin(pathfinder)
- bot.loadPlugin(pvp)
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const sword = bot.inventory.items().find(item => item.name.includes('sword'))
- if (sword) bot.equip(sword, 'hand')
- }, 150)
- })
- bot.on('playerCollect', (collector, itemDrop) => {
- if (collector !== bot.entity) return
- setTimeout(() => {
- const shield = bot.inventory.items().find(item => item.name.includes('shield'))
- if (shield) bot.equip(shield, 'off-hand')
- }, 250)
- })
- let guardPos = null
- let busy = false
- bot.on('spawn', () => { // gives error when bot spawns
- console.log('spawned in server')
- bot.hawkEye.stop()
- stopGuarding()
- bot.chat('I spawned, watch out!')
- })
- function canSee(pos) {
- const block = bot.blockAt(pos)
- const r = bot.canSeeBlock(block)
- if (r) {
- bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
- } else {
- bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
- }
- }
- function sayPosition(username) {
- //bot.chat(`My puplic position is disabled`)
- bot.chat(`I am at ${bot.entity.position}`)
- //bot.chat(`You are at ${bot.players[username].entity.position}`)
- //bot.chat(`I don't know your position.`)
- bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
- }
- function sayEquipment() {
- const eq = bot.players[username].entity.equipment
- const eqText = []
- if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
- if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
- if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
- if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
- if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
- if (eqText.length) {
- bot.chat(`You are ${eqText.join(', ')}.`)
- } else {
- bot.chat('You are without armor!')
- }
- }
- function sayVersion() { // work in prograss not working yet
- bot.chat('/version')
- console.log(`${command.message} confermed ${brand}`)
- }
- function saySpawnPoint() {
- bot.chat(`Spawn is at ${bot.spawnPoint}`)
- }
- function sayBlockUnder() {
- const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
- bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
- console.log(block)
- }
- function quit(username) {
- console.log('quit command used')
- bot.quit(`${username} told me too`)
- }
- function sayNick() {
- bot.chat(`My name is ${bot.player.displayName}`)
- }
- // begin of autoeats paste
- bot.once('spawn', () => {
- bot.autoEat.options = {
- priority: 'foodPoints',
- startAt: 14,
- bannedFood: []
- }
- })
- // The bot eats food automatically and emits these events when it starts eating and stops eating.
- bot.on('autoeat_started', () => {
- console.log('Auto Eat started!')
- })
- bot.on('autoeat_stopped', () => {
- console.log('Auto Eat stopped!')
- })
- bot.on('health', () => {
- if (bot.food === 20) bot.autoEat.disable()
- // Disable the plugin if the bot is at 20 food points
- else bot.autoEat.enable() // Else enable the plugin again
- })
- // end of paste autoeat
- bot.on('whisper', (username, message, rawMessage) => {
- console.log(`I received a message from ${username}: ${message}`)
- bot.whisper(username, 'I can tell secrets too.')
- })
- bot.on('nonSpokenChat', (message) => {
- console.log(`Non spoken chat: ${message}`)
- })
- bot.on('login', () => {
- bot.chat('Hi everyone!')
- })
- bot.on('spawnReset', (message) => {
- console.log('spawnReset command used')
- stopGuarding()
- bot.hawkEye.stop()
- bot.chat('Oh noez! My bed is broken.')
- })
- bot.on('forcedMove', () => {
- console.log(`I have been forced to move to ${bot.entity.position}`)
- bot.chat(`I have been forced to move to ${bot.entity.position}`)
- })
- bot.on('health', () => {
- console.log(`I have ${bot.health} health and ${bot.food} food`)
- bot.chat(`I have ${bot.health} health and ${bot.food} food`)
- })
- bot.on('death', () => {
- console.log('I died, stopping and respawning')
- stopGuarding()
- bot.hawkEye.stop()
- bot.respawn
- bot.chat('I died x.x ugh!!')
- // need instructions to return to
- // what i was doing.
- })
- bot.on('kicked', (reason) => {
- console.log(`I got kicked for ${reason}`)
- })
- bot.on('rain', () => {
- if (bot.isRaining) {
- console.log('It started raining.')
- //bot.chat('It started raining.')
- } else {
- console.log('It stopped raining.')
- //bot.chat('It stopped raining.')
- }
- })
- bot.on('noteHeard', (block, instrument, pitch) => {
- bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
- })
- bot.on('chestLidMove', (block, isOpen) => {
- const action = isOpen ? 'open' : 'close'
- bot.chat(`Hey, did someone just ${action} a chest?`)
- })
- bot.on('pistonMove', (block, isPulling, direction) => {
- const action = isPulling ? 'pulling' : 'pushing'
- bot.chat(`A piston is ${action} near me, i can hear it.`)
- })
- bot.on('playerJoined', (player) => {
- if (player.username !== bot.username) {
- console.log(`${player.username}! Joined the server.`)
- //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
- }
- })
- bot.on('playerLeft', (player) => {
- if (player.username === bot.username) return
- console.log(`${player.username} left the server`)
- // bot.chat(`Bye ${player.username}`)
- })
- /*
- bot.on('playerCollect', (collector, collected) => {
- if (collector.type === 'player' && collected.type === 'object') {
- const rawItem = collected.metadata[10]
- const item = mineflayer.Item.fromNotch(rawItem)
- bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
- }
- })
- */
- /*
- bot.on('entitySpawn', (entity) => {
- if (entity.type === 'mob') {
- console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
- } else if (entity.type === 'player') {
- console.log(`Look who decided to show up: ${entity.username}`)
- } else if (entity.type === 'object') {
- console.log(`There's a ${entity.objectType} at ${entity.position}`)
- } else if (entity.type === 'global') {
- console.log('Ooh lightning!')
- } else if (entity.type === 'orb') {
- console.log('Gimme dat exp orb!')
- }
- })
- */
- const target = bot.hawkEye.getPlayer()
- console.log(target)
- if (!target) {
- return false
- }
- function Start() {
- bot.hawkEye.autoAttack(target)
- }
- bot.on('entityHurt', (entity) => {
- if (entity.type === 'mob') {
- bot.chat(`Haha! The ${entity.mobType} got hurt!`)
- } else if (entity.type === 'player') {
- bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
- }
- })
- bot.on('entitySwingArm', (entity) => {
- bot.chat(`${entity.username}, I see that your arm is working fine.`)
- })
- bot.on('entityCrouch', (entity) => {
- bot.chat(`${entity.username}: you so sneaky.`)
- })
- bot.on('entityUncrouch', (entity) => {
- bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
- })
- bot.on('entitySleep', (entity) => {
- bot.chat(`Good night, ${entity.username}`)
- })
- bot.on('entityWake', (entity) => {
- bot.chat(`Top of the morning, ${entity.username}`)
- })
- bot.on('entityEat', (entity) => {
- bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
- })
- bot.on('entityAttach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
- }
- })
- bot.on('entityDetach', (entity, vehicle) => {
- if (entity.type === 'player' && vehicle.type === 'object') {
- bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
- }
- })
- bot.on('entityEquipmentChange', (entity) => {
- console.log('entityEquipmentChange', entity)
- })
- bot.on('entityEffect', (entity, effect) => {
- console.log('entityEffect', entity, effect)
- })
- bot.on('entityEffectEnd', (entity, effect) => {
- console.log('entityEffectEnd', entity, effect)
- })
- function guardArea(pos) {
- guardPos = pos.clone()
- if (!bot.pvp.target) {
- moveToGuardPos()
- }
- }
- function stopGuarding() {
- guardPos = null
- bot.pvp.stop()
- bot.pathfinder.setGoal(null)
- }
- function moveToGuardPos() {
- const mcData = require('minecraft-data')(bot.version)
- bot.pathfinder.setMovements(new Movements(bot, mcData))
- bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
- }
- bot.on('stoppedAttacking', () => {
- if (guardPos) {
- moveToGuardPos()
- }
- })
- bot.on('physicTick', () => {
- if (bot.pvp.target) return
- if (bot.pathfinder.isMoving()) return
- const entity = bot.nearestEntity()
- if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
- })
- bot.on('physicTick', () => {
- if (!guardPos) return
- const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
- e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
- const entity = bot.nearestEntity(filter)
- if (entity) {
- bot.pvp.attack(entity)
- }
- })
- /*
- bot.on('chat', (username, message) => {
- if (username === bot.username) return
- const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
- if (result) {
- canSee(new Vec3(result[1], result[2], result[3]))
- return
- }
- switch (message) {
- case 'pos':
- console.log("pos command used")
- sayPosition(username)
- break
- case 'wearing':
- console.log("wearing command used")
- sayEquipment()
- break
- case 'nick':
- console.log("saynick command used")
- sayNick()
- break
- case 'spawn':
- console.log("spawn command used")
- saySpawnPoint()
- break
- case 'block':
- console.log("block command used")
- sayBlockUnder(username)
- break
- default:
- console.log("I am ready!")
- bot.chat("I am ready!")
- }
- */
- // text of bots username and help will give a list of bot commands
- bot.on('chat', (username, message) => { // work in progress....
- if (message === `${bot.player.displayName} help`)
- bot.chat('command reminders are: stop, leave, fight me, guard, ')
- bot.chat('pos, wearing, nick, spawn, block ')
- bot.chat('arch-start, Version.(wip not all commands work...)')
- bot.chat('Bot may just leave if it errors out.')
- })
- bot.on('chat', (username, message) => { // work in progress....
- if (message === 'Version') {
- console.log("Version command used just used")
- console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
- bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
- console.log("sayVersion command used")
- sayVersion(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'leave') {
- console.log("leave command used")
- bot.chat("Yes sir right away!")
- bot.quit(username)
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'arch-start') {
- console.log("arch-start command used")
- bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
- Start()
- return
- }
- })
- bot.on('chat', (username, message) => {
- if (message === 'guard') { // if message guard do gaurd
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('I will guard that location.')
- guardArea(player.entity.position)
- }
- if (message === 'fight me') {
- const player = bot.players[username]
- if (!player) {
- bot.chat("I can't see you.")
- return
- }
- bot.chat('Prepare to fight!')
- bot.chat('5')
- bot.chat('4')
- bot.chat('3')
- bot.chat('2')
- bot.chat('1')
- bot.chat('GO!!!')
- bot.pvp.attack(player.entity)
- }
- if (message === 'stop') {
- bot.chat('I will stop!')
- bot.hawkEye.stop()
- stopGuarding()
- }
- })
- function not_busy() {
- guardPos = pos.clone()
- if (guardPos == null) {
- return false
- } else { (guardPos == !null)
- return true
- }
- }
- bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
- if (busy == true) {
- console.log("I am busy!")
- bot.chat("I am busy!")
- } else { if (busy == false)
- console.log('I am ready!')
- bot.chat('I am ready!')
- }
- })
- bot.on('sleep', () => {
- bot.chat('Good night!')
- })
- bot.on('wake', () => {
- bot.chat('Good morning!')
- })
- function goToSleep() {
- const bed = bot.findBlock({
- matching: block => bot.isABed(block)
- })
- if (bed) {
- bot.sleep(bed, (err) => {
- if (err) {
- bot.chat(`I can't sleep: ${err.message}`)
- } else {
- bot.chat("I'm sleeping")
- }
- })
- } else {
- bot.chat('No nearby bed')
- }
- }
- function wakeUp() {
- bot.wake((err) => {
- if (err) {
- bot.chat(`I can't wake up: ${err.message}`)
- } else {
- bot.chat('I woke up')
- }
- }
- )
- }
- // syntax, syntax, syntax ???
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement