Created
April 5, 2015 02:16
-
-
Save wtfaremyinitials/164fc54270ad69fc282b to your computer and use it in GitHub Desktop.
Duties examlpe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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