Advertisement
buffsovernexus

Untitled

May 12th, 2019
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1. --[[
  2.  
  3. FarmerBot v1.0.0
  4.  
  5. Guide
  6. -----------------
  7. Crops: Wheat
  8. -----------------
  9.  
  10. Goals:
  11. Farm down a line of crops and constantly check the crops.
  12.  
  13. 2.0 Goals:
  14. - Allow multiple bots at the same time (designating their name in logs)
  15. - Attempt to till the ground below it (excluding water)
  16. - Add more crops
  17. ]]--
  18.  
  19. -- Globals --
  20. local crops = {
  21. { id = 1, mature = 7, name = "minecraft:carrots", seed = "minecraft:carrot", label = "Carrots" },
  22. { id = 2, mature = 7, name = "minecraft:wheat", seed = "minecraft:wheat_seeds", label = "Wheat" },
  23. { id = 3, mature = 7, name = "minecraft:potatoes", seed = "minecraft:potato", label = "Potatoes" },
  24. { id = 4, mature = 7, name = "magicalcrops:MinicioCrop", seed = "magicalcrops:MinicioSeeds", label = "Minicio" },
  25. { id = 5, mature = 7, name = "magicalcrops:FireCrop", seed = "magicalcrops:FireSeeds", label = "Fire" },
  26. { id = 6, mature = 7, name = "magicalcrops:SheepCrop", seed = "magicalcrops:SheepSeeds", label = "Sheep" },
  27. { id = 7, mature = 7, name = "magicalcrops:NatureCrop", seed = "magicalcrops:NatureSeeds", label = "Nature" },
  28. { id = 8, mature = 7, name = "magicalcrops:FluixCrop", seed = "magicalcrops:FluixSeeds", label = "Fluix" },
  29. { id = 9, mature = 7, name = "magicalcrops:QuartzCrop", seed = "magicalcrops:QuartzSeeds", label = "Quartz" },
  30. { id = 10, mature = 7, name = "magicalcrops:WaterCrop", seed = "magicalcrops:WaterSeeds", label = "Water" },
  31. { id = 11, mature = 7, name = "magicalcrops:NetherCrop", seed = "magicalcrops:NetherSeeds", label = "Nether" },
  32. { id = 12, mature = 7, name = "magicalcrops:EarthCrop", seed = "magicalcrops:EarthSeeds", label = "Earth" },
  33. { id = 13, mature = 7, name = "magicalcrops:DiamondCrop", seed = "magicalcrops:DiamondSeeds", label = "Diamond" }
  34. }
  35.  
  36. -- [[ START PLAYER INPUT ]]--
  37. local input = { rows = 0, length = 0, crop = 0 }
  38.  
  39. term.write("Enter number of rows (left): ")
  40. input.rows = tonumber(read())
  41. term.clear()
  42. term.write("Enter in length of row (forward): ")
  43. input.length = tonumber(read())
  44. term.clear()
  45. for k,v in pairs (crops) do
  46. print("#" .. v.id .. " - " .. label)
  47. end
  48. term.write("Enter crop ID for seeding: ")
  49. input.crop = tonumber(read())
  50. term.clear()
  51.  
  52. -- [[ END PLAYER INPUT ]]--
  53. rednet.send(12, "----- Bot #" .. os.getComputerID() .. " Task -----", "bttp")
  54. rednet.send(12, "Size: " .. input.rows .. "x" .. input.length, "bttp")
  55.  
  56. -- Helper Function: Determine if the crop is fully developed. If not, alert the user.
  57. function isGrown(row, length, current, expected)
  58. if current == expected then
  59. return true
  60. end
  61. return false
  62. end
  63.  
  64. -- Helper Function: Determines if the crop ID has any seeds for said crop. Selects seed if true.
  65. function hasSeeds(id)
  66. for k,v in pairs(crops) do
  67. if v.id == id then
  68. for i = 1, 16 do
  69. local data = turtle.getItemDetail(i)
  70. if data ~= nil then
  71. if data.name == v.seed then
  72. turtle.select(i)
  73. return true
  74. end
  75. end
  76. end
  77. end
  78. end
  79. return false
  80. end
  81.  
  82. --refueling
  83. function refuel(level)
  84. for i = 1, 16 do
  85. if turtle.getFuelLevel() > level then
  86. break
  87. end
  88. turtle.select(i)
  89. if refuel(0) then
  90. turtle.refuel(turtle.getItemCount())
  91. end
  92. end
  93. end
  94.  
  95. function dropItems()
  96. for i = 16,1,-1 do
  97. turtle.select(i)
  98. turtle.dropDown()
  99. end
  100. end
  101.  
  102. -- Network Handling (modem on right)
  103. if rednet.isOpen("right") then
  104. rednet.send(12, "[Bot #" .. os.getComputerID() .. "] Connected to modem!", "bttp")
  105. else
  106. rednet.open("right")
  107. rednet.send(12, "[Bot #" .. os.getComputerID() .. "] Turning on modem...", "bttp")
  108. rednet.send(12, "[Bot #" .. os.getComputerID() .. "] Connected successfully!", "bttp")
  109. end
  110.  
  111. -- 2.0 Function: Attempt to fix an un-tilled grass block
  112. function fixBlock()
  113. turtle.digDown()
  114. if hasSeeds(input.crop) then
  115. turtle.placeDown()
  116. end
  117. end
  118.  
  119. -- Preface: Determine if the bot was placed on the ground. If so, go up one block.
  120. if turtle.detectDown() then
  121. turtle.up()
  122. turtle.forward()
  123. end
  124.  
  125. --[[ START FARMING TASK ]]--
  126. while true do
  127. -- Start farming the area.
  128. for i = 1, input.rows do
  129.  
  130. for j = 1, input.length do
  131. -- Check status of current crop.
  132. if turtle.detectDown() then
  133. --There is something below. Determine if it is something we can handle.
  134. local success, data = turtle.inspectDown()
  135. if success then
  136. for k,v in pairs(crops) do
  137. if data.name == v.name then
  138. if isGrown(i,j,data.metadata,v.mature) then
  139. --Break the block... Then replace...
  140. turtle.digDown()
  141. turtle.suckDown() -- Pick up the local crop.
  142. local curpos = turtle.getSelectedSlot();
  143. if hasSeeds(v.id) then
  144. turtle.placeDown()
  145. else
  146. rednet.send(12, "[Bot #" .. os.getComputerID() .. "] No seeds for " .. v.label .. " @ (" .. i .. "," .. j .. ")", "bttp")
  147. end
  148. turtle.select(curpos)
  149. end
  150. end
  151. end
  152. else
  153. rednet.send(12, "[Bot #" .. os.getComputerID() .. "] ERROR: No Block @ (" .. i .. "," .. j .. ")", "bttp")
  154. end
  155. else
  156. fixBlock()
  157. end
  158.  
  159. -- Go forward one to continue.
  160. if j < input.length then
  161. turtle.forward()
  162. end
  163. end
  164. os.sleep(3)
  165. -- Done reviewing the row. Now move to new row.
  166. local isEven = i % 2 == 0
  167. if isEven == false then
  168. turtle.turnLeft()
  169. turtle.forward()
  170. turtle.turnLeft()
  171. else
  172. turtle.turnRight()
  173. turtle.forward()
  174. turtle.turnRight()
  175. end
  176. end
  177. os.sleep(5)
  178.  
  179. -- Go back to start where chest is.
  180. if input.rows % 2 == 1 then
  181. for k = 1, input.length do
  182. turtle.forward()
  183. end
  184. else
  185. turtle.turnLeft()
  186. turtle.turnLeft()
  187. turtle.forward()
  188. end
  189. turtle.turnLeft()
  190. for l = 1, input.rows do
  191. turtle.forward()
  192. end
  193. turtle.turnLeft()
  194.  
  195. -- Drop items in hopper below.
  196. turtle.down()
  197.  
  198. os.sleep(2)
  199. local needs = input.rows * input.length + input.rows + input.length + 2
  200. refuel(needs)
  201. dropItems()
  202. os.sleep(300)
  203.  
  204. turtle.up()
  205.  
  206. turtle.forward()
  207. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement