Advertisement
Guest User

Untitled

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