Advertisement
buffsovernexus

Untitled

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