Advertisement
buffsovernexus

Untitled

May 11th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 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. }
  27.  
  28. -- Helper Function: Determine if the crop is fully developed. If not, alert the user.
  29. function isGrown(row, length, current, expected)
  30. rednet.send(12, "[FarmBot] Crop (" .. row .. "," .. length .. ") status: " .. tonumber(string.format("%.3f", (current/expected) * 100)) .. "%", "bttp")
  31. if current == expected then
  32. return true
  33. end
  34. return false
  35. end
  36.  
  37. -- Helper Function: Determines if the crop ID has any seeds for said crop. Selects seed if true.
  38. function hasSeeds(id)
  39. for k,v in pairs(crops) do
  40. if v.id == id then
  41. for i = 1, 16 do
  42. local data = turtle.getItemDetail(i)
  43. if data.name == v.seed then
  44. turtle.select(i)
  45. return true
  46. end
  47. end
  48. end
  49. end
  50. return false
  51. end
  52.  
  53. function dropItems()
  54. for i = 16,1,-1 do
  55. turtle.select(i)
  56. turtle.dropDown()
  57. end
  58. end
  59.  
  60. -- 2.0 Function: Attempt to fix an un-tilled grass block and place a seed.
  61. function fixBlock()
  62. turtle.digDown()
  63. if hasSeeds(input.crop) then
  64. turtle.placeDown()
  65. end
  66. end
  67.  
  68. -- Network Handling (modem on right)
  69. if rednet.isOpen("right") then
  70. rednet.send(12, "[FarmBot] Connected to modem!", "bttp")
  71. else
  72. rednet.open("right")
  73. rednet.send(12, "[FarmBot] Turning on modem...", "bttp")
  74. rednet.send(12, "[FarmBot] Connected successfully!", "bttp")
  75. end
  76.  
  77.  
  78. -- Player Input
  79. local input = { rows = 0, length = 0, crop = 0 }
  80.  
  81. -- Ask player for input
  82. term.write("Please enter number of rows: ")
  83. input.rows = tonumber(read())
  84. term.write("Please enter in length of row: ")
  85. input.length = tonumber(read())
  86. --Display all of the crops.
  87. for k,v in pairs(crops) do
  88. print("#" .. tostring(v.id) .. " - " .. v.label)
  89. end
  90. term.write("Please enter in the crop ID to replace: ")
  91. input.crop = tonumber(read())
  92.  
  93. rednet.send(12, "[FarmBot] Farming " .. input.rows .. "x" .. input.length .. " sized farm.", "bttp")
  94.  
  95. -- Preface: Determine if the bot was placed on the ground. If so, go up one block.
  96. if turtle.detectDown() then
  97. turtle.up()
  98. turtle.forward()
  99. end
  100.  
  101. while true do
  102.  
  103. -- Start farming the area.
  104. for i = 1, input.rows do
  105.  
  106. for j = 1, input.length do
  107. -- Check status of current crop.
  108. if turtle.detectDown() then
  109. --There is something below. Determine if it is something we can handle.
  110. local success, data = turtle.inspectDown()
  111. if success then
  112. for k,v in pairs(crops) do
  113. if data.name == v.name then
  114. if isGrown(i,j,data.metadata,v.mature) then
  115. --Break the block... Then replace...
  116. turtle.digDown()
  117. turtle.suckDown() -- Pick up the local crop.
  118. if hasSeeds(v.id) then
  119. turtle.placeDown()
  120. else
  121. rednet.send(12, "[FarmBot] Unable to find seed for " .. v.label .. " (" .. i .. "," .. j .. ")", "bttp")
  122. end
  123. end
  124. end
  125. end
  126. else
  127. rednet.send(12, "[FarmBot] Cannot read block (" .. i .. "," .. j .. ")", "bttp")
  128. end
  129. else
  130. rednet.send(12, "[FarmBot] Seeding block (" .. i .. "," .. j .. ")", "bttp")
  131. fixBlock()
  132. end
  133.  
  134. -- Go forward one to continue.
  135. if j < input.length then
  136. turtle.forward()
  137. end
  138. end
  139. os.sleep(3)
  140. -- Done reviewing the row. Now move to new row.
  141. local isEven = i % 2 == 0
  142. if isEven == false then
  143. turtle.turnLeft()
  144. turtle.forward()
  145. turtle.turnLeft()
  146. else
  147. turtle.turnRight()
  148. turtle.forward()
  149. turtle.turnRight()
  150. end
  151. end
  152. rednet.send(12, "[FarmBot] Resetting back to start.", "bttp")
  153. os.sleep(5)
  154.  
  155. -- Go back to start where chest is.
  156. for k = 1, input.length do
  157. turtle.forward()
  158. end
  159. turtle.turnLeft()
  160. for l = 1, input.rows do
  161. turtle.forward()
  162. end
  163. turtle.turnLeft()
  164.  
  165. -- Drop items in hopper below.
  166. turtle.down()
  167. os.sleep(2)
  168. dropItems()
  169. os.sleep(2)
  170. turtle.up()
  171.  
  172. turtle.forward()
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement