Advertisement
Guest User

InfiniteFarm

a guest
May 20th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. Fuel = 16
  2. FARMHIGHT = 5
  3. CLUSTERS = 3
  4. -- Edit values above to suit your needs
  5. function megaSuck()
  6.     for b=1,3,1 do
  7.         turtle.suck()
  8.     end
  9. end -- suck 3 times to avoid loss^
  10. --Change these functions if your farm downst have the same spacing as mine
  11. --You would be aiming to change the second number in the for loops of each function
  12. function up()
  13.     checkFuel()
  14.     for l=1,3,1 do
  15.         turtle.up()
  16.     end
  17. end
  18. function right()
  19.     turtle.turnRight()
  20.     for o=1,4,1 do
  21.         turtle.forward()
  22.     end
  23.     turtle.turnLeft()
  24. end
  25. function left()
  26.     turtle.turnLeft()
  27.     for p=1,4,1 do
  28.         turtle.forward()
  29.     end
  30.     turtle.turnRight()
  31. end
  32. function down()
  33.     for g=1,FARMHIGHT,1 do
  34.         for h=1,3,1 do
  35.             turtle.down()
  36.         end
  37.     end
  38. end
  39.     --DO NOT CHANGE THE REST
  40.     --OF THE FUNCTIONS
  41.     --UNLESS YOU KNOW WHAT YOU'RE DOING    
  42. function RTH()
  43.     down()
  44.     for m=1,CLUSTERS-1,1 do
  45.         left()
  46.     end
  47. end
  48. function dump()
  49.     rotate(2)
  50.     for d=CLUSTERS+1,15,1 do
  51.         turtle.select(d)
  52.         turtle.drop()
  53.     end
  54.     rotate(2)
  55. end
  56. function plant()
  57.     turtle.select(ACTIVECROP)
  58.     turtle.place()
  59. end
  60. function checkFuel()
  61.     if turtle.getFuelLevel() < 300 then
  62.         turtle.select(Fuel)
  63.         turtle.refuel(5)
  64.     end
  65. end
  66. function farm()
  67.     turtle.dig()
  68.     megaSuck()
  69.     turtle.select(ACTIVECROP)
  70.     turtle.place()    
  71. end
  72. function rotate(times)
  73.     for j=1 , times, 1 do
  74.         turtle.turnLeft()
  75.     end
  76. end
  77. function process()
  78.     checkFuel()
  79.     while true  do --When building keep in mind the implications of this while loop
  80.         turtle.forward()
  81.         turtle.turnLeft()--Facing crop
  82.         if turtle.detect() then -- if crop found
  83.             farm()
  84.         else plant() end--if farmland is empty
  85.         rotate(2)--face other crop
  86.         if turtle.detect() then
  87.             farm()
  88.         else plant() end
  89.         turtle.turnLeft()--prepares to move forward
  90.         if turtle.detect() then break end --IF AT THE END
  91.     end
  92.     rotate(2) -- Turn Around  
  93.     while not turtle.detect() do -- go back also keep this loop in mind while building
  94.         turtle.forward()
  95.     end
  96.     rotate(2)--Getting ready to proceed
  97. end            
  98. function anothaOne(last)-- In charge of farming 1 cluster
  99.     for b=1,FARMHIGHT,1 do--Y AXIS LOOP
  100.         if last and b==FARMHIGHT then --If Last Line and Last cluster
  101.             process()--Z Axis
  102.             RTH()--Return To Home        
  103.         else if b==FARMHIGHT and not last then -- If last of the cluster but not the last cluster
  104.             process()
  105.             down()
  106.         else -- could also be (else if not b==FARMHIGHT and not last then)            
  107.             process()
  108.             up()
  109.         end
  110.     end
  111. end
  112. end --if someone could point out why this end needs to be here thatd be epic
  113.     print("Put crops in the first " .. CLUSTERS .. " slots")
  114.     print("Press Enter to continue")
  115.     temp = io.read()
  116.   --THIS IS WHERE THE CODE STARTS
  117. for x=1,CLUSTERS,1 do --X Axis Loop
  118.     ACTIVECROP = ((x+(CLUSTERS-1))%CLUSTERS)+1 --For the uninitiated the % returns the remainder so 7%3=1
  119.     if x==CLUSTERS then --if last
  120.         anothaOne(true)--one more then stop
  121.         break
  122.     else
  123.     anothaOne()--Y Axis
  124.     right() -- go right on X Axis
  125.     end
  126. end
  127. dump() --Dump items at chest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement