KyneSilverhide

Farm Sugar Cane

May 30th, 2013
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.28 KB | None | 0 0
  1.     function fuelItUp()
  2.     --Finds out if the turtle needs to refuel and if it has fuel to run
  3.         needsFuel = turtle.getFuelLevel()
  4.         minimumFuelLevel = 10
  5.         hasFuel = turtle.getItemCount(16)
  6.         useFuel = turtle.refuel()
  7.         if needsFuel == "unlimited" then
  8.            
  9.         else
  10.             if tonumber(needsFuel) < tonumber(minimumFuelLevel) then
  11.                 if hasFuel > 0 then
  12.                     turtle.select(16)
  13.                     turtle.refuel(1)
  14.                     turtle.select(1)
  15.                 else
  16.                     print("Please insert fuel into slot 16")
  17.                     repeat os.sleep(1)
  18.                     until tonumber(turtle.getItemCount(16)) > 0
  19.                     fuelItUp()
  20.                 end
  21.             end
  22.         end
  23.     end
  24.    
  25.     function questions()
  26.         length = 11
  27.         rows = 8
  28.         declarations()
  29.     end
  30.    
  31.     function declarations()
  32.         currentPos = 0
  33.         currentRow = 1
  34.         startBlock = 1
  35.         startRow = 1
  36.         det = turtle.detect()
  37.         detDown = turtle.detectDown()
  38.         prime()
  39.     end
  40.    
  41.     function prime()
  42.         fuelItUp()
  43.         turtle.up()
  44.         turtle.up()
  45.         farmDown()
  46.     end
  47.    
  48.     function farmDown()
  49.         while tonumber(currentPos) ~= tonumber(length) do
  50.             fuelItUp()
  51.             if det == true then
  52.                 turtle.dig()
  53.                 turtle.forward()
  54.                 currentPos = currentPos + 1
  55.                 if detDown == true then
  56.                     turtle.digDown()
  57.                 end
  58.             else
  59.                 if detDown == true then
  60.                     turtle.digDown()
  61.                 end
  62.             end
  63.         end
  64.         if tonumber(currentRow) ~= tonumber(rows) then
  65.             if tonumber(currentRow) % 2 == 0 then
  66.                 rightTurn()
  67.             else
  68.                 leftTurn()
  69.             end
  70.         else
  71.             ending()
  72.         end
  73.     end
  74.    
  75.     function leftTurn()
  76.         turtle.turnLeft()
  77.         turtle.forward()
  78.         if det == true then
  79.             turtle.dig()
  80.             turtle.forward()
  81.         end
  82.         turtle.turnLeft()
  83.         if detDown == true then
  84.             turtle.digDown()
  85.         end
  86.         currentRow = currentRow + 1
  87.         farmBack()
  88.     end
  89.    
  90.     function rightTurn()
  91.         turtle.turnRight()
  92.         turtle.forward()
  93.         if det == true then
  94.             turtle.dig()
  95.             turtle.forward()
  96.         end
  97.         turtle.turnRight()
  98.         if detDown == true then
  99.             turtle.digDown()
  100.         end
  101.         currentRow = currentRow + 1
  102.         farmDown()
  103.     end
  104.    
  105.     function farmBack()
  106.         while tonumber(currentPos) ~= tonumber(startBlock) do
  107.             fuelItUp()
  108.             if det == true then
  109.                 turtle.dig()
  110.                 turtle.forward()
  111.                 currentPos = currentPos - 1
  112.                 if detDown == true then
  113.                     turtle.digDown()
  114.                 end
  115.             else
  116.                 if detDown == true then
  117.                     turtle.digDown()
  118.                 end
  119.             end
  120.         end
  121.         if tonumber(currentRow) ~= tonumber(rows) then
  122.             if tonumber(currentRow) % 2 == 0 then
  123.                 rightTurn()
  124.             else
  125.                 leftTurn()
  126.             end
  127.         else
  128.             ending()
  129.         end
  130.     end
  131.    
  132.    
  133.     function ending()
  134.         if tonumber(currentRow) % 2 == 0 then
  135.             turtle.forward()
  136.             turtle.turnLeft()
  137.             turtle.down()
  138.             turtle.down()
  139.         else
  140.             turtle.turnLeft()
  141.             turtle.turnLeft()
  142.             while tonumber(currentPos) ~= tonumber(startBlock - 1) do
  143.                 turtle.forward()
  144.                 currentPos = currentPos - 1
  145.             end
  146.             turtle.turnLeft()
  147.             turtle.down()
  148.             turtle.down()
  149.         end
  150.         while tonumber(currentRow) ~= tonumber(startRow) do
  151.             fuelItUp()
  152.             turtle.forward()
  153.             turtle.forward()
  154.             currentRow = currentRow - 1
  155.         end
  156.         dropoff()
  157.     end
  158.    
  159.     function dropoff()
  160.         s = 1
  161.         total = 0
  162.         while s < 16 do
  163.             items = turtle.getItemCount(s)
  164.             total = items + total
  165.             if items > 0 then
  166.                 turtle.select(s)
  167.                 turtle.drop()
  168.             end
  169.             s = s + 1
  170.         end
  171.         turtle.turnLeft()
  172.         print("Total Items Deposited:")
  173.         print(total)
  174.     end
  175.    
  176. questions()
Advertisement
Add Comment
Please, Sign In to add comment