gridcaster

TFarm

Jun 2nd, 2021 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[ SETTINGS ]]--
  2. X=18
  3. Y=9
  4. sendID=-1
  5. plant = "true"
  6. fuelID="minecraft:coal"
  7. sleepOnLoad=120
  8. --[[    END   ]]--
  9.  
  10.  
  11.  
  12. Status="on the Wrong Block :/"
  13. xb=1
  14. shell.run("clear")
  15. right="false"
  16. pause="false"
  17. stop="false"
  18. local fin="false"
  19. local f = Y*X+Y+X+10
  20. sId = tonumber(sendID)
  21.  
  22.  
  23. local function unload()
  24. if pause == "true" then
  25. fin ="true"
  26. shell.run(shell.getRunningProgram())
  27. else
  28. end
  29. Status="Loading/Unloading"
  30. for a=1,14 do
  31. turtle.select(a)
  32. turtle.dropDown()
  33. end
  34. for item=1, 16 do
  35. Isuc, Iname = turtle.getItemDetail()
  36. turtle.select(14)
  37. turtle.suckDown()
  38. if Iname == "minecraft:wheat_seeds" or "minecraft:carrot" or "minecraft:potato" then
  39. turtle.transferTo(15)
  40. elseif Iname == FuelID then
  41. turtle.transferTo(16)
  42. end
  43. turtle.select(14)
  44. turtle.dropDown()
  45. end
  46. Status="sleeping"
  47. sleep(sleepOnLoad)
  48. turtle.select(16)
  49. turtle.refuel()
  50. turtle.select(14)
  51. turtle.dropDown()
  52. turtle.select(1)
  53. turtle.forward()
  54.  
  55. xb=1
  56. right="false"
  57. end
  58.  
  59.  
  60. local function Fplant()
  61. Status = "planting"
  62. sucess, data = turtle.inspectDown()
  63. if plant == "true" then
  64. turtle.select(15)
  65. turtle.placeDown()
  66. turtle.select(1)
  67. else
  68. end
  69.  
  70. end
  71.  
  72.  
  73. local function detect()
  74. if pause == "true" then
  75. else
  76. Status = "moving forward"
  77. sucess, data = turtle.inspectDown()
  78. if sucess == true then
  79.  if data.metadata == 7 then
  80.  Status = "farming"
  81.  turtle.digDown()
  82.  turtle.select(2)
  83.  turtle.transferTo(15)
  84.   turtle.select(1)
  85.  sleep(0.2)
  86.  Fplant()
  87.  end
  88. else
  89. turtle.digDown()
  90. Fplant()
  91. end
  92. end
  93. end
  94.  
  95. local function curve()
  96. sucess, data = turtle.inspectDown()
  97. if right == "false" then
  98. xb = xb+1
  99. if xb <= X then
  100. detect()
  101. Status = "turning to the right"
  102. turtle.turnRight()
  103. turtle.forward()
  104. turtle.turnRight()
  105. right = "true"
  106. end
  107.  
  108. elseif right == "true" then
  109. xb = xb+1
  110. if xb <= X then
  111. detect()
  112. Status = "turning to the left"
  113. turtle.turnLeft()
  114. turtle.forward()
  115. turtle.turnLeft()
  116. right = "false"
  117. end
  118. end
  119. end
  120.  
  121. local function back()
  122. detect()
  123. Status = "going back"
  124.  if right == "true" then
  125.  turtle.turnRight()
  126. detect()
  127. for i1=3,xb do
  128. turtle.forward()
  129.  
  130. end
  131. turtle.turnLeft()
  132. turtle.forward()
  133. turtle.turnLeft()
  134. turtle.turnLeft()
  135. unload()
  136. end
  137.  
  138.  
  139. if right == "false" then
  140. turtle.turnLeft()
  141. turtle.turnLeft()
  142. detect()
  143. for i2=2,Y do
  144. turtle.forward()
  145. end
  146. turtle.turnRight()
  147.  
  148. for i1=3,xb do
  149. turtle.forward()
  150.  
  151. end
  152. turtle.turnLeft()
  153. turtle.forward()
  154. turtle.turnLeft()
  155. turtle.turnLeft()
  156. unload()
  157. end
  158. end
  159.  
  160. local function send()
  161.  
  162. local function opnmdm()
  163. for i,v in pairs(rs.getSides()) do
  164.   if peripheral.getType(v) == "modem" then
  165.    if not rednet.isOpen(v) then rednet.open(v) end
  166.   return true end
  167. end
  168. return false end
  169.  
  170. opnmdm()
  171.  
  172. while fin == "false" do
  173. Id, message, protocol = rednet.receive()
  174. if Id == sendID then
  175.  
  176. if not os.getComputerLabel() then
  177. os.setComputerLabel("FeelingTurtle")
  178. end
  179.  
  180. if message == "stop" then
  181. Status = "Stopped"
  182. stop = "true"
  183. sleep(1)
  184. rednet.send(sId, os.getComputerLabel() .."[".. os.getComputerID() .."] Stopped!")
  185. end
  186.  
  187.  
  188. if message == "resume" then
  189. Status = "on the wrong block :/"
  190. stop = "false"
  191. sleep(1)
  192. rednet.send(sId, os.getComputerLabel() .."[".. os.getComputerID() .."] Resumed")
  193. end
  194.  
  195.  
  196. if message == "status" then
  197. sleep(1)
  198. rednet.send(sId, os.getComputerLabel() .."[".. os.getComputerID() .."] is "..Status)
  199. end
  200.  
  201. if message == "fuel" then
  202. sleep(1)
  203. rednet.send(sId, os.getComputerLabel() .."[".. os.getComputerID() .."] has "..turtle.getFuelLevel().." Fuel!")
  204. end
  205.  
  206. if message == "type" then
  207. sleep(1)
  208. rednet.send(sId, os.getComputerLabel() .."[".. os.getComputerID() .."] Is a Farming Turtle!")
  209. end
  210.  
  211. if message == "help" then
  212. sleep(1)
  213. rednet.send(sId, os.getComputerLabel() .."[".. os.getComputerID() .."] Commands: stop, resume, status, fuel, type")
  214. end
  215.  
  216. if message and message ~= "" then
  217. rednet.send(sId, "Invalid command!")
  218. message=""
  219. else
  220.  
  221. end
  222. end
  223. end
  224. end
  225.  
  226. local function ui()
  227. while fin == "false" do
  228. x1, y1 = term.getSize()
  229. x2, y2 = term.getCursorPos()
  230. text = os.getComputerLabel().."[".. os.getComputerID().."]"
  231. term.setCursorPos(x1/2/string.len(text)+1,1)
  232. print(text)
  233. text = " Status: Is ".. Status.."              "
  234. term.setCursorPos(x1/2/string.len(text),3)
  235. print(text)
  236. term.setCursorPos(1,4)
  237. print("---------------------------------------")
  238. sleep(0.01)
  239. term.setCursorPos(1,y2)
  240. end
  241. end
  242.  
  243. local function shellP()
  244.  
  245. while fin == "false" do
  246. x2, y2 = term.getCursorPos()
  247.  
  248. if y2 > 13 then
  249. term.clear()
  250.  term.setCursorPos(1,5)
  251.  elseif y2 < 5 then
  252.  term.setCursorPos(1,5)
  253.  else
  254.  end
  255.  
  256. write("> ")
  257. c = read()
  258.  
  259. if c == "stop" then
  260. Status = "Stopped"
  261. stop = "true"
  262. print(os.getComputerLabel() .."[".. os.getComputerID() .."] Stopped!")
  263.  
  264. elseif c == "resume" then
  265. Status = "sleeping"
  266. stop = "false"
  267. print(os.getComputerLabel() .."[".. os.getComputerID() .."] Resumed")
  268.  
  269. elseif c == "status" then
  270. print(os.getComputerLabel() .."[".. os.getComputerID() .."] is "..Status)
  271.  
  272. elseif c == "fuel" then
  273. print(os.getComputerLabel() .."[".. os.getComputerID() .."] has "..turtle.getFuelLevel().." Fuel!")
  274.  
  275.  
  276.  
  277. elseif c == "type" then
  278. print(os.getComputerLabel() .."[".. os.getComputerID() .."] Is a Felling Turtle!")
  279.  
  280.  
  281. elseif c == "exit" then
  282. print("Terminated!")
  283. pause = "true"
  284. turtle.select(1)
  285. sleep(0.5)
  286. os.reboot()
  287. elseif c == "help" then
  288. print("Commands: ")
  289. print("stop, resume, status, fuel, type, exit")
  290. else
  291. print("Invalid Command!")
  292.  
  293.  
  294. end
  295. sleep(2)
  296. term.clear()
  297. end
  298. end
  299.  
  300. local function main()
  301. os.pullEvent =os.pullEventRaw
  302. unload()
  303. while turtle.getFuelLevel() < f do
  304. sleep(1)
  305. Status="out of Fuel!"
  306. turtle.select(16)
  307. turtle.refuel(64)
  308. end
  309. while true do
  310. if pause == "false" and stop == "false" then
  311. for i3=2,Y do
  312. detect()
  313. turtle.forward()
  314. end
  315. curve()
  316.  
  317. if X < xb then
  318. pause="true"
  319.  
  320. back()
  321. end
  322.  
  323. end
  324. end
  325. sleep(0.01)
  326. end
  327.  
  328.  
  329. parallel.waitForAny(ui, send, shellP, main)
  330. shell.run(shell.getRunningProgram())
Add Comment
Please, Sign In to add comment