Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mineflayer = require('mineflayer');
- var navigatePlugin = require('mineflayer-navigate')(mineflayer);
- var scaffoldPlugin = require('mineflayer-scaffold')(mineflayer);
- var blockFinderPlugin = require('mineflayer-blockfinder')(mineflayer);
- var parse = require('shell-quote').parse;
- var blocksToMine = [];
- var master = "TheTechPony"
- var bot = mineflayer.createBot({
- host: process.argv[2],
- username: '', // email and password are required only for
- password: '', // online-mode=true servers
- version: "1.12",
- });
- bot.chatAddPattern(/^\[.*?(\w*) -> me \] (.*)$/, "chat", "essentials chat");
- bot.chatAddPattern(/^\[.*?(\w*) -> me \] (.*)$/, "whisper", "essentials whisper");
- //bot.chatAddPattern(/^.*?(\w*) has requested (?:to teleport to you|that you teleport to them)\.$/, "tpRequest", "epicsb tpa request");
- console.log('---- TTPB: Loaded patterns');
- scaffoldPlugin(bot);
- navigatePlugin(bot);
- blockFinderPlugin(bot);
- console.log('---- TTPB: Loaded plugins');
- bot.on('message', msg => console.log(msg.toString()))
- //--------------------------------------------------------------------------
- bot.on('chat', function(username, message) {
- console.log(username + ': ' + message);
- message = message.split(" ");
- var target = bot.players[username].entity;
- if (username === bot.username) return
- for (var i = 0; i < message.length; i++) {
- if (message[0] === 'come') {
- bot.navigate.to(target.position);
- return
- } else if (message[0] === 'tpa') {
- tpa(username);
- return
- } else if (message[0] === 'findblocks') {
- findBlock(message[1], message[2]);
- return
- } else if (message[0] === 'lumberjack') {
- if (null === message[1]) {
- var id = 17
- var amt = 3
- }
- findBlock(id, amt);
- return
- } else {
- bot.chat("/msg " + username + " Invalid command. Message 'help' for more a list of commands");
- return
- };
- }
- });
- //--------------------------------------------------------------------------
- bot.on('spawn', function() {
- console.log('Spawned');
- bot.chat("/msg TheTechPony Current admins: " + master);
- });
- bot.on('tpRequest', function(username) {
- if ( username == master ) {
- bot.chat("/tpaccept")
- }
- });
- bot.on('kicked', function(reason) {
- console.log("---- I got kicked for", reason);
- });
- //--------------------------------------------------------------------------
- bot.navigate.blocksToAvoid[132] = true; // avoid tripwire
- bot.navigate.blocksToAvoid[59] = true; // ok to trample crops
- bot.navigate.on('cannotFind', function (closestPath, player) {
- bot.chat("/msg " + player + " unable to find path. Message force-come to make me break my way to you.");
- //bot.navigate.walk(closestPath);
- });
- bot.navigate.on('interrupted', function() {
- bot.chat("/msg " + master + " Navigation interrupted; stopping now.");
- });
- //--------------------------------------------------------------------------
- function digSchedule() {
- blocksToMine.map(function(b) {
- bot.scaffold.to(b)
- });
- }
- function findBlock(ID, amt) {
- ID = parseInt(ID)
- amt = parseInt(amt)
- bot.findBlock({
- point: bot.entity.position,
- matching: ID,
- maxDistance: 512,
- count: amt,
- }, function(err, block) {
- if (err) {
- return bot.chat('/msg ' + master + ' Error searching for blocks: ' + err);
- return;
- }
- if (block.length) {
- for (var i = 0; i < block.length; i++) {
- console.log(block[i].position);
- blocksToMine.push(block[i].position);
- }
- digSchedule();
- return;
- } else {
- bot.chat("/msg " + master + " I couldn't find any " + ID + " blocks within 256.");
- return;
- }
- });
- };
- //--------------------------------------------------------------------------
- function tpa(username) {
- bot.chat("/tpa " + username);
- };
- function moveTo(username, forced) {
- var target = bot.players[username].entity;
- if (forced) {
- bot.scaffold.to(target.position, function(err) {
- if (err) {
- bot.chat("/msg " + master + " I didn't make it: " + err.code);
- }
- });
- } else {
- bot.navigate.to(target.position);
- };
- };
- function scaffoldListen() {
- bot.scaffold.on('changeState', onScaffoldChangeState);
- }
- function scaffoldStopListen() {
- bot.scaffold.removeListener('changeState', onScaffoldChangeState);
- }
- function onScaffoldChangeState(oldState, newState, reason, data) {
- if (newState === 'off') {
- if (reason === 'death') {
- respond("I died. Pausing mining operation.");
- } else if (reason === 'success') {
- findBlockAndWalk();
- } else if (reason === 'errorDigging') {
- respond("Error digging.");
- } else if (reason === 'errorEquipping') {
- respond("Error equipping.");
- } else if (reason === 'itemRequired') {
- if (data.type === 'tool') {
- respond("I lack the tool to break " + data.targetBlock.displayName);
- } else if (data.type === 'scaffolding') {
- respond("I lack scaffolding materials.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement