nikich800

farmer

May 14th, 2021 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. seeds, harvests, fuel = 1, 2, 16
  2. oddity = true
  3.  
  4.  
  5. function flush()
  6.     i = 1
  7.     while(i < 17)
  8.     do
  9.        turtle.select(i)
  10.         turtle.dropDown()
  11.     end
  12.     turtle.select(1)
  13. end
  14.  
  15. function try_flush()
  16.     success, data = turtle.inspectDown();
  17.  
  18.     if(success)
  19.     then
  20.         if(data.name == "minecraft:chest")
  21.         then
  22.             flush()
  23.         end
  24.     end
  25. end
  26.  
  27. function go()
  28.     turtle.suckDown()
  29.    
  30.     try_flush()
  31.  
  32.     if(turtle.getFuelLevel() > 1)
  33.     then
  34.         turtle.forward()
  35.     else
  36.         turtle.select(fuel)
  37.         turtle.refuel()
  38.         turtle.select(seeds)
  39.     end
  40. end
  41.  
  42. function goToNextLine()
  43.     if(oddity)
  44.     then
  45.         turtle.turnRight()
  46.         go()
  47.         turtle.turnRight()
  48.         oddity = false
  49.     else
  50.         turtle.turnLeft()
  51.         go()
  52.         turtle.turnLeft()
  53.         oddity = true
  54.     end
  55. end
  56.  
  57. function harvest()
  58.     success, data = turtle.inspectDown()
  59.     if(success)
  60.     then
  61.         if(data.state.age == 7)
  62.         then
  63.             turtle.digDown()
  64.             turtle.suckDown()
  65.             turtle.placeDown()
  66.         end
  67.     end
  68.  
  69.     if(not turtle.inspectDown())
  70.     then
  71.         seeds, harvests = harvests, seeds
  72.         turtle.select(seeds)
  73.         turtle.placeDown()
  74.     end
  75.    
  76. end
  77.  
  78. function lineEndCheck()
  79.     success, data = turtle.inspect()
  80.     return data.name == "minecraft:cobblestone"
  81. end
  82.  
  83.  
  84.  
  85.  
  86.  
  87. --Main loop
  88. while(true)
  89. do
  90.     --Self refuel
  91.     turtle.turnRight()
  92.     turtle.turnRight()
  93.     turtle.select(fuel)
  94.     turtle.suck()
  95.     turtle.refuel()
  96.     turtle.drop()
  97.     turtle.turnRight()
  98.     turtle.turnRight()
  99.  
  100.     --First line harvest
  101.     while(true)
  102.     do
  103.         try_flush()
  104.  
  105.         if(lineEndCheck())
  106.         then
  107.             break
  108.         end
  109.  
  110.         harvest()
  111.         go()
  112.     end
  113.  
  114.     --Transition
  115.     turtle.turnRight()
  116.     turtle.forward()
  117.     turtle.turnRight()
  118.  
  119.     --Next line harvest
  120.     while(true)
  121.     do
  122.         try_flush()
  123.  
  124.         if(lineEndCheck())
  125.         then
  126.             break
  127.         end
  128.  
  129.         harvest()
  130.         go()
  131.     end
  132.  
  133.     --Transition
  134.     turtle.turnRight()
  135.     turtle.forward()
  136.     turtle.turnRight()
  137.  
  138.     --First line succ
  139.     while(true)
  140.     do
  141.         try_flush()
  142.  
  143.         if(lineEndCheck())
  144.         then
  145.             break
  146.         end
  147.  
  148.         turtle.suckDown()
  149.         go()
  150.     end
  151.  
  152.     --BIG transition
  153.     turtle.turnRight()
  154.     turtle.forward()
  155.     turtle.forward()
  156.     turtle.turnRight()
  157.  
  158.     --Looped for the rest
  159.     while(true)
  160.     do
  161.         --Harvest
  162.         while(true)
  163.         do
  164.             try_flush()
  165.  
  166.             if(lineEndCheck())
  167.             then
  168.                 break
  169.             end
  170.  
  171.             harvest()
  172.             go()
  173.         end
  174.  
  175.         --Transition
  176.         turtle.turnRight()
  177.         turtle.forward()
  178.         turtle.turnRight()
  179.  
  180.         --Succ
  181.         while(true)
  182.         do
  183.             try_flush()
  184.            
  185.             if(lineEndCheck())
  186.             then
  187.                 break
  188.             end
  189.  
  190.             turtle.suckDown()
  191.             go()
  192.         end
  193.  
  194.         --BIG transition
  195.         turtle.turnRight()
  196.         turtle.forward()
  197.         turtle.forward()
  198.         turtle.turnRight()
  199.     end
  200.  
  201. --[[
  202.     while(true)
  203.     do
  204.         while(true)
  205.         do
  206.             success, data = turtle.inspectDown()
  207.            
  208.             if(lineEndCheck(data))
  209.             then
  210.                 break
  211.             end
  212.             collect()
  213.             go()
  214.         end
  215.  
  216.         flush()
  217.  
  218.         succ, dat = turtle.inspect()
  219.         if(dat.name == "minecraft:netherrack")
  220.         then
  221.             break
  222.         end
  223.    
  224.         goToNextLine()
  225.     end
  226.    
  227.     turtle.turnRight()
  228.     while(true)
  229.     do
  230.         turtle.forward()
  231.         succ, dat = turtle.inspect()
  232.         if(dat.name == "minecraft:netherrack")
  233.         then
  234.             turtle.turnRight()
  235.             break
  236.         end
  237.     end
  238. ]]--
  239.  
  240.     sleep(600)
  241. end
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
Add Comment
Please, Sign In to add comment