Advertisement
Thomas9666

[Lua] Auto Tree Farm [CC]

Feb 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. local col = 0
  2. local row = 0
  3.  
  4. local function loadsettings()
  5. file = io.open("settings.txt", "r")
  6. while true do
  7. line = file:read()
  8. if line == nil then break end
  9. col = tonumber(line)
  10. line = file:read()
  11. if line == nil then break end
  12. row = tonumber(line)
  13. file:close()
  14. return true
  15. end
  16. file:close()
  17. return false
  18. end
  19.  
  20. local function createsettings()
  21. term.clear()
  22. term.setCursorPos(1,1)
  23. print("Please select your settings:")
  24.  
  25. write("Number of columns: ")
  26. col = tonumber(read())
  27.  
  28. write("Number of rows: ")
  29. row = tonumber(read())
  30.  
  31. file = io.open("settings.txt", "w")
  32. file:write(col)
  33. file:write("\n")
  34. file:write(row)
  35. file:write("\n")
  36. file:close()
  37.  
  38. term.clear()
  39. term.setCursorPos(1,1)
  40. print("Ready to harvest")
  41. end
  42.  
  43. if fs.exists("settings.txt") then
  44. if not loadsettings() then
  45. createsettings()
  46. end
  47. term.clear()
  48. term.setCursorPos(1,1)
  49. print("Ready to harvest")
  50. else
  51. createsettings()
  52. end
  53.  
  54. function rturn()
  55. turtle.turnRight()
  56. turtle.forward()
  57. turtle.forward()
  58. turtle.forward()
  59. turtle.forward()
  60. turtle.turnRight()
  61. end
  62.  
  63. function lturn()
  64. turtle.turnLeft()
  65. turtle.forward()
  66. turtle.forward()
  67. turtle.forward()
  68. turtle.forward()
  69. turtle.turnLeft()
  70. end
  71.  
  72. function chop()
  73. turtle.dig()
  74. turtle.forward()
  75. turtle.digDown()
  76. turtle.select(1)
  77. turtle.placeDown()
  78. turtle.select(2)
  79. count = 0
  80. while turtle.compareUp() do
  81. turtle.digUp()
  82. turtle.up()
  83. count = count + 1
  84. end
  85. for i=0,count do
  86. turtle.down()
  87. end
  88. turtle.forward()
  89. turtle.select(2)
  90. end
  91.  
  92. function move()
  93. turtle.forward()
  94. turtle.forward()
  95. turtle.forward()
  96. end
  97.  
  98. function check()
  99. if turtle.compare() then
  100. chop()
  101. else
  102. turtle.forward()
  103. end
  104. end
  105.  
  106. -- used to check how to return to start position
  107. lastturn = "l"
  108.  
  109. -- Call a refuel before moving
  110. turtle.select(16)
  111. turtle.refuel(10)
  112. turtle.select(2)
  113.  
  114.  
  115. -- First move called outside loop so turtle can turn outside the farm in loop
  116.  
  117.  
  118. for i = 1,col do
  119. move()
  120. for j = 1,row do
  121. check()
  122. move()
  123. end
  124. if lastturn == "l" then
  125. rturn()
  126. lastturn = "r"
  127. elseif lastturn == "r" then
  128. lturn()
  129. lastturn = "l"
  130. end
  131. end
  132.  
  133. if lastturn == "l" then
  134. turtle.turnLeft()
  135. for k = 1,col do
  136. move()
  137. turtle.forward()
  138. end
  139. turtle.turnRight()
  140. elseif lastturn == "r" then
  141. for g =0,row do
  142. move()
  143. turtle.forward()
  144. end
  145. turtle.turnRight()
  146. for h = 1,col do
  147. move()
  148. turtle.forward()
  149. end
  150. turtle.turnRight()
  151. end
  152. turtle.select(2)
  153. slots = turtle.getItemCount()
  154. turtle.dropDown(slots - 1)
  155. turtle.select(3)
  156. turtle.dropDown()
  157. turtle.select(4)
  158. turtle.dropDown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement