Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. local component = require("component")
  2. local robot = require("robot")
  3. local computer = require("computer")
  4. local inv = component.inventory_controller
  5. local nav = component.navigation
  6. local geo = component.geolyzer
  7. local vector = require("vector")
  8. local side = require("sides")
  9. local slot = 1
  10. local startx, starty, startz = nav.getPosition()
  11.  
  12. local function harvest()
  13. if geo.analyze(0).growth == 1 then
  14. robot.swingDown()
  15. robot.suckDown()
  16. return true
  17. else
  18. return false
  19. end
  20. end
  21. local function plant()
  22. print("trying to plant")
  23. local slot = 1
  24. if inv.getStackInInternalSlot() then
  25. while not inv.getStackInInternalSlot().label == "Seeds" do
  26. if not slot == 16 then
  27. slot = slot + 1
  28. else
  29. slot = 1
  30. end
  31. robot.select(slot)
  32. end
  33. end
  34. if inv.getStackInInternalSlot(slot) then
  35. if inv.getStackInInternalSlot(slot).label == "Seeds" then
  36. inv.equip()
  37. robot.placeDown()
  38. return true
  39.  
  40. else
  41. return false
  42. end
  43. end
  44. return true
  45. end
  46. local function faceNorth()
  47. local face = nav.getFacing()
  48. if not face == 2 then
  49. elseif face == 3 then
  50. robot.turnRight()
  51. robot.turnRight()
  52. elseif face == 4 then
  53. robot.turnRight()
  54. elseif face == 5 then
  55. robotapi.turnLeft()
  56. else
  57. return false
  58. end
  59. return true
  60. end
  61. local function faceSouth()
  62. local face = nav.getFacing()
  63. if not face == 3 then
  64. elseif face == 2 then
  65. robot.turnAround()
  66. elseif face == 5 then
  67. robot.turnRight()
  68. elseif face == 4 then
  69. robot.turnLeft()
  70. else
  71. return false
  72. end
  73. return true
  74. end
  75. local function faceEast()
  76. local face = nav.getFacing()
  77. if not face == 5 then
  78. print("Faces East")
  79. elseif face == 4 then
  80. robot.turnAround()
  81. elseif face == 2 then
  82. robot.turnRight()
  83. elseif face == 3 then
  84. robot.turnLeft()
  85. else
  86. return false
  87. end
  88. return true
  89. end
  90. local function faceWest()
  91. local face = nav.getFacing()
  92. if not face == 4 then
  93. elseif face == 5 then
  94. robot.turnAround()
  95. elseif face == 3 then
  96. robot.turnRight()
  97. elseif face == 2 then
  98. robot.turnLeft()
  99. else
  100. return false
  101. end
  102. return true
  103. end
  104. local function goThere(gox, goz)
  105. local beginx, beginy, beginz = nav.getPosition()
  106. if beginx < gox then
  107. repeat
  108. faceEast()
  109. robot.forward()
  110. until beginx == gox
  111. elseif beginx > gox then
  112. repeat
  113. faceWest()
  114. robot.forward()
  115. until beginx == gox
  116. end
  117. if beginz < goz then
  118. repeat
  119. faceSouth()
  120. robot.forward()
  121. until beginz == goz
  122. elseif beginz > goz then
  123. repeat
  124. faceNorth()
  125. robot.forward()
  126. until beginz == goz
  127. end
  128. return true
  129. end
  130. local function charge()
  131. gothere(startx, startz)
  132. faceNorth()
  133. local shestside = checkChestSide()
  134. local chestsize = getInventorySize(chestside)
  135. local slot = 0
  136. while not slot == chestsize do
  137. slot = slot + 1
  138. select(slot)
  139. dropIntoSlot(chestside, slot)
  140. end
  141. while not computer.energy == computer.maxEnergy do
  142. os.sleep(100)
  143. end
  144. end
  145. local function chargeTest()
  146. local charge = tonumber(computer.energy())
  147. local invslot = 0
  148. local freeslots = robot.inventorySize()
  149. local slot = 1
  150. if charge / tonumber(computer.maxEnergy()) <= 0.1 then
  151. charge()
  152. return true
  153. else
  154. repeat
  155. slot = slot + 1
  156. robot.select(slot)
  157. if robot.count(slot) ~= 0 then
  158. freeslots = freeslots -1
  159. end
  160.  
  161. until slot == robot.inventorySize()
  162. if freeslots <= 2 then
  163. charge()
  164. return true
  165. end
  166. end
  167. end
  168. local function checkChestSide()
  169. local chestSide
  170. faceNorth()
  171. if not getInventorySize(0) == "no inventory" then
  172. chestSide = 0
  173. elseif not getInventorySize(1) == "no inventory" then
  174. chestSide = 1
  175. elseif not getInventorySize(2) == "no inventory" then
  176. chestSide = 2
  177. elseif not getInventorySize(3) == "no inventory" then
  178. chestSide = 3
  179. elseif not getInventorySize(4) == "no inventory" then
  180. chestSide = 4
  181. elseif not getInventorySize(5) == "no inventory" then
  182. chestSide = 5
  183. end
  184. return chestSide
  185. end
  186. local function farm(fieldsize)
  187. faceNorth()
  188. local endx = startx + fieldsize -1
  189. local endz = startz - fieldsize -1
  190. local currentx = startx
  191. local currentz = startz
  192. local currenty = 0
  193.  
  194. repeat
  195. if not currentx == startx then
  196. faceNorth()
  197. robot.forward()
  198. end
  199. while not currentx == startx do
  200. faceEast()
  201. robot.forward()
  202. currentx, currenty, currentz = nav.getPosition()
  203. end
  204. repeat
  205. harvest()
  206. plant()
  207. faceEast()
  208. robot.forward()
  209. currentx, currenty, currentz = nav.getPosition()
  210. until currentx == endx
  211. chargeTest()
  212. until currentz == endz
  213. charge()
  214. end
  215.  
  216. print("Enter Field Size: ")
  217. local fieldsizein = tonumber(io.read())
  218. while true do
  219. farm(fieldsizein)
  220. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement