Blazuno

Untitled

Oct 26th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.41 KB | None | 0 0
  1. robot.api = require("robot")
  2. component.api = require("component")
  3. print("Robot crop farm! (Before starting, ensure you have seeds in the first slot [it'll tell you where else you need to put them for first time autoplanting] and fuel in the last 2 slots before continuing with this program)")
  4. print("Length? (the way the robot is facing.)")
  5. Length = tonumber(read())
  6. if Length == 0 then
  7. print("Invalid")
  8. else do
  9. print("Width?")
  10. Width = tonumber(read())
  11. SeedSlotAmount = Length*Width/64
  12. SeedSlotAmount = math.ceil(SeedSlotAmount)
  13. if SeedSlotAmount>14 then
  14. SeedSlotAmount = 14
  15. end
  16. print("Delay between farming sessions?")
  17. Delay = tonumber(read())
  18. print("Do you want to have the robot plant them for the first run as a first time?")
  19. FirstRun = read()
  20. if FirstRun == "yes" then
  21. FirstRun = true
  22. print("Okay farming time make sure you have seeds in slots 1- "..SeedSlotAmount.." and fuel in the last 2 slots.")
  23. elseif FirstRun == "no" then
  24. FirstRun = false
  25. print("Okay farming time just have fuel in the last 2 slots.")
  26. else
  27. print("Invalid.")
  28. end
  29. end
  30. end
  31.  
  32.  
  33. TurtleXPos = 1
  34. TurtleYPos = 1
  35.  
  36.  
  37. turnLeft = false
  38. changeXPos = false
  39.  
  40. function changeReverseXPos()
  41. if changeXPos == false then
  42. changeXPos = true
  43. else
  44. changeXPos = false
  45. print(changeXPos)
  46. end
  47. end
  48.  
  49.  
  50. SeedCount = Length*Width
  51.  
  52. function checkFirst()
  53. local x
  54. if robot.count([slot: 1])==0 then
  55. print("No seeds in first slot!")
  56. repeat
  57. sleep(1)
  58. until robot.count([slot: 1])>=1
  59. end
  60. end
  61.  
  62. function checkSeedCount()
  63. local SlotNum = 5
  64. local x
  65. local y = false
  66. SeedAmount = 0
  67. for x=1,SeedSlotAmount do
  68. if robot.count([slot: SlotNum])>0 then
  69. SeedAmount = robot.count([slot: SlotNum])
  70. elseif robot.count([slot: SlotNum])==0 then
  71. if robot.select([slot: SlotNum])<19 then
  72. repeat
  73. SlotNum=SlotNum+1
  74. robot.select([slot: SlotNum])
  75. sleep(0.5)
  76. until robot.select([slot: SlotNum])==19
  77. end
  78. if robot.select([slot: SlotNum])==19 then
  79. robot.select([slot: 19])
  80. end
  81. end
  82. if robot.count([slot: SlotNum])==0 and robot.select([slot: SlotNum])==19 then
  83. SlotNum = 1
  84. print("Out of seeds")
  85. repeat
  86. sleep(1)
  87. until robot.count([slot: SlotNum])>0
  88. robot.select([slot: 1])
  89. end
  90. end
  91. return SeedAmount
  92. end
  93.  
  94.  
  95. function doRefuel()
  96. local slotNum = 15
  97. local TurtleXPoss = TurtleXPos
  98. local TurtleYPoss = TurtleYPos
  99. local TurtleXPosss = TurtleXPos
  100. local TurtleYPosss = TurtleYPos
  101. local g
  102. local j
  103. local l
  104. local h
  105. local k
  106. local v
  107. local SlotNum2 = 15
  108. if turtle.getFuelLevel()<100 then
  109. if turtle.getItemCount(15)>0 then
  110. turtle.select(15)
  111. turtle.refuel()
  112. turtle.select(1)
  113. elseif turtle.getItemCount(15)==0 then
  114. if turtle.getItemCount(16)>0 then
  115. turtle.select(16)
  116. turtle.refuel()
  117. turtle.select(1)
  118. elseif turtle.getItemCount(16)==0 then
  119. turtle.select(15)
  120. if bit.band(TurtleYPoss, 1) == 0 then
  121. turtle.turnRight()
  122. else
  123. turtle.turnLeft()
  124. end
  125. for j=1,(TurtleYPosss-1) do
  126. turtle.forward()
  127. end
  128. turtle.turnLeft()
  129. for g=1,(TurtleXPosss-1) do
  130. turtle.forward()
  131. end
  132. turtle.up()
  133. turtle.select(15)
  134. if turtle.suck() == true then
  135. turtle.refuel(32)
  136. turtle.select(16)
  137. turtle.suck()
  138. turtle.refuel(32)
  139. else
  140. turtle.select(16)
  141. if turtle.suck() == true and turtle.refuel(32) == true then
  142. turtle.refuel(32)
  143. else
  144. turtle.select(15)
  145. print("Turtle is out of fuel. Please input fuel into the chest/turtle.")
  146. repeat
  147. sleep(1)
  148. until turtle.refuel() == true or turtle.suck() == true and turtle.refuel(32)
  149. turtle.refuel(32)
  150. turtle.select(1)
  151. end
  152. end
  153. turtle.down()
  154. turtle.turnRight()
  155. turtle.turnRight()
  156. for h=1,TurtleXPos-1 do
  157. turtle.forward()
  158. end
  159. turtle.turnRight()
  160. for k=1,TurtleYPos-1 do
  161. turtle.forward()
  162. end
  163. if bit.band(TurtleYPoss, 2) == 0 then
  164. turtle.turnLeft()
  165. else
  166. turtle.turnRight()
  167. end
  168. end
  169. end
  170. turtle.select(1)
  171. end
  172. end
  173.  
  174.  
  175. function doDelay()
  176. for l=1,Delay do
  177. sleep(60)
  178. end
  179. end
  180.  
  181. function checkFull()
  182. local ResourceSlotCount = SeedSlotAmount + 1
  183. local q
  184. local j
  185. local g
  186. local p
  187. local l
  188. local h
  189. local k
  190. local SlotNum = 2
  191. local SlotNum2 = ResourceSlotCount
  192. local TurtleXPoss = TurtleXPos
  193. local TurtleYPoss = TurtleYPos
  194. local TurtleXPosss = TurtleXPos
  195. local TurtleYPosss = TurtleYPos
  196. for q=2,14 do
  197. if SlotNum2>14 then
  198. SlotNum2 = 14
  199. end
  200. if turtle.getItemCount(SlotNum2)==64 then
  201. repeat
  202. SlotNum2=SlotNum2+1
  203. local itemCount=turtle.getItemCount(SlotNum2)
  204. until itemCount<64 or SlotNum2 == 15
  205. turtle.select(1)
  206. elseif SlotNum2==15 and turtle.getItemCount==64 then
  207. if bit.band(TurtleYPoss, 2) == 0 then
  208. turtle.turnRight()
  209. else
  210. turtle.turnLeft()
  211. end
  212. for j=1,TurtleYPoss-1 do
  213. turtle.forward()
  214. end
  215. turtle.turnLeft()
  216. for g=1,TurtleXPoss-1 do
  217. turtle.forward()
  218. end
  219. for l=ResourceSlotCount,13 do
  220. turtle.select(SlotNum)
  221. turtle.drop()
  222. SlotNum=SlotNum+1
  223. end
  224. turtle.turnRight()
  225. turtle.turnRight()
  226. for h=1,TurtleXPosss-1 do
  227. turtle.forward()
  228. end
  229. turtle.turnRight()
  230. for k=1,TurtleYPosss-1 do
  231. turtle.forward()
  232. end
  233. if bit.band(TurtleYPoss, 2) == 0 then
  234. turtle.turnLeft()
  235. else
  236. turtle.turnRight()
  237. end
  238. ResourceSlotCount=SeedSlotAmount+1
  239. turtle.select(1)
  240. end
  241. end
  242. end
  243.  
  244.  
  245. function goHome()
  246. local TurtleXPoss = TurtleXPos
  247. local TurtleYPoss = TurtleYPos
  248. local TurtleXPosss = TurtleXPos
  249. local TurtleYPosss = TurtleYPos
  250. local q
  251. local p
  252. local h
  253. local SlotNum = SeedSlotAmount+1
  254. local b
  255. local SlotNum2 = 2
  256. if bit.band(TurtleYPoss, 1) == 0 then
  257. turtle.turnRight()
  258. else
  259. turtle.turnLeft()
  260. end
  261. for q=1,TurtleYPosss-1 do
  262. turtle.forward()
  263. end
  264. turtle.turnLeft()
  265. for p=1,TurtleXPosss-1 do
  266. turtle.forward()
  267. end
  268. if FirstRun==true then
  269. for h=SeedSlotAmount,14 do
  270. turtle.select(SlotNum)
  271. turtle.drop(64)
  272. SlotNum=SlotNum+1
  273. if SlotNum==15 then
  274. SlotNum=1
  275. end
  276. end
  277. else
  278. for b=2,14 do
  279. turtle.select(SlotNum2)
  280. turtle.drop(64)
  281. SlotNum2=SlotNum2+1
  282. if SlotNum2==15 then
  283. SlotNum2=1
  284. end
  285. end
  286. end
  287. turtle.select(15)
  288. turtle.up()
  289. turtle.suck(64)
  290. turtle.refuel()
  291. turtle.select(16)
  292. turtle.suck(64)
  293. turtle.refuel()
  294. turtle.select(1)
  295. turtle.down()
  296. turtle.turnRight()
  297. turtle.turnRight()
  298. end
  299.  
  300.  
  301.  
  302.  
  303.  
  304. function lengthSpan()
  305. local p
  306. for LengthLoop = 1,Length-1 do
  307. if FirstRun == false then
  308. checkFull()
  309. else
  310. checkSeedCount()
  311. end
  312. doRefuel()
  313. turtle.digDown()
  314. turtle.placeDown()
  315. turtle.forward()
  316. if changeXPos == false then
  317. TurtleXPos = TurtleXPos+1
  318. print("Debug: TurtleXPos: "..TurtleXPos)
  319. elseif changeXPos == true then
  320. TurtleXPos = TurtleXPos-1
  321. print("Debug: TurtleXPos: "..TurtleXPos)
  322. end
  323. end
  324. end
  325.  
  326. function nextRow()
  327. if turnLeft == false then
  328. turtle.turnRight()
  329. turtle.digDown()
  330. turtle.placeDown()
  331. turtle.forward()
  332. turtle.turnRight()
  333. turnLeft = true
  334. TurtleYPos = TurtleYPos + 1
  335. print(TurtleYPos)
  336. elseif turnLeft == true then
  337. turtle.turnLeft()
  338. turtle.digDown()
  339. turtle.placeDown()
  340. turtle.forward()
  341. turtle.turnLeft()
  342. turnLeft = false
  343. TurtleYPos = TurtleYPos+1
  344. print(TurtleYPos)
  345. end
  346. end
  347.  
  348.  
  349.  
  350.  
  351.  
  352. function harvestLand()
  353. local q
  354. local l
  355. local slotNum=1
  356. checkFirst()
  357. for q=1,Width do
  358. lengthSpan()
  359. nextRow()
  360. changeReverseXPos()
  361. end
  362. goHome()
  363. doDelay()
  364. if FirstRun==true then
  365. FirstRun=false
  366. end
  367. end
  368. while true do
  369. harvestLand()
  370. end
Add Comment
Please, Sign In to add comment