Skip to content

Instantly share code, notes, and snippets.

@kevinvdburgt
Created June 22, 2018 14:11
Show Gist options
  • Save kevinvdburgt/40be349387b2efb5a9c7eeba8b39185a to your computer and use it in GitHub Desktop.
Save kevinvdburgt/40be349387b2efb5a9c7eeba8b39185a to your computer and use it in GitHub Desktop.
breakBlock = (block) => {
return new Promise((resolve, reject) => {
// @TODO: Equip the right tool
this.bot.dig(block, (err) => {
if (err) {
return reject(err);
}
return resolve();
});
});
};
mine = (position, direction) => {
const target = position.floor().plus(direction);
const lower = this.bot.blockAt(target);
const upper = this.bot.blockAt(target.offset(0, 1, 0));
if (lower && lower.boundingBox !== 'empty') {
this.breakBlock(lower).then(() => {
setTimeout(() => this.mine(position, direction), 500);
});
return;
}
if (upper && upper.boundingBox !== 'empty') {
this.breakBlock(upper).then(() => {
setTimeout(() => this.mine(position, direction), 500);
});
return;
}
this.bot.navigate.walk([target.offset(0.5, 0, 0.5)], (err) => {
if (err) {
console.error('err>', err);
// return;
}
setTimeout(() => {
this.mine(this.bot.entity.position, vec3(0, 0, 1));
}, 250);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment