Gaimo

Farming

Sep 25th, 2018
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. -- data entry --
  2. local Args = {...}
  3.  
  4. if #Args ~= 2 then
  5.     print("Usage: farm <length> <width>")
  6.     return
  7. end
  8.  
  9. -- vars --
  10. lenght = tonumber ( Args[1] )
  11. lenght1 = tonumber ( Args[1] )
  12. width = tonumber ( Args[2] )
  13.  
  14. -- check fuel level --
  15. function checkfuel()
  16.     --term.clear()
  17.     print( "Fuel level is "..turtle.getFuelLevel() )
  18.  
  19.     if turtle.getFuelLevel() < 80 then
  20.         print("Add coal on inventory!")
  21.         for n=1,16 do
  22.             local nCount = turtle.getItemCount(n)
  23.             if nCount > 0 then
  24.                 turtle.select( n )
  25.                 if turtle.refuel(1) then
  26.                     print( "New Fuel level is "..turtle.getFuelLevel() )
  27.                 end
  28.             end
  29.         end
  30.     end
  31. end
  32.  
  33. function task()
  34.     checkfuel()
  35.     turtle.forward()
  36.     turtle.digDown()
  37.     turtle.down()
  38.     turtle.suckDown()
  39.     turtle.up()
  40.     turtle.digDown()
  41.     turtle.select( 1 )
  42.     if turtle.placeDown() then
  43.         lenght = lenght - 1
  44.     else
  45.         turtle.select(2)
  46.         if turtle.placeDown() then
  47.             lenght = lenght - 1
  48.         else
  49.             turtle.select(3)
  50.             if turtle.placeDown() then
  51.                 lenght = lenght - 1
  52.                 if lenght == 0 then
  53.                     turtle.turtleRight()
  54.                     turtle.forward()
  55.                     turtle.turnLeft()
  56.                     width = width - 1
  57.                 end
  58.             else           
  59.                 print("please add seeds on slot 1,2 and 3")
  60.             end
  61.         end
  62.     end
  63. end
  64.  
  65. function task1()
  66.     checkfuel()
  67.     turtle.forward()
  68.     turtle.digDown()
  69.     turtle.down()
  70.     turtle.suckDown()
  71.     turtle.up()
  72.     turtle.digDown()
  73.     turtle.select( 1 )
  74.     if turtle.placeDown() then
  75.         lenght = lenght + 1
  76.     else
  77.         turtle.select(2)
  78.         if turtle.placeDown() then
  79.             lenght = lenght + 1
  80.         else
  81.             turtle.select(3)
  82.             if turtle.placeDown() then
  83.                 lenght = lenght + 1
  84.                 if lenght == lenght1 then
  85.                     turtle.turtleLeft()
  86.                     turtle.forward()
  87.                     turtle.turnRight()
  88.                     width = width - 1
  89.                 end
  90.             else           
  91.                 print("please add seeds on slot 1,2 and 3")
  92.             end
  93.         end
  94.     end
  95. end
  96.  
  97. -- loop --
  98. function fLoop()
  99.     while width > 0 do
  100.         while lenght > 0 do
  101.             task()
  102.         end
  103.  
  104.         while lenght < 0 do
  105.             task1()
  106.         end
  107.     end
  108. end
  109.  
  110. function fStart()
  111.     term.clear()
  112.     print("==== starting planting ====")
  113.     print("please add seeds on slot 1,2 and 3")
  114.     sleep(2)
  115.     turtle.turnRight()
  116.     turtle.turnRight()
  117.     fLoop()
  118. end
  119.  
  120. -- program --
  121. fStart()
Advertisement
Add Comment
Please, Sign In to add comment