Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. --- Move forward in a line for amnt blocks
  2. --- Return false if the turtle gets stuck midway
  3. function lineMotion(amnt)
  4. for x = 1, amnt do
  5. local b = turtle.forward()
  6. if not b then
  7. return b;
  8. end
  9. end
  10. end
  11.  
  12. --- Performs func and moves one block forward
  13. --- repeats x times
  14. --- Returns true if successfully moves and performs func
  15. --- for the entire length, false otherwise
  16. function lineMotionDoWhile(x, func)
  17. for xI = 1, x do
  18. local b = func()
  19. if not b then
  20. return b;
  21. end
  22. b = turtle.forward()
  23. if not b then
  24. return b;
  25. end
  26. end
  27. return true
  28. end --lineMotionDoWhile
  29.  
  30.  
  31. --- Moves in a rect shape and performs func
  32. --- Always performs the func first before moving
  33. --- Returns false if movement is blocked, true otherwise
  34. function rectMotionDoWhile(x, y, func)
  35. local turn = turtle.turnLeft
  36. for xI = 1, x do
  37. --- Decide to turn left or right
  38. if xI % 2 == 0 then
  39. turn = turtle.turnLeft
  40. else
  41. turn = turtle.turnRight
  42. end
  43.  
  44. --- Move in a line
  45. local b = lineMotionDoWhile(y, func)
  46. if not b then
  47. return b
  48. end
  49.  
  50. --- Move to next row
  51. turn()
  52. turtle.forward()
  53. turn()
  54. end --- for xI = 1, x do
  55. end --- rectMotionDoWhile
  56.  
  57. function hasEnoughFuel(x, y, z)
  58. x = math.max(x, 1)
  59. y = math.max(y, 1)
  60. z = math.max(z, 1)
  61. local fuel = turtle.getFuelLevel()
  62. return fuel >= x * y * z
  63. end --- hasEnoughFuel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement