Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. --getting cli args
  2.  
  3. local args = {...}
  4.  
  5. --defining variables
  6.  
  7. local errors = 0
  8.  
  9. local width = 0
  10. local range = 0
  11.  
  12. local treesCut = 0
  13.  
  14. --assigning values
  15.  
  16. if args[1] ~= nil and args[1] > 0 then
  17. width = args[1] * 1
  18. else
  19. print("Please provide orchard width")
  20. errors = errors + 1
  21. end
  22.  
  23. if args[2] ~= nil and args[2] > 0 then
  24. range = args[2] * 1
  25. else
  26. print("Please provide orchard range")
  27. errors = errors + 1
  28. end
  29.  
  30. if turtle.getFuelLevel() == 0 then
  31. print("No fuel left - please refill")
  32. errors = errors + 1
  33. end
  34.  
  35. --defining functions
  36.  
  37. function fellTree()
  38. print("Felling tree...")
  39.  
  40. local upMoves = 0
  41.  
  42. turtle.dig()
  43. turtle.forward()
  44.  
  45. while turtle.detectUp() do
  46. turtle.digUp()
  47. turtle.up()
  48. upMoves = upMoves + 1
  49. end
  50.  
  51. --returning to ground
  52.  
  53. for i = 1, upMoves, 1 do
  54. turtle.down()
  55. end
  56.  
  57. print("Finished felling tree")
  58. end
  59.  
  60. function strafeCol(column)
  61. if (column % 2) == 1 then
  62. turtle.turnRight()
  63. turtle.forward()
  64. turtle.turnRight()
  65. elseif (column % 2) == 0 then
  66. turtle.turnLeft()
  67. turtle.forward()
  68. turtle.turnLeft()
  69. end
  70. end
  71.  
  72. function clearColumn(length)
  73. for i = 1, length, 1 do
  74. if turtle.detect() then
  75. print("Detected tree")
  76. fellTree()
  77. treesCut = treesCut + 1
  78. else
  79. if i < length then
  80. turtle.forward()
  81. end
  82. end
  83. end
  84. end
  85.  
  86. --main section begin
  87.  
  88. if errors == 0 then
  89.  
  90. for x = 1, width, 1 do
  91. clearColumn(range)
  92.  
  93. if x < width then
  94. strafeCol(x)
  95. end
  96. end
  97.  
  98. print("Returning to origin...")
  99.  
  100. --return begin
  101.  
  102. if (width % 2) == 1 then
  103. turtle.turnLeft()
  104.  
  105. for i = 1, (width - 1), 1 do
  106. turtle.forward()
  107. end
  108.  
  109. turtle.turnLeft()
  110.  
  111. for i = 1, (range - 1), 1 do
  112. turtle.forward()
  113. end
  114.  
  115. turtle.turnLeft()
  116. turtle.turnLeft()
  117.  
  118. elseif (width % 2) == 0 then
  119. turtle.turnRight()
  120.  
  121. for i = 1, (width - 1), 1 do
  122. turtle.forward()
  123. end
  124.  
  125. turtle.turnRight()
  126. end
  127.  
  128. print("Done")
  129. print("Chopped down " ..tostring(treesCut) .." trees")
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement