Advertisement
buffsovernexus

FarmBot v1.0.1

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