Advertisement
Bkmz

Untitled

Jan 4th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. N = 9
  2. M = 14
  3.  
  4. -- END CONFIG SECTION
  5.  
  6. seeds_count  = 0
  7. MAX_ITEMS    = 64
  8.  
  9. for i=2,16 do
  10.     if turtle.compareTo(i) then
  11.         seeds_count = seeds_count + turtle.getItemCount(i)
  12.     end
  13. end
  14.  
  15. if seeds_count-16 < N*M then
  16.     printError("Not enough seeds!")
  17.     -- return
  18. end
  19.  
  20. args = ...
  21.  
  22. turtle.refuel(64)
  23.  
  24. function reset_out()
  25.     redstone.setOutput("left", false)
  26.     redstone.setOutput("right", false)    
  27. end
  28.  
  29. function harvest_complete(rotation)
  30.     if rotation == turtle.turnRight then
  31.         redstone.setOutput("left", true)
  32.     else
  33.         redstone.setOutput("right", true)
  34.     end
  35.     os.sleep(1)
  36. end
  37.  
  38. function operation(forwarded, x, y)
  39.     -- adding to the firtst slot seeds
  40.     if turtle.getItemCount(1) == 1 then
  41.         for i=2,16 do
  42.             if turtle.compareTo(i) then
  43.                 available_items = turtle.getItemCount(i)
  44.                 if available_items == MAX_ITEMS then
  45.                     available_items = available_items - 1
  46.                 end
  47.                 turtle.transferTo(1, available_items)
  48.             end
  49.         end
  50.     end
  51.     turtle.digDown()
  52.     turtle.placeDown()
  53. end
  54.  
  55. -- function defenitions
  56. function check_start(delay)
  57.     while true do
  58.         if redstone.getInput("back") == true then
  59.             -- go_to_house()
  60.             return
  61.         else
  62.             os.sleep(delay)
  63.         end
  64.     end
  65. end
  66.  
  67. function go_to_house()
  68.     os.sleep(2)
  69.     -- checking position of end harvest
  70.     if M%2 == 0 then
  71.         -- we at the same line
  72.         -- turtle.back()
  73.         turtle.turnRight()
  74.         for i=1,M do
  75.             turtle.forward()
  76.         end
  77.         turtle.turnLeft()
  78.  
  79.     else
  80.         -- we at opposite line
  81.         turtle.back()
  82.         turtle.turnLeft()
  83.         for i=1,M+1 do
  84.             turtle.forward()
  85.         end
  86.         turtle.turnRight()
  87.         for i=1,N+1 do
  88.             turtle.forward()
  89.         end
  90.         turtle.turnRight()
  91.         turtle.forward()
  92.         turtle.turnRight()
  93.     end
  94. end
  95.  
  96. function run()
  97.     return turtle.forward()
  98. end
  99.  
  100. function harvest()
  101.     local i = 0
  102.     while i<M do
  103.         j=0
  104.         while j<N-1 do
  105.             if run() then
  106.                 operation(true, i, j)
  107.             else
  108.                 operation(false, i, j)
  109.                 j=j-1
  110.             end
  111.             turtle.dig()
  112.             j=j+1
  113.         end
  114.  
  115.         if i%2 == 0 then
  116.             rotation = turtle.turnLeft
  117.         else
  118.             rotation = turtle.turnRight
  119.         end
  120.  
  121.         rotation()
  122.  
  123.         if run() then
  124.             operation(true, i,j)
  125.         else
  126.             operation(false, i,j)
  127.             run()
  128.         end
  129.  
  130.         rotation()
  131.         i=i+1
  132.  
  133.     end
  134.  
  135.     reset_out()
  136.     harvest_complete(rotation)
  137. end
  138.  
  139.  
  140.  
  141. check_start(0.5)
  142. harvest()
  143. go_to_house()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement