Advertisement
StreamerYT

Untitled

Dec 5th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.27 KB | None | 0 0
  1. const mineflayer = require('mineflayer')
  2. const vec3 = require('vec3')
  3. var mcdata = mcdata = require('minecraft-data')(minecraftversion);
  4. var automining=false,
  5.     minecraftversion="1.12.2";
  6. if (process.argv.length < 4 || process.argv.length > 6) {
  7.   console.log('Usage : node miner.js <host> <port> [<name>] [<password>]')
  8.   process.exit(1)
  9. }
  10.  
  11. const bot = mineflayer.createBot({
  12.   host: process.argv[2],
  13.   port: parseInt(process.argv[3]),
  14.   username: process.argv[4] ? process.argv[4] : 'miner',
  15.   password: process.argv[5]
  16. })
  17.  
  18. bot.on('chat', (user, msg) => {
  19.     if(msg.startsWith("!")){
  20.         cmd(msg)
  21.     }  
  22. })
  23.  
  24. function cmd(msg){
  25.     const args = msg.slice("!".length).split(' ');
  26.     const cmdname = args.shift().toLowerCase();
  27.     const arg = msg.slice(+1 + +"!".length + +cmd.length)  
  28.    
  29.     if(cmdname){
  30.         if(cmdname=="automine"){
  31.             if(arg){
  32.                 autominingfunc(arg)
  33.             }
  34.         }else if(cmdname=="stopautomine"){
  35.             automining=false
  36.         }
  37.     }
  38. }
  39. function autominingfunc(blockname){
  40.     if(automining=='false'){
  41.         automining='true';
  42.         if(blockname){
  43.             block = mcdata.blocksByName[blockname];
  44.             if(block){
  45.                 setTimeout(function(){
  46.                 function autominingscript(block){
  47.                     if(automining=='false'){
  48.                         MCbot.chat('I finished digging')
  49.                     }else{
  50.                         MCbot.findBlock(
  51.                             {
  52.                                 point: MCbot.entity.position,
  53.                                 matching: block.id,
  54.                                 maxDistance: 256,
  55.                                 count: 1,
  56.                             },
  57.                             function(err, blocks) {
  58.                                 if (err) {
  59.                                     MCbot.chat('Search error '+block.displayName +' : '+ err);
  60.                                     automining='false';
  61.                                     autominingscript(block)
  62.                                 }
  63.                                 if (blocks.length) {
  64.                                     MCbot.scaffold.to(blocks[0].position, function(err) {
  65.                                         if (err) {
  66.                                             MCbot.chat("error: " + err.code);
  67.                                             automining='false';
  68.                                             autominingscript(block)
  69.                                         } else {
  70.                                             autominingscript(block)
  71.                                         }
  72.                                     })
  73.                                 } else {
  74.                                     MCbot.chat("Not found "+block.displayName+"");
  75.                                     automining='false';
  76.                                     autominingscript(block)
  77.                                 }
  78.                             }
  79.                         );
  80.                     }
  81.                 }
  82.                 autominingscript(block)
  83.                 }, 5000);
  84.             }else{
  85.                 MCbot.chat('Unknown block')
  86.                 automining='false';
  87.             }
  88.         }  
  89.     } else if(automining=='true'){
  90.         MCbot.chat('Mistake. Bot digs')
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement