Advertisement
Floke900

Untitled

Jun 25th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. -- can only harvest wheat.
  2. -- will automatically turn dirt into farmland.
  3. -- farm size has to be 8x8, no water in this area.
  4. -- place turtle on the left side of an edge, one block above ground.
  5. -- place a chest under the turtle, it will fill it.
  6. -- place seeds in the four top slots. in every slot should be at least one seed to prevent bugs.
  7. -- place fuel in the botton right slot.
  8.  
  9.  
  10. seedsSlots = {1, 2, 3, 4}
  11. harvestSlots = {5, 6, 7, 8, 9, 10, 11, 12}
  12. fuelSlot = 16
  13. wheat = {name = 'minecraft:wheat', metadata = 7}
  14.  
  15.  
  16. function findSlotWithSpace()
  17. for i = 1, #harvestSlots do
  18. turtle.select(harvestSlots[i])
  19. if turtle.getItemSpace() > 0 then
  20. return true
  21. end
  22. end
  23. return false
  24. end
  25.  
  26. function findSlotWithSeeds()
  27. for i = 1, #seedsSlots do
  28. turtle.select(seedsSlots[i])
  29. if turtle.getItemCount() > 0 then
  30. turtle.placeDown()
  31. return true
  32. end
  33. end
  34. return false
  35. end
  36.  
  37. function searchForHarvestedSeeds()
  38. for i = 1, #harvestSlots do
  39. turtle.select(harvestSlots[i])
  40. local item = turtle.getItemDetail()
  41. if item ~= nil and item.name == "minecraft:wheat_seeds" then
  42. for i = 1, #seedsSlots do
  43. turtle.transferTo(seedsSlots[i])
  44. end
  45. end
  46. end
  47. end
  48.  
  49. function harvestAndPlant()
  50. local success,data = turtle.inspectDown()
  51.  
  52. if success == false then -- nothing found
  53. turtle.digDown() -- changes grass to farmland
  54. else
  55. if data.name ~= wheat.name or data.metadata ~= wheat.metadata then
  56. return
  57. end
  58. findSlotWithSpace()
  59. turtle.digDown()
  60. end
  61.  
  62. if not findSlotWithSeeds() then
  63. searchForHarvestedSeeds()
  64. findSlotWithSeeds()
  65. end
  66. turtle.placeDown()
  67. end
  68.  
  69. function forwardAndHarvest(n)
  70. for i = 1, n do
  71. turtle.forward()
  72. harvestAndPlant()
  73. end
  74. end
  75.  
  76. function tillEightByEight()
  77. -- line 1 and turn
  78. forwardAndHarvest(8)
  79. turtle.turnRight()
  80. forwardAndHarvest(1)
  81. turtle.turnRight()
  82. -- line 2 and turn
  83. forwardAndHarvest(7)
  84. turtle.turnLeft()
  85. forwardAndHarvest(1)
  86. turtle.turnLeft()
  87. -- line 3 and turn
  88. forwardAndHarvest(7)
  89. turtle.turnRight()
  90. forwardAndHarvest(1)
  91. turtle.turnRight()
  92. -- line 4 and turn
  93. forwardAndHarvest(7)
  94. turtle.turnLeft()
  95. forwardAndHarvest(1)
  96. turtle.turnLeft()
  97. -- line 5 and turn
  98. forwardAndHarvest(7)
  99. turtle.turnRight()
  100. forwardAndHarvest(1)
  101. turtle.turnRight()
  102. -- line 6 and turn
  103. forwardAndHarvest(7)
  104. turtle.turnLeft()
  105. forwardAndHarvest(1)
  106. turtle.turnLeft()
  107. -- line 7 and turn
  108. forwardAndHarvest(7)
  109. turtle.turnRight()
  110. forwardAndHarvest(1)
  111. turtle.turnRight()
  112. -- line 8
  113. forwardAndHarvest(7)
  114. -- move to chest
  115. turtle.turnRight()
  116. for i = 1, 7 do
  117. turtle.forward()
  118. end
  119. turtle.turnLeft()
  120. turtle.forward()
  121. turtle.turnLeft()
  122. turtle.turnLeft()
  123. end
  124.  
  125. function unload()
  126. local seeds = 0
  127. local wheat = 0
  128. for i = 1, #harvestSlots do
  129. turtle.select(harvestSlots[i])
  130. local item = turtle.getItemDetail()
  131. if item ~= nil then
  132. if item.name == "minecraft:wheat_seeds" then
  133. seeds = seeds + getItemCount()
  134. elseif item.name == "minecraft:wheat" then
  135. wheat = wheat + getItemCount()
  136. else
  137. print(item.name)
  138. end
  139. turtle.dropDown()
  140. end
  141. end
  142. print(seeds.." seeds harvested")
  143. print(wheat.." wheat harvested")
  144. end
  145.  
  146. function refuel()
  147. if turtle.getFuelLevel() < turtle.getFuelLimit() then
  148. turtle.select(fuelSlot)
  149. turtle.refuel()
  150. end
  151. end
  152.  
  153. 'minecraft:wheat'
  154. if item ~= nil and item.name == "minecraft:wheat_seeds" then
  155.  
  156. -- main program
  157. function main()
  158. refuel()
  159. local fuelBegin = turtle.getFuelLevel()
  160. if fuelBegin < 200 then
  161. print("Not enough fuel left.")
  162. return
  163. end
  164.  
  165. tillEightByEight()
  166. searchForHarvestedSeeds()
  167. unload()
  168.  
  169. local fuelEnd = turtle.getFuelLevel()
  170. print("fuel consumed: "..(fuelBegin - fuelEnd))
  171. os.sleep(1)
  172. end
  173.  
  174. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement