Mariomarco

TurtleFarm

Dec 29th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. rednet.open("left")
  2. rednet.open("right")
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. write("   Final FarmOS 1.2")
  6. term.setCursorPos(1,2)
  7. movedir = "right"
  8. filledslot = 2
  9. step = 0
  10. row = 0
  11. line = 0
  12. sidedone = false
  13. finished = false
  14. rednet.open("left")
  15. rednet.open("right")
  16.  
  17. local function getfilledslot()
  18.     while turtle.getItemCount(filledslot) == 0 do
  19.         if filledslot + 1 <= 16 then
  20.             filledslot = filledslot + 1
  21.         else
  22.             filledslot = 2
  23.         end
  24.         sleep(0.1)
  25.     end
  26. end
  27.  
  28. local function callSeeds()
  29. turtle.turnLeft()
  30. turtle.suck()
  31. turtle.suck()
  32. turtle.suck()
  33. turtle.suck()
  34. turtle.suck()
  35. turtle.suck()
  36. turtle.suck()
  37. turtle.suck()
  38. turtle.suck()
  39. turtle.suck()
  40. turtle.suck()
  41. turtle.suck()
  42. turtle.suck()
  43. turtle.suck()
  44. turtle.suck()
  45. turtle.turnRight()
  46. end
  47.  
  48. local function GOHOME()
  49. turtle.turnRight()
  50. turtle.turnRight()
  51. turtle.forward()
  52. turtle.forward()
  53. turtle.forward()
  54. turtle.forward()
  55. turtle.forward()
  56. turtle.forward()
  57. turtle.forward()
  58. turtle.forward()
  59. turtle.forward()
  60. turtle.forward()
  61. turtle.forward()
  62. turtle.forward()
  63. turtle.forward()
  64. turtle.turnRight()
  65. turtle.forward()
  66. turtle.forward()
  67. turtle.forward()
  68. turtle.forward()
  69. turtle.forward()
  70. turtle.forward()
  71. turtle.forward()
  72. turtle.forward()
  73. turtle.forward()
  74. turtle.forward()
  75. turtle.forward()
  76. turtle.forward()
  77. turtle.forward()
  78. turtle.forward()
  79. turtle.forward()
  80. turtle.forward()
  81. turtle.forward()
  82. turtle.forward()
  83. turtle.forward()
  84. turtle.forward()
  85. turtle.forward()
  86. turtle.forward()
  87. turtle.forward()
  88. turtle.forward()
  89. turtle.turnLeft()
  90. turtle.select(2)
  91. turtle.drop()
  92. turtle.select(3)
  93. turtle.drop()
  94. turtle.select(4)
  95. turtle.drop()
  96. turtle.select(5)
  97. turtle.drop()
  98. turtle.select(6)
  99. turtle.drop()
  100. turtle.select(7)
  101. turtle.drop()
  102. turtle.select(8)
  103. turtle.drop()
  104. turtle.select(9)
  105. turtle.drop()
  106. turtle.select(10)
  107. turtle.drop()
  108. turtle.select(11)
  109. turtle.drop()
  110. turtle.select(12)
  111. turtle.drop()
  112. turtle.select(13)
  113. turtle.drop()
  114. turtle.select(14)
  115. turtle.drop()
  116. turtle.select(15)
  117. turtle.drop()
  118. turtle.select(16)
  119. turtle.drop()
  120.  turtle.turnRight()
  121.  turtle.turnRight()
  122. end
  123.  
  124. local function refuel()
  125.    if turtle.getFuelLevel() <= 20 then
  126.     turtle.select(1)
  127.     turtle.refuel(2)
  128.     turtle.refuel(2)
  129.     turtle.refuel(2)
  130.     turtle.refuel(2)
  131.    end
  132.    rednet.broadcast("FarmTurtleCoal")
  133.    rednet.broadcast(tostring(turtle.getItemCount(1)))
  134. end
  135.  
  136. local function checkFuelLevel()
  137.     rednet.broadcast("FarmTurtleFuel")
  138.     rednet.broadcast(tostring(turtle.getFuelLevel()))
  139. end
  140.  
  141. local function tiltline()
  142. while finished == false do
  143. while turtle.detect() == false do
  144. getfilledslot()
  145. turtle.select(filledslot)
  146. turtle.placeDown()
  147. getfilledslot()
  148. turtle.forward()
  149. checkFuelLevel()
  150. refuel()
  151. end
  152. if movedir == "left" then
  153.     turtle.turnLeft()
  154. if turtle.detect() == true then
  155.     finished= true
  156. end
  157.     turtle.forward()
  158.     turtle.turnLeft()
  159. movedir ="right"
  160. else
  161.     turtle.turnRight()
  162.     turtle.turnRight()
  163. movedir ="left"
  164. end
  165. while turtle.detect() == false do
  166. if turtle.detectDown() == true then
  167. turtle.select(filledslot)
  168. getfilledslot()
  169. turtle.forward()
  170. checkFuelLevel()
  171. refuel()
  172. else
  173. getfilledslot()
  174. turtle.select(filledslot)
  175. getfilledslot()
  176. turtle.placeDown()
  177. turtle.forward()
  178. checkFuelLevel()
  179. refuel()
  180. end
  181. end
  182. end
  183. end
  184.  
  185. while redstone.getInput("left") == false do
  186.   local senderId, message, distance = rednet.receive()
  187. if message == "Farmer.Start()" then
  188. write("working...    ")
  189.   while finished == false do
  190.    filledslot = 2
  191.    callSeeds()
  192.    turtle.select(filledslot)
  193.    tiltline()
  194.   end
  195. finished = false
  196. movedir = "right"
  197. step = 0
  198. row = 0
  199. line = 0
  200. sidedone = false
  201. filledslot = 2
  202. GOHOME()
  203. elseif message=="Farmer.Exit()" then
  204. return
  205. end
  206. sleep(0.01)
  207. end
  208. return
Advertisement
Add Comment
Please, Sign In to add comment