Advertisement
acxl

code base version 1.3

Dec 11th, 2020
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.73 KB | None | 0 0
  1. 11.22.5;((
  2. $(document)
  3.  
  4.  
  5.  
  6. ;((
  7.  
  8.  
  9.  
  10.  
  11.  
  12. 22.4
  13.  
  14.  
  15.  
  16. const mineflayer = require('mineflayer', 'minecraft-protocol')
  17. const Vec3 = require('vec3').Vec3
  18. const fs = require('fs')
  19. const { version } = require('os')
  20. const pvp = require('mineflayer-pvp').plugin
  21. const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
  22. const armorManager = require('mineflayer-armor-manager')
  23. const autoeat = require('mineflayer-auto-eat')
  24. const minecraftHawkEye = require('minecrafthawkeye')
  25.  
  26. function jsonReader(filePath, cb) {
  27. fs.readFile(filePath, (err, fileData) => {
  28. if (err) {
  29. return cb && cb(err)
  30. }
  31. try {
  32. const object = JSON.parse(fileData)
  33. return cb && cb(null, object)
  34. } catch (err) {
  35. return cb && cb(err)
  36. }
  37. })
  38. }
  39.  
  40. jsonReader('./mc_login_info.json', (err, mc_login_info) => {
  41. if (err) {
  42. console.log(err)
  43. return
  44. }
  45.  
  46. const bot = mineflayer.createBot({
  47. version: mc_login_info.version,
  48. host: mc_login_info.host,
  49. port: mc_login_info.port,
  50. username: mc_login_info.username,
  51. password: mc_login_info.password,
  52. // give time for communication to hosts&client with longer ping times
  53. checkTimeoutInterval: 30 * 1000, // 30 * 1000 is equal to 30 seconds
  54. logErrors: true
  55. })
  56. })
  57.  
  58. bot._client.on('custom_payload', (packet) => {
  59. // console.log(packet)
  60. if (packet.channel === "minecraft:brand") {
  61. let data = packet.data
  62. let brand = String.fromCharCode.apply(null, data)
  63. console.log(brand)
  64. }
  65. })
  66.  
  67. bot.once('login', () => {
  68. console.log('logged in')
  69. console.log(`curent client version ${bot.version}`)
  70. // console.log(`curent server version is ${server.version}`)
  71. })
  72.  
  73. bot.loadPlugin(autoeat)
  74. bot.loadPlugin(armorManager)
  75. bot.loadPlugin(minecraftHawkEye)
  76. bot.loadPlugin(pathfinder)
  77. bot.loadPlugin(pvp)
  78.  
  79.  
  80. bot.on('playerCollect', (collector, itemDrop) => {
  81. if (collector !== bot.entity) return
  82.  
  83. setTimeout(() => {
  84. const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  85. if (sword) bot.equip(sword, 'hand')
  86. }, 150)
  87. })
  88.  
  89. bot.on('playerCollect', (collector, itemDrop) => {
  90. if (collector !== bot.entity) return
  91.  
  92. setTimeout(() => {
  93. const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  94. if (shield) bot.equip(shield, 'off-hand')
  95. }, 250)
  96. })
  97.  
  98. let guardPos = null
  99. let busy = false
  100.  
  101. bot.on('spawn', () => { // gives error when bot spawns
  102. console.log('spawned in server')
  103. bot.hawkEye.stop()
  104. stopGuarding()
  105. bot.chat('I spawned, watch out!')
  106. })
  107.  
  108. function canSee(pos) {
  109. const block = bot.blockAt(pos)
  110. const r = bot.canSeeBlock(block)
  111. if (r) {
  112. bot.chat(`I can see the block of ${block.displayName} at ${pos}`)
  113. } else {
  114. bot.chat(`I cannot see the block of ${block.displayName} at ${pos}`)
  115. }
  116. }
  117.  
  118. function sayPosition(username) {
  119. //bot.chat(`My puplic position is disabled`)
  120. bot.chat(`I am at ${bot.entity.position}`)
  121. //bot.chat(`You are at ${bot.players[username].entity.position}`)
  122. //bot.chat(`I don't know your position.`)
  123. bot.chat(`${username} is at ${bot.players[username].entity.position} from me.`)
  124. }
  125.  
  126. function sayEquipment() {
  127. const eq = bot.players[username].entity.equipment
  128. const eqText = []
  129. if (eq[0]) eqText.push(`holding a ${eq[0].displayName}`)
  130. if (eq[1]) eqText.push(`wearing a ${eq[1].displayName} on your feet`)
  131. if (eq[2]) eqText.push(`wearing a ${eq[2].displayName} on your legs`)
  132. if (eq[3]) eqText.push(`wearing a ${eq[3].displayName} on your torso`)
  133. if (eq[4]) eqText.push(`wearing a ${eq[4].displayName} on your head`)
  134. if (eqText.length) {
  135. bot.chat(`You are ${eqText.join(', ')}.`)
  136. } else {
  137. bot.chat('You are without armor!')
  138. }
  139. }
  140.  
  141. function sayVersion() { // work in prograss not working yet
  142. bot.chat('/version')
  143. console.log(`${command.message} confermed ${brand}`)
  144. }
  145.  
  146. function saySpawnPoint() {
  147. bot.chat(`Spawn is at ${bot.spawnPoint}`)
  148. }
  149.  
  150. function sayBlockUnder() {
  151. const block = bot.blockAt(bot.players[username].entity.position.offset(0, -1, 0))
  152. bot.chat(`Block under you is ${block.displayName} in the ${block.biome.name} biome`)
  153. console.log(block)
  154. }
  155.  
  156. function quit(username) {
  157. console.log('quit command used')
  158. bot.quit(`${username} told me too`)
  159. }
  160.  
  161. function sayNick() {
  162. bot.chat(`My name is ${bot.player.displayName}`)
  163. }
  164.  
  165. // begin of autoeats paste
  166. bot.once('spawn', () => {
  167. bot.autoEat.options = {
  168. priority: 'foodPoints',
  169. startAt: 14,
  170. bannedFood: []
  171. }
  172. })
  173. // The bot eats food automatically and emits these events when it starts eating and stops eating.
  174. bot.on('autoeat_started', () => {
  175. console.log('Auto Eat started!')
  176. })
  177.  
  178. bot.on('autoeat_stopped', () => {
  179. console.log('Auto Eat stopped!')
  180. })
  181.  
  182. bot.on('health', () => {
  183. if (bot.food === 20) bot.autoEat.disable()
  184. // Disable the plugin if the bot is at 20 food points
  185. else bot.autoEat.enable() // Else enable the plugin again
  186. })
  187. // end of paste autoeat
  188.  
  189. bot.on('whisper', (username, message, rawMessage) => {
  190. console.log(`I received a message from ${username}: ${message}`)
  191. bot.whisper(username, 'I can tell secrets too.')
  192. })
  193.  
  194. bot.on('nonSpokenChat', (message) => {
  195. console.log(`Non spoken chat: ${message}`)
  196. })
  197.  
  198. bot.on('login', () => {
  199. bot.chat('Hi everyone!')
  200. })
  201.  
  202. bot.on('spawnReset', (message) => {
  203. console.log('spawnReset command used')
  204. stopGuarding()
  205. bot.hawkEye.stop()
  206. bot.chat('Oh noez! My bed is broken.')
  207. })
  208.  
  209. bot.on('forcedMove', () => {
  210. console.log(`I have been forced to move to ${bot.entity.position}`)
  211. bot.chat(`I have been forced to move to ${bot.entity.position}`)
  212. })
  213.  
  214. bot.on('health', () => {
  215. console.log(`I have ${bot.health} health and ${bot.food} food`)
  216. bot.chat(`I have ${bot.health} health and ${bot.food} food`)
  217. })
  218.  
  219. bot.on('death', () => {
  220. console.log('I died, stopping and respawning')
  221. stopGuarding()
  222. bot.hawkEye.stop()
  223. bot.respawn
  224. bot.chat('I died x.x ugh!!')
  225. // need instructions to return to
  226. // what i was doing.
  227. })
  228.  
  229. bot.on('kicked', (reason) => {
  230. console.log(`I got kicked for ${reason}`)
  231. })
  232.  
  233. bot.on('rain', () => {
  234. if (bot.isRaining) {
  235. console.log('It started raining.')
  236. //bot.chat('It started raining.')
  237. } else {
  238. console.log('It stopped raining.')
  239. //bot.chat('It stopped raining.')
  240. }
  241. })
  242.  
  243. bot.on('noteHeard', (block, instrument, pitch) => {
  244. bot.chat(`Music for my ears! I just heard a ${instrument.name}`)
  245. })
  246.  
  247. bot.on('chestLidMove', (block, isOpen) => {
  248. const action = isOpen ? 'open' : 'close'
  249. bot.chat(`Hey, did someone just ${action} a chest?`)
  250. })
  251.  
  252. bot.on('pistonMove', (block, isPulling, direction) => {
  253. const action = isPulling ? 'pulling' : 'pushing'
  254. bot.chat(`A piston is ${action} near me, i can hear it.`)
  255. })
  256.  
  257. bot.on('playerJoined', (player) => {
  258. if (player.username !== bot.username) {
  259. console.log(`${player.username}! Joined the server.`)
  260. //bot.chat(`Hello, ${player.username}! Welcome to the server.`)
  261. }
  262. })
  263.  
  264. bot.on('playerLeft', (player) => {
  265. if (player.username === bot.username) return
  266. console.log(`${player.username} left the server`)
  267. // bot.chat(`Bye ${player.username}`)
  268. })
  269. /*
  270. bot.on('playerCollect', (collector, collected) => {
  271. if (collector.type === 'player' && collected.type === 'object') {
  272. const rawItem = collected.metadata[10]
  273. const item = mineflayer.Item.fromNotch(rawItem)
  274. bot.chat(`${collector.username !== bot.username ? ("I'm so jealous. " + collector.username) : 'I '} collected ${item.count} ${item.displayName}`)
  275. }
  276. })
  277. */
  278. /*
  279. bot.on('entitySpawn', (entity) => {
  280. if (entity.type === 'mob') {
  281. console.log(`Look out! A ${entity.mobType} spawned at ${entity.position}`)
  282. } else if (entity.type === 'player') {
  283. console.log(`Look who decided to show up: ${entity.username}`)
  284. } else if (entity.type === 'object') {
  285. console.log(`There's a ${entity.objectType} at ${entity.position}`)
  286. } else if (entity.type === 'global') {
  287. console.log('Ooh lightning!')
  288. } else if (entity.type === 'orb') {
  289. console.log('Gimme dat exp orb!')
  290. }
  291. })
  292. */
  293.  
  294. const target = bot.hawkEye.getPlayer()
  295. console.log(target)
  296. if (!target) {
  297. return false
  298. }
  299.  
  300. function Start() {
  301. bot.hawkEye.autoAttack(target)
  302. }
  303.  
  304. bot.on('entityHurt', (entity) => {
  305. if (entity.type === 'mob') {
  306. bot.chat(`Haha! The ${entity.mobType} got hurt!`)
  307. } else if (entity.type === 'player') {
  308. bot.chat(`Aww, poor ${entity.username} got hurt. Maybe you shouldn't have a ping of ${bot.players[entity.username].ping}`)
  309. }
  310. })
  311.  
  312. bot.on('entitySwingArm', (entity) => {
  313. bot.chat(`${entity.username}, I see that your arm is working fine.`)
  314. })
  315.  
  316. bot.on('entityCrouch', (entity) => {
  317. bot.chat(`${entity.username}: you so sneaky.`)
  318. })
  319.  
  320. bot.on('entityUncrouch', (entity) => {
  321. bot.chat(`${entity.username}: welcome back from the land of hunchbacks.`)
  322. })
  323.  
  324. bot.on('entitySleep', (entity) => {
  325. bot.chat(`Good night, ${entity.username}`)
  326. })
  327.  
  328. bot.on('entityWake', (entity) => {
  329. bot.chat(`Top of the morning, ${entity.username}`)
  330. })
  331.  
  332. bot.on('entityEat', (entity) => {
  333. bot.chat(`${entity.username}: OM NOM NOM NOMONOM. That's what you sound like.`)
  334. })
  335.  
  336. bot.on('entityAttach', (entity, vehicle) => {
  337. if (entity.type === 'player' && vehicle.type === 'object') {
  338. bot.chat(`Sweet, ${entity.username} is riding that ${vehicle.objectType}`)
  339. }
  340. })
  341.  
  342. bot.on('entityDetach', (entity, vehicle) => {
  343. if (entity.type === 'player' && vehicle.type === 'object') {
  344. bot.chat(`Lame, ${entity.username} stopped riding the ${vehicle.objectType}`)
  345. }
  346. })
  347.  
  348. bot.on('entityEquipmentChange', (entity) => {
  349. console.log('entityEquipmentChange', entity)
  350. })
  351.  
  352. bot.on('entityEffect', (entity, effect) => {
  353. console.log('entityEffect', entity, effect)
  354. })
  355.  
  356. bot.on('entityEffectEnd', (entity, effect) => {
  357. console.log('entityEffectEnd', entity, effect)
  358. })
  359.  
  360. function guardArea(pos) {
  361. guardPos = pos.clone()
  362.  
  363. if (!bot.pvp.target) {
  364. moveToGuardPos()
  365. }
  366. }
  367.  
  368. function stopGuarding() {
  369. guardPos = null
  370. bot.pvp.stop()
  371. bot.pathfinder.setGoal(null)
  372. }
  373.  
  374. function moveToGuardPos() {
  375. const mcData = require('minecraft-data')(bot.version)
  376. bot.pathfinder.setMovements(new Movements(bot, mcData))
  377. bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  378. }
  379.  
  380. bot.on('stoppedAttacking', () => {
  381. if (guardPos) {
  382. moveToGuardPos()
  383. }
  384. })
  385.  
  386. bot.on('physicTick', () => {
  387. if (bot.pvp.target) return
  388. if (bot.pathfinder.isMoving()) return
  389.  
  390. const entity = bot.nearestEntity()
  391. if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  392. })
  393.  
  394. bot.on('physicTick', () => {
  395. if (!guardPos) return
  396.  
  397. const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 8 &&
  398. e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  399.  
  400. const entity = bot.nearestEntity(filter)
  401. if (entity) {
  402. bot.pvp.attack(entity)
  403. }
  404. })
  405. /*
  406. bot.on('chat', (username, message) => {
  407. if (username === bot.username) return
  408. const result = /canSee (-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/.exec(message)
  409. if (result) {
  410. canSee(new Vec3(result[1], result[2], result[3]))
  411. return
  412. }
  413. switch (message) {
  414. case 'pos':
  415. console.log("pos command used")
  416. sayPosition(username)
  417. break
  418. case 'wearing':
  419. console.log("wearing command used")
  420. sayEquipment()
  421. break
  422. case 'nick':
  423. console.log("saynick command used")
  424. sayNick()
  425. break
  426. case 'spawn':
  427. console.log("spawn command used")
  428. saySpawnPoint()
  429. break
  430. case 'block':
  431. console.log("block command used")
  432. sayBlockUnder(username)
  433. break
  434. default:
  435. console.log("I am ready!")
  436. bot.chat("I am ready!")
  437. }
  438. */
  439.  
  440. // text of bots username and help will give a list of bot commands
  441. bot.on('chat', (username, message) => { // work in progress....
  442. if (message === `${bot.player.displayName} help`)
  443. bot.chat('command reminders are: stop, leave, fight me, guard, ')
  444. bot.chat('pos, wearing, nick, spawn, block ')
  445. bot.chat('arch-start, Version.(wip not all commands work...)')
  446. bot.chat('Bot may just leave if it errors out.')
  447. })
  448.  
  449. bot.on('chat', (username, message) => { // work in progress....
  450. if (message === 'Version') {
  451. console.log("Version command used just used")
  452. console.log(`version check! The version of the server is ${command.message} confermed ${brand}`)
  453. bot.chat(`version check! The version of the server is ${command.message} confermed ${brand}`)
  454. console.log("sayVersion command used")
  455. sayVersion(username)
  456. return
  457. }
  458. })
  459.  
  460. bot.on('chat', (username, message) => {
  461. if (message === 'leave') {
  462. console.log("leave command used")
  463. bot.chat("Yes sir right away!")
  464. bot.quit(username)
  465. return
  466. }
  467. })
  468.  
  469. bot.on('chat', (username, message) => {
  470. if (message === 'arch-start') {
  471. console.log("arch-start command used")
  472. bot.chat("Arrows away!! Ya, geting them... whahoo!!!")
  473. Start()
  474. return
  475. }
  476. })
  477.  
  478. bot.on('chat', (username, message) => {
  479. if (message === 'guard') { // if message guard do gaurd
  480. const player = bot.players[username]
  481.  
  482. if (!player) {
  483. bot.chat("I can't see you.")
  484. return
  485. }
  486. bot.chat('I will guard that location.')
  487. guardArea(player.entity.position)
  488. }
  489.  
  490. if (message === 'fight me') {
  491. const player = bot.players[username]
  492.  
  493. if (!player) {
  494. bot.chat("I can't see you.")
  495. return
  496. }
  497.  
  498. bot.chat('Prepare to fight!')
  499. bot.chat('5')
  500. bot.chat('4')
  501. bot.chat('3')
  502. bot.chat('2')
  503. bot.chat('1')
  504. bot.chat('GO!!!')
  505. bot.pvp.attack(player.entity)
  506. }
  507.  
  508. if (message === 'stop') {
  509. bot.chat('I will stop!')
  510. bot.hawkEye.stop()
  511. stopGuarding()
  512. }
  513. })
  514.  
  515. function not_busy() {
  516. guardPos = pos.clone()
  517.  
  518. if (guardPos == null) {
  519. return false
  520.  
  521. } else { (guardPos == !null)
  522. return true
  523. }
  524. }
  525.  
  526.  
  527. bot.on('not_busy', () => { // if bot is not busy than say "I am ready"
  528. if (busy == true) {
  529. console.log("I am busy!")
  530. bot.chat("I am busy!")
  531. } else { if (busy == false)
  532. console.log('I am ready!')
  533. bot.chat('I am ready!')
  534. }
  535.  
  536. })
  537.  
  538. bot.on('sleep', () => {
  539. bot.chat('Good night!')
  540. })
  541.  
  542. bot.on('wake', () => {
  543. bot.chat('Good morning!')
  544. })
  545.  
  546. function goToSleep() {
  547. const bed = bot.findBlock({
  548. matching: block => bot.isABed(block)
  549. })
  550. if (bed) {
  551. bot.sleep(bed, (err) => {
  552. if (err) {
  553. bot.chat(`I can't sleep: ${err.message}`)
  554. } else {
  555. bot.chat("I'm sleeping")
  556. }
  557. })
  558. } else {
  559. bot.chat('No nearby bed')
  560. }
  561. }
  562.  
  563. function wakeUp() {
  564. bot.wake((err) => {
  565. if (err) {
  566. bot.chat(`I can't wake up: ${err.message}`)
  567. } else {
  568. bot.chat('I woke up')
  569. }
  570. }
  571.  
  572. )
  573. }
  574. // syntax, syntax, syntax ???
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement