Created
June 22, 2018 14:11
-
-
Save kevinvdburgt/40be349387b2efb5a9c7eeba8b39185a to your computer and use it in GitHub Desktop.
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
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