Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Duties examlpe
var mineflayer = require('mineflayer');
var navigatePlugin = require('mineflayer-navigate')(mineflayer);
var blockfinderPlugin = require('mineflayer-blockfinder')(mineflayer);
var scaffoldPlugin = require('mineflayer-scaffold')(mineflayer);
var Duties = require('duties');
var BaseTask = function* BaseTask($) {
while(true) {
setTimeout($.resume, 500);
yield $.suspend();
}
};
var LumberjackTask = function* LumberjackTask($) {
while(true) {
var block = bot.findBlockSync({
point: bot.entity.position,
matching: [5, 17],
maxDistance: 256,
count: 1
})[0];
yield $.add(GotoTreeTask, block);
}
};
var GotoTreeTask = function* GotoTreeTask($, block) {
var pos = block.position;
bot.scaffold.to(pos, $.resume);
yield $.suspend();
};
var duties = new Duties();
duties.add(BaseTask);
duties.start();
var bot = mineflayer.createBot({
host: 'localhost',
port: 50000,
username: 'Woodhouse'
});
navigatePlugin(bot);
blockfinderPlugin(bot);
scaffoldPlugin(bot);
bot.on('chat', function(username, message) {
if(message == 'start') {
duties.add(LumberjackTask);
bot.chat('Starting sir.');
}
if(message == 'stop') {
duties.stop();
bot.chat('Stopping sir.');
}
});
// bot.navigate.on('pathFound', function (path) {
// bot.chat("found path. I can get there in " + path.length + " moves.");
// });
// bot.navigate.on('cannotFind', function (closestPath) {
// bot.chat("unable to find path. getting as close as possible");
// bot.navigate.walk(closestPath);
// });
// bot.navigate.on('arrived', function () {
// bot.chat("I have arrived");
// });
// bot.navigate.on('interrupted', function() {
// bot.chat("stopping");
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.