SirSheepe

Untitled

Feb 23rd, 2018
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --xKLNbmuK
  2. -- Utilities
  3.  
  4. function sleep(s)
  5. local ntime = os.time() + s
  6. repeat until os.time() > ntime
  7. end
  8.  
  9. function countItem(id, damage)
  10. damage = damage or 0
  11. local count = 0
  12. for i = 1, 16 do
  13. local data = turtle.getItemDetail(i)
  14. if data then
  15. if data.name == id and data.damage == damage then
  16. count = count + data.count
  17. end
  18. end
  19. end
  20. return count
  21. end
  22.  
  23. function findItem(id, damage)
  24. damage = damage or 0
  25. for i = 1, 16 do
  26. local data = turtle.getItemDetail(i)
  27. if data then
  28. if data.name == id and data.damage == damage then
  29. return i
  30. end
  31. end
  32. end
  33. return -1
  34. end
  35.  
  36. local fuelSource = "minecraft:coal"
  37. local donePercent = 0
  38. local c = 0
  39.  
  40. -- Turtle Wrapper
  41.  
  42. local Turtle = {}
  43.  
  44. function Turtle.refuel()
  45. local a = turtle.getFuelLevel()
  46. turtle.select(findItem(fuelSource))
  47. turtle.refuel(1)
  48. local b = turtle.getFuelLevel()
  49. local increase = b - a
  50.  
  51. for i = 1, math.floor((100-increase)/increase) do
  52. if countItem(fuelSource) > 0 then
  53. turtle.refuel(1)
  54. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;4; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  55. end
  56. end
  57. end
  58.  
  59. function Turtle.up()
  60. if turtle.getFuelLevel() >= 1 then
  61. local success = turtle.up()
  62. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  63. return success
  64. else
  65. local fuelCount = countItem(fuelSource)
  66.  
  67. if fuelCount >= 1 then
  68. Turtle.refuel()
  69. return Turtle.up()
  70. else
  71. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Fuel Needed;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  72. exit()
  73. return false
  74. end
  75. end
  76. end
  77.  
  78. function Turtle.down()
  79. if turtle.getFuelLevel() >= 1 then
  80. local success = turtle.down()
  81. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  82. return success
  83. else
  84. local fuelCount = countItem(fuelSource)
  85.  
  86. if fuelCount > 0 then
  87. Turtle.refuel()
  88. return Turtle.down()
  89. else
  90. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Fuel Needed;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  91. exit()
  92. return false
  93. end
  94. end
  95. end
  96.  
  97. function Turtle.forward()
  98. if turtle.getFuelLevel() >= 1 then
  99. local success = turtle.forward()
  100. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  101. return success
  102. else
  103. local fuelCount = countItem(fuelSource)
  104.  
  105. if fuelCount > 0 then
  106. Turtle.refuel()
  107. return Turtle.forward()
  108. else
  109. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Fuel Needed;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  110. exit()
  111. return false
  112. end
  113. end
  114. end
  115.  
  116. function Turtle.back()
  117. if turtle.getFuelLevel() >= 1 then
  118. local success = turtle.back()
  119. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  120. return success
  121. else
  122. local fuelCount = countItem(fuelSource)
  123.  
  124. if fuelCount > 0 then
  125. Turtle.refuel()
  126. return Turtle.back()
  127. else
  128. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Fuel Needed;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  129. exit()
  130. return false
  131. end
  132. end
  133. end
  134.  
  135. function Turtle.right()
  136. if turtle.getFuelLevel() >= 1 then
  137. local success = turtle.turnRight()
  138. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  139. if success and Turtle.forward() then
  140. turtle.turnLeft()
  141. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  142. return true
  143. elseif not success then
  144. return false
  145. else
  146. turtle.turnLeft()
  147. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  148. return false
  149. end
  150. else
  151. local fuelCount = countItem(fuelSource)
  152.  
  153. if fuelCount > 0 then
  154. Turtle.refuel()
  155. return Turtle.right()
  156. else
  157. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Fuel Needed;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  158. exit()
  159. return false
  160. end
  161. end
  162. end
  163.  
  164. function Turtle.left()
  165. if turtle.getFuelLevel() >= 1 then
  166. local success = turtle.turnLeft()
  167. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  168. if success and Turtle.forward() then
  169. turtle.turnRight()
  170. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  171. return true
  172. elseif not success then
  173. return false
  174. else
  175. turtle.turnRight()
  176. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  177. return false
  178. end
  179. else
  180. local fuelCount = countItem(fuelSource)
  181.  
  182. if fuelCount > 0 then
  183. Turtle.refuel()
  184. return Turtle.left()
  185. else
  186. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Fuel Needed;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  187. exit()
  188. return false
  189. end
  190. end
  191. end
  192.  
  193.  
  194. function Turtle.placeUp(id, countUp, damage)
  195. if countItem(id, damage) > 0 then
  196. local slot = findItem(id, damage)
  197. turtle.select(slot)
  198. local success = turtle.placeUp()
  199. if success and countUp then
  200. c = c + 1
  201. end
  202. return success
  203. else
  204. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Not enough "..id.." ("..damage..");", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  205. exit()
  206. return false
  207. end
  208. end
  209.  
  210.  
  211. function Turtle.repeatMethod(method, n)
  212. if turtle.getFuelLevel() >= 1 then
  213. for i = 1, n do
  214. local success = Turtle[method]()
  215. if not success then
  216. break
  217. end
  218. end
  219. else
  220. local fuelCount = countItem(fuelSource)
  221.  
  222. if fuelCount > 0 then
  223. Turtle.refuel()
  224. return Turtle.repeatMethod(method, n)
  225. else
  226. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Fuel Needed;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  227. exit()
  228. return false
  229. end
  230. end
  231. end
  232.  
  233. -- Main thread
  234.  
  235. function makeFarmPlot(n)
  236.  
  237. if countItem("AgriCraft:waterChannel") < (80 * (n or 1)) then
  238. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Not enough water channels (%d Missing);", turtle.getFuelLevel(), turtle.getFuelLimit(), (80 * (n or 1)) - countItem("AgriCraft:waterChannel"))..tostring(donePercent))
  239. return
  240. end
  241.  
  242. if countItem("AgriCraft:waterTank") < (n or 1) then
  243. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Not enough water tanks (%d Missing);", turtle.getFuelLevel(), turtle.getFuelLimit(), (n or 1) - countItem("AgriCraft:waterTank"))..tostring(donePercent))
  244. return
  245. end
  246.  
  247. if countItem("AgriCraft:sprinkler") < (80 * (n or 1)) then
  248. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Not enough sprinklers (%d Missing);", turtle.getFuelLevel(), turtle.getFuelLimit(), (80 * (n or 1)) - countItem("AgriCraft:sprinkler"))..tostring(donePercent))
  249. return
  250. end
  251.  
  252. c = 0
  253.  
  254. Turtle.up()
  255. Turtle.up()
  256.  
  257.  
  258. for i = 1, (n or 1) do
  259.  
  260. if i == 1 then
  261. turtle.turnRight()
  262. end
  263. Turtle.repeatMethod("forward", 4)
  264. turtle.turnLeft()
  265.  
  266. Turtle.forward()
  267. Turtle.placeUp("AgriCraft:waterChannel", true)
  268.  
  269. for i = 1, 5 do
  270.  
  271. for i = 1, 8 do
  272. Turtle.forward()
  273. if (c % 161) == 40 then
  274. Turtle.placeUp("AgriCraft:waterTank", true)
  275. else
  276. Turtle.placeUp("AgriCraft:waterChannel", true)
  277. end
  278. donePercent = c / (161 * (n or 1))
  279. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  280. end
  281.  
  282. turtle.turnLeft()
  283. Turtle.forward()
  284. turtle.turnLeft()
  285.  
  286. if i ~= 5 then
  287.  
  288. Turtle.placeUp("AgriCraft:waterChannel", true)
  289.  
  290. for i = 1, 8 do
  291. Turtle.forward()
  292. if (c % 161) == 40 then
  293. Turtle.placeUp("AgriCraft:waterTank", true)
  294. else
  295. Turtle.placeUp("AgriCraft:waterChannel", true)
  296. end
  297. donePercent = c / (161 * (n or 1))
  298. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  299. end
  300.  
  301. turtle.turnRight()
  302. Turtle.forward()
  303. turtle.turnRight()
  304.  
  305. Turtle.placeUp("AgriCraft:waterChannel", true)
  306.  
  307. end
  308.  
  309. end
  310.  
  311. Turtle.repeatMethod("forward", 9)
  312. turtle.turnLeft()
  313. Turtle.repeatMethod("forward", 9)
  314. turtle.turnLeft()
  315. Turtle.down()
  316.  
  317. Turtle.forward()
  318. Turtle.placeUp("AgriCraft:sprinkler", true)
  319.  
  320. for i = 1, 5 do
  321.  
  322. for i = 1, 8 do
  323. Turtle.forward()
  324. Turtle.placeUp("AgriCraft:sprinkler", true)
  325. donePercent = c / (161 * (n or 1))
  326. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  327. end
  328.  
  329. turtle.turnLeft()
  330. Turtle.forward()
  331. turtle.turnLeft()
  332.  
  333. if i ~= 5 then
  334.  
  335. Turtle.placeUp("AgriCraft:sprinkler", true)
  336.  
  337. for i = 1, 8 do
  338. Turtle.forward()
  339. Turtle.placeUp("AgriCraft:sprinkler", true)
  340. donePercent = c / (161 * (n or 1))
  341. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  342. end
  343.  
  344. turtle.turnRight()
  345. Turtle.forward()
  346. turtle.turnRight()
  347.  
  348. Turtle.placeUp("AgriCraft:sprinkler", true)
  349.  
  350. end
  351.  
  352. end
  353.  
  354. Turtle.repeatMethod("forward", 9)
  355. turtle.turnLeft()
  356. Turtle.up()
  357. Turtle.repeatMethod("forward", 5)
  358.  
  359. if i == (n or 1) then
  360. turtle.turnLeft()
  361. Turtle.repeatMethod("down", 2)
  362. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;2; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  363. else
  364. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;5; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  365. Turtle.repeatMethod("forward", 12)
  366. end
  367.  
  368. end
  369.  
  370. end
  371.  
  372. function addSprinklers(n)
  373.  
  374. if countItem("AgriCraft:sprinkler") < (80 * (n or 1)) then
  375. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;3;Not enough sprinklers (%d Missing);", turtle.getFuelLevel(), turtle.getFuelLimit(), (80 * (n or 1)) - countItem("AgriCraft:sprinkler"))..tostring(donePercent))
  376. return
  377. end
  378.  
  379. c = 0
  380.  
  381. for i = 1, n do
  382.  
  383. if i == 1 then
  384. turtle.turnRight()
  385. end
  386. Turtle.repeatMethod("forward", 4)
  387. turtle.turnLeft()
  388. Turtle.down()
  389.  
  390. Turtle.forward()
  391. Turtle.placeUp("AgriCraft:sprinkler", true)
  392.  
  393. for i = 1, 5 do
  394.  
  395. for i = 1, 8 do
  396. Turtle.forward()
  397. Turtle.placeUp("AgriCraft:sprinkler", true)
  398. donePercent = c / (80 * (n or 1))
  399. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  400. end
  401.  
  402. turtle.turnLeft()
  403. Turtle.forward()
  404. turtle.turnLeft()
  405.  
  406. if i ~= 5 then
  407.  
  408. Turtle.placeUp("AgriCraft:sprinkler", true)
  409.  
  410. for i = 1, 8 do
  411. Turtle.forward()
  412. Turtle.placeUp("AgriCraft:sprinkler", true)
  413. donePercent = c / (80 * (n or 1))
  414. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;1; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  415. end
  416.  
  417. turtle.turnRight()
  418. Turtle.forward()
  419. turtle.turnRight()
  420.  
  421. Turtle.placeUp("AgriCraft:sprinkler", true)
  422.  
  423. end
  424.  
  425. end
  426.  
  427. Turtle.repeatMethod("forward", 9)
  428. turtle.turnLeft()
  429. Turtle.up()
  430. Turtle.repeatMethod("forward", 5)
  431.  
  432. if i == (n or 1) then
  433. turtle.turnLeft()
  434. Turtle.repeatMethod("down", 2)
  435. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;2; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  436. else
  437. peripheral.call("right", "transmit", 3, 1, string.format("%d;%d;5; ;", turtle.getFuelLevel(), turtle.getFuelLimit())..tostring(donePercent))
  438. Turtle.repeatMethod("forward", 12)
  439. end
  440.  
  441. end
  442.  
  443. end
  444.  
  445. addSprinklers(8)
RAW Paste Data