Skip to content

Instantly share code, notes, and snippets.

@MrOrz
Created December 4, 2013 06:56
Show Gist options
  • Save MrOrz/7783433 to your computer and use it in GitHub Desktop.
Save MrOrz/7783433 to your computer and use it in GitHub Desktop.
Mineflayer fishing bot.
var mineflayer = require('mineflayer'),
repl = require("repl");
var FISHING_ROD = 346, RAW_FISH = 349;
var FISHING_INTERVAL = 200;
var bot = mineflayer.createBot({
host: "<server>",
username: "<username>"
});
// Caught fish, report!
//
bot.on('playerCollect', function(collector, collected){
if(collector.username === '<username>'){
console.log("Now have", bot.inventory.count(RAW_FISH) , "fish.");
}
});
var fishing = function(){
// No fishing rods left.
if(bot.inventory.count(FISHING_ROD) <= 0){
console.error("No fishing rods now.");
return;
// Fishing rod broken, switch to fishing rod then continue fishing.
}else if(!( bot.heldItem && bot.heldItem.type === FISHING_ROD)){
var rod = bot.inventory.findInventoryItem(FISHING_ROD);
bot.equip(rod, 'hand', function(err){
if(err) throw err;
console.log(bot.inventory.count(FISHING_ROD) , "fishing rods left.");
});
}else{
// Just fish.
bot.activateItem();
}
setTimeout(fishing, FISHING_INTERVAL);
}
bot.on('spawn', fishing);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment