bot.on('playerJoined', (player) => {
if(player.username === bot.username){
setTimeout(find, 5000)
}else{
return;
}
})
function find(){
var posWood = null;
var posWoodX = null;
var posWoodY = null;
var posWoodZ = null;
bot.findBlock({
point: bot.entity.position,
matching: 17,
maxDistance: 70,
count: 1,
}, function(err, blockPoints) {
if (err) {
bot.chat('Error trying to find: ' + err);
return;
}
if (blockPoints.length) {
posWood = blockPoints[0].position;
posWoodX = blockPoints[0].position.x;
posWoodY = 71;
posWoodZ = blockPoints[0].position.z +1;
var temp = vec3(posWoodX, posWoodY, posWoodZ);
console.log(blockPoints[0].position);
bot.chat('I found ' + blockPoints[0].position + '.');
bot.navigate.to(temp)
bot.navigate.on('arrived', function () {
if (bot.targetDigBlock) {
bot.chat(`already digging ${bot.targetDigBlock.name}`)
} else {
var target = bot.blockAt(bot.entity.position.offset(0, 1, -1))
if (target && bot.canDigBlock(target)) {
bot.chat(`starting to dig ${target.name}`)
bot.dig(target, onDiggingCompleted)
} else {
bot.chat('cannot dig')
}
}
function onDiggingCompleted (err) {
if (err) {
console.log(err.stack)
return
}
bot.chat(`finished digging ${target.name}`)
find()
}
})
return;
} else {
return;
}
});
}
if(player.username === bot.username){
setTimeout(find, 5000)
}else{
return;
}
})
function find(){
var posWood = null;
var posWoodX = null;
var posWoodY = null;
var posWoodZ = null;
bot.findBlock({
point: bot.entity.position,
matching: 17,
maxDistance: 70,
count: 1,
}, function(err, blockPoints) {
if (err) {
bot.chat('Error trying to find: ' + err);
return;
}
if (blockPoints.length) {
posWood = blockPoints[0].position;
posWoodX = blockPoints[0].position.x;
posWoodY = 71;
posWoodZ = blockPoints[0].position.z +1;
var temp = vec3(posWoodX, posWoodY, posWoodZ);
console.log(blockPoints[0].position);
bot.chat('I found ' + blockPoints[0].position + '.');
bot.navigate.to(temp)
bot.navigate.on('arrived', function () {
if (bot.targetDigBlock) {
bot.chat(`already digging ${bot.targetDigBlock.name}`)
} else {
var target = bot.blockAt(bot.entity.position.offset(0, 1, -1))
if (target && bot.canDigBlock(target)) {
bot.chat(`starting to dig ${target.name}`)
bot.dig(target, onDiggingCompleted)
} else {
bot.chat('cannot dig')
}
}
function onDiggingCompleted (err) {
if (err) {
console.log(err.stack)
return
}
bot.chat(`finished digging ${target.name}`)
find()
}
})
return;
} else {
return;
}
});
}