Guest User

Untitled

a guest
Jan 5th, 2021
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. const mineflayer = require('mineflayer')
  2. const pvp = require('mineflayer-pvp').plugin
  3. const { pathfinder, Movements, goals} = require('mineflayer-pathfinder')
  4. const armorManager = require('mineflayer-armor-manager')
  5. const bot = mineflayer.createBot({
  6. host: 'lubek.net',
  7. port: 25601,
  8. username: 'Straznik',
  9. logErrors: false
  10. })
  11. const mcData = require('minecraft-data')(bot.version)
  12.  
  13.  
  14. bot.loadPlugin(pvp)
  15. bot.loadPlugin(armorManager)
  16. bot.loadPlugin(pathfinder)
  17. bot.on('playerCollect', (collector, itemDrop) => {
  18. if (collector !== bot.entity) return
  19.  
  20. setTimeout(() => {
  21. const sword = bot.inventory.items().find(item => item.name.includes('sword'))
  22. if (sword) bot.equip(sword, 'hand')
  23. }, 150)
  24. })
  25.  
  26. bot.on('playerCollect', (collector, itemDrop) => {
  27. if (collector !== bot.entity) return
  28.  
  29. setTimeout(() => {
  30. const shield = bot.inventory.items().find(item => item.name.includes('shield'))
  31. if (shield) bot.equip(shield, 'off-hand')
  32. }, 250)
  33. })
  34.  
  35. let guardPos = null
  36.  
  37. function guardArea (pos) {
  38. guardPos = pos.clone()
  39.  
  40. if (!bot.pvp.target) {
  41. moveToGuardPos()
  42. }
  43. }
  44.  
  45. function stopGuarding () {
  46. guardPos = null
  47. bot.pvp.stop()
  48. bot.pathfinder.setGoal(null)
  49. }
  50.  
  51. function moveToGuardPos () {
  52. bot.pathfinder.setMovements(new Movements(bot, mcData))
  53. bot.pathfinder.setGoal(new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z))
  54. }
  55.  
  56.  
  57.  
  58. bot.on('stoppedAttacking', () => {
  59. if (guardPos) {
  60. moveToGuardPos()
  61. }
  62. })
  63.  
  64. bot.on('physicTick', () => {
  65. if (bot.pvp.target) return
  66. if (bot.pathfinder.isMoving()) return
  67.  
  68. const entity = bot.nearestEntity()
  69. if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0))
  70. })
  71.  
  72. bot.on('physicTick', () => {
  73. if (!guardPos) return
  74.  
  75. const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 16 &&
  76. e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
  77.  
  78. const entity = bot.nearestEntity(filter)
  79. if (entity) {
  80. bot.pvp.attack(entity)
  81. }
  82. })
  83.  
  84. bot.on('chat', (username, message) => {
  85. if (message === 'guard') {
  86. const player = bot.players[username]
  87.  
  88. if (!player) {
  89. bot.chat("I can't see you.")
  90. return
  91. }
  92.  
  93. bot.chat('I will guard that location.')
  94. guardArea(player.entity.position)
  95. }
  96.  
  97. if (message === 'fight me') {
  98. const player = bot.players[username]
  99.  
  100. if (!player) {
  101. bot.chat("I can't see you.")
  102. return
  103. }
  104.  
  105. bot.chat('Prepare to fight!')
  106. bot.pvp.attack(player.entity)
  107. }
  108. if (message === 'login') {
  109. bot.chat('/login lubek_yt')
  110. }
  111. if (message === 'home') {
  112. bot.chat('/home')
  113. }
  114. if (message === 'stop') {
  115. bot.chat('I will no longer guard this area.')
  116. stopGuarding()
  117. }
  118. })
  119.  
Advertisement
Add Comment
Please, Sign In to add comment