Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. local branchLength = 32
  2. local turnRight = true
  3.  
  4. local robot = require("robot");
  5. local component = require("component")
  6. local inv = component.inventory_controller
  7.  
  8. function turnInBranchDir()
  9. if turnRight then
  10. robot.turnRight()
  11. else
  12. robot.turnLeft()
  13. end
  14. end
  15.  
  16. function swingIfTool()
  17. if robot.durability() == nil then
  18. error('ERROR: no tool')
  19. end
  20. robot.swing()
  21. raiseIfInventoryFull()
  22. end
  23.  
  24. function swingUpIfTool()
  25. if robot.durability() == nil then
  26. error('ERROR: no tool')
  27. end
  28. robot.swingUp()
  29. raiseIfInventoryFull()
  30. end
  31.  
  32. function swingDownIfTool()
  33. if robot.durability() == nil then
  34. error('ERROR: no tool')
  35. end
  36. robot.swingDown()
  37. raiseIfInventoryFull()
  38. end
  39.  
  40. function raiseIfInventoryFull()
  41. local allFull = true
  42. for i = 1, robot.inventorySize(), 1 do
  43. if inv.getStackInInternalSlot(i) == nil then
  44. allFull = false
  45. end
  46. end
  47. if allFull then
  48. error('ERROR: inventory full')
  49. end
  50. end
  51.  
  52. function grabTool()
  53.  
  54. end
  55.  
  56. function mineForward()
  57. swingIfTool()
  58. robot.forward()
  59. swingUpIfTool()
  60. if not robot.detectDown() then
  61. robot.placeDown()
  62. end
  63. if not robot.detectDown() then
  64. error("ERROR: place failed!")
  65. end
  66. end
  67.  
  68. function branch()
  69. turnInBranchDir()
  70. for i = 1, branchLength, 1 do
  71. mineForward()
  72. end
  73. robot.turnAround()
  74. for i = 1, branchLength, 1 do
  75. robot.forward()
  76. end
  77. turnInBranchDir()
  78. end
  79.  
  80. -- while true do
  81. -- for i = 1, 4, 1 do
  82. -- mineForward()
  83. -- end
  84. -- branch()
  85. -- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement