Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mineflayer = require('mineflayer')
- const vec3 = require('vec3')
- var mcdata = mcdata = require('minecraft-data')(minecraftversion);
- var automining=false,
- minecraftversion="1.12.2";
- if (process.argv.length < 4 || process.argv.length > 6) {
- console.log('Usage : node miner.js <host> <port> [<name>] [<password>]')
- process.exit(1)
- }
- const bot = mineflayer.createBot({
- host: process.argv[2],
- port: parseInt(process.argv[3]),
- username: process.argv[4] ? process.argv[4] : 'miner',
- password: process.argv[5]
- })
- bot.on('chat', (user, msg) => {
- if(msg.startsWith("!")){
- cmd(msg)
- }
- })
- function cmd(msg){
- const args = msg.slice("!".length).split(' ');
- const cmdname = args.shift().toLowerCase();
- const arg = msg.slice(+1 + +"!".length + +cmd.length)
- if(cmdname){
- if(cmdname=="automine"){
- if(arg){
- autominingfunc(arg)
- }
- }else if(cmdname=="stopautomine"){
- automining=false
- }
- }
- }
- function autominingfunc(blockname){
- if(automining=='false'){
- automining='true';
- if(blockname){
- block = mcdata.blocksByName[blockname];
- if(block){
- setTimeout(function(){
- function autominingscript(block){
- if(automining=='false'){
- MCbot.chat('I finished digging')
- }else{
- MCbot.findBlock(
- {
- point: MCbot.entity.position,
- matching: block.id,
- maxDistance: 256,
- count: 1,
- },
- function(err, blocks) {
- if (err) {
- MCbot.chat('Search error '+block.displayName +' : '+ err);
- automining='false';
- autominingscript(block)
- }
- if (blocks.length) {
- MCbot.scaffold.to(blocks[0].position, function(err) {
- if (err) {
- MCbot.chat("error: " + err.code);
- automining='false';
- autominingscript(block)
- } else {
- autominingscript(block)
- }
- })
- } else {
- MCbot.chat("Not found "+block.displayName+"");
- automining='false';
- autominingscript(block)
- }
- }
- );
- }
- }
- autominingscript(block)
- }, 5000);
- }else{
- MCbot.chat('Unknown block')
- automining='false';
- }
- }
- } else if(automining=='true'){
- MCbot.chat('Mistake. Bot digs')
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement