SHARE
TWEET

Untitled

Floke900 Jun 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. -- main program
  154. function main()
  155.   refuel()
  156.   local fuelBegin = turtle.getFuelLevel()
  157.   if fuelBegin < 200 then
  158.     print("Not enough fuel left.")
  159.     return
  160.   end
  161.  
  162.   tillEightByEight()
  163.   searchForHarvestedSeeds()
  164.   unload()
  165.  
  166.   local fuelEnd = turtle.getFuelLevel()
  167.   print("fuel consumed: "..(fuelBegin - fuelEnd))
  168.   os.sleep(1)
  169. end
  170.  
  171. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top