Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. var mineflayer = require('mineflayer');
  2. var navigatePlugin = require('mineflayer-navigate')(mineflayer);
  3. var scaffoldPlugin = require('mineflayer-scaffold')(mineflayer);
  4. var blockFinderPlugin = require('mineflayer-blockfinder')(mineflayer);
  5. var parse = require('shell-quote').parse;
  6. var blocksToMine = [];
  7. var master = "TheTechPony"
  8.  
  9. var bot = mineflayer.createBot({
  10. host: process.argv[2],
  11. username: 'silverstrats4lyfe@gmail.com', // email and password are required only for
  12. password: 'WordPass11', // online-mode=true servers
  13. version: "1.12",
  14. });
  15.  
  16. bot.chatAddPattern(/^\[.*?(\w*) -> me \] (.*)$/, "chat", "essentials chat");
  17. bot.chatAddPattern(/^\[.*?(\w*) -> me \] (.*)$/, "whisper", "essentials whisper");
  18. //bot.chatAddPattern(/^.*?(\w*) has requested (?:to teleport to you|that you teleport to them)\.$/, "tpRequest", "epicsb tpa request");
  19. console.log('---- TTPB: Loaded patterns');
  20.  
  21. scaffoldPlugin(bot);
  22. navigatePlugin(bot);
  23. blockFinderPlugin(bot);
  24. console.log('---- TTPB: Loaded plugins');
  25.  
  26. bot.on('message', msg => console.log(msg.toString()))
  27.  
  28. //--------------------------------------------------------------------------
  29.  
  30. bot.on('chat', function(username, message) {
  31. console.log(username + ': ' + message);
  32. message = message.split(" ");
  33. var target = bot.players[username].entity;
  34.  
  35. if (username === bot.username) return
  36.  
  37. for (var i = 0; i < message.length; i++) {
  38. if (message[0] === 'come') {
  39. bot.navigate.to(target.position);
  40. return
  41. } else if (message[0] === 'tpa') {
  42. tpa(username);
  43. return
  44. } else if (message[0] === 'findblocks') {
  45. findBlock(message[1], message[2]);
  46. return
  47. } else if (message[0] === 'lumberjack') {
  48. if (null === message[1]) {
  49. var id = 17
  50. var amt = 3
  51. }
  52. findBlock(id, amt);
  53. return
  54. } else {
  55. bot.chat("/msg " + username + " Invalid command. Message 'help' for more a list of commands");
  56. return
  57. };
  58. }
  59. });
  60.  
  61. //--------------------------------------------------------------------------
  62.  
  63. bot.on('spawn', function() {
  64. console.log('Spawned');
  65. bot.chat("/msg TheTechPony Current admins: " + master);
  66. });
  67.  
  68. bot.on('tpRequest', function(username) {
  69. if ( username == master ) {
  70. bot.chat("/tpaccept")
  71. }
  72. });
  73.  
  74. bot.on('kicked', function(reason) {
  75. console.log("---- I got kicked for", reason);
  76. });
  77.  
  78. //--------------------------------------------------------------------------
  79.  
  80. bot.navigate.blocksToAvoid[132] = true; // avoid tripwire
  81. bot.navigate.blocksToAvoid[59] = true; // ok to trample crops
  82. bot.navigate.on('cannotFind', function (closestPath, player) {
  83. bot.chat("/msg " + player + " unable to find path. Message force-come to make me break my way to you.");
  84. //bot.navigate.walk(closestPath);
  85. });
  86. bot.navigate.on('interrupted', function() {
  87. bot.chat("/msg " + master + " Navigation interrupted; stopping now.");
  88. });
  89.  
  90. //--------------------------------------------------------------------------
  91.  
  92. function digSchedule() {
  93. blocksToMine.map(function(b) {
  94. bot.scaffold.to(b)
  95. });
  96. }
  97.  
  98.  
  99. function findBlock(ID, amt) {
  100. ID = parseInt(ID)
  101. amt = parseInt(amt)
  102. bot.findBlock({
  103. point: bot.entity.position,
  104. matching: ID,
  105. maxDistance: 512,
  106. count: amt,
  107. }, function(err, block) {
  108. if (err) {
  109. return bot.chat('/msg ' + master + ' Error searching for blocks: ' + err);
  110. return;
  111. }
  112. if (block.length) {
  113. for (var i = 0; i < block.length; i++) {
  114. console.log(block[i].position);
  115. blocksToMine.push(block[i].position);
  116. }
  117. digSchedule();
  118. return;
  119. } else {
  120. bot.chat("/msg " + master + " I couldn't find any " + ID + " blocks within 256.");
  121. return;
  122. }
  123. });
  124. };
  125.  
  126. //--------------------------------------------------------------------------
  127.  
  128. function tpa(username) {
  129. bot.chat("/tpa " + username);
  130. };
  131.  
  132. function moveTo(username, forced) {
  133. var target = bot.players[username].entity;
  134. if (forced) {
  135. bot.scaffold.to(target.position, function(err) {
  136. if (err) {
  137. bot.chat("/msg " + master + " I didn't make it: " + err.code);
  138. }
  139. });
  140. } else {
  141. bot.navigate.to(target.position);
  142. };
  143. };
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. function scaffoldListen() {
  164. bot.scaffold.on('changeState', onScaffoldChangeState);
  165. }
  166.  
  167. function scaffoldStopListen() {
  168. bot.scaffold.removeListener('changeState', onScaffoldChangeState);
  169. }
  170.  
  171. function onScaffoldChangeState(oldState, newState, reason, data) {
  172. if (newState === 'off') {
  173. if (reason === 'death') {
  174. respond("I died. Pausing mining operation.");
  175. } else if (reason === 'success') {
  176. findBlockAndWalk();
  177. } else if (reason === 'errorDigging') {
  178. respond("Error digging.");
  179. } else if (reason === 'errorEquipping') {
  180. respond("Error equipping.");
  181. } else if (reason === 'itemRequired') {
  182. if (data.type === 'tool') {
  183. respond("I lack the tool to break " + data.targetBlock.displayName);
  184. } else if (data.type === 'scaffolding') {
  185. respond("I lack scaffolding materials.");
  186. }
  187. }
  188. }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement