Guest User

Untitled

a guest
Jun 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. breakBlock = (block) => {
  2. return new Promise((resolve, reject) => {
  3. // @TODO: Equip the right tool
  4.  
  5. this.bot.dig(block, (err) => {
  6. if (err) {
  7. return reject(err);
  8. }
  9.  
  10. return resolve();
  11. });
  12. });
  13. };
  14.  
  15. mine = (position, direction) => {
  16. const target = position.floor().plus(direction);
  17.  
  18. const lower = this.bot.blockAt(target);
  19. const upper = this.bot.blockAt(target.offset(0, 1, 0));
  20.  
  21. if (lower && lower.boundingBox !== 'empty') {
  22. this.breakBlock(lower).then(() => {
  23. setTimeout(() => this.mine(position, direction), 500);
  24. });
  25. return;
  26. }
  27.  
  28. if (upper && upper.boundingBox !== 'empty') {
  29. this.breakBlock(upper).then(() => {
  30. setTimeout(() => this.mine(position, direction), 500);
  31. });
  32. return;
  33. }
  34.  
  35. this.bot.navigate.walk([target.offset(0.5, 0, 0.5)], (err) => {
  36. if (err) {
  37. console.error('err>', err);
  38. // return;
  39. }
  40.  
  41. setTimeout(() => {
  42. this.mine(this.bot.entity.position, vec3(0, 0, 1));
  43. }, 250);
  44. });
  45. };
Add Comment
Please, Sign In to add comment