Advertisement
Serious07

FarmerPro

Jul 27th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Direction: 0=up 1=right 2=down 3=left
  2.  
  3. tX = 0
  4. tY = 0
  5. tDirection = 0
  6.  
  7. backX = 0
  8. backY = 0
  9. backDirection = 0
  10.  
  11. waiting = 12
  12. i = 0
  13. imax = 9
  14. j = 0
  15. jmax = 9
  16. direction = 0
  17. SelectedSlot = 13
  18. imax = imax - 1
  19.  
  20. local function tTurnLeft()
  21.         if tDirection ~= 0 then
  22.                 tDirection = tDirection - 1
  23.         else
  24.                 tDirection = 3
  25.         end
  26.         turtle.turnLeft()
  27. end
  28.  
  29. local function tTurnRight()
  30.         if tDirection ~= 3 then
  31.                 tDirection = tDirection + 1
  32.         else
  33.                 tDirection = 0
  34.         end
  35.         turtle.turnRight()
  36. end
  37.  
  38. local function tForward()
  39.         while turtle.forward() == false do
  40.                 turtle.forward()
  41.         end
  42.  
  43.         if tDirection == 0 then
  44.                 tY = tY + 1
  45.         elseif tDirection == 1 then
  46.                 tX = tX + 1
  47.         elseif tDirection == 2 then
  48.                 tY = tY - 1
  49.         elseif tDirection == 3 then
  50.                 tX = tX - 1
  51.         end
  52. end
  53.  
  54. local function goToStartPos()
  55.         print("Back to home.")
  56.         backX = tX
  57.         backY = tY
  58.         backDirection = tDirection
  59.        
  60.         if tDirection == 0 then
  61.                 tTurnLeft()
  62.                 tTurnLeft()
  63.         elseif tDirection == 1 then
  64.                 tTurnRight()
  65.         elseif tDirection == 3 then
  66.                 tTurnLeft()
  67.         end
  68.        
  69.         while tY ~= 0 do
  70.                 tForward()
  71.         end
  72.        
  73.         tTurnLeft()
  74.        
  75.         while tX ~= 0 do
  76.                 tForward()
  77.         end
  78.        
  79.         tTurnRight()
  80. end
  81.  
  82. local function goToOldPos()
  83.         print("Back to work.")
  84.         if tDirection == 1 then
  85.                 tTurnLeft()
  86.         elseif tDirection == 2 then
  87.                 tTurnLeft()
  88.                 tTurnLeft()
  89.         elseif tDirection == 3 then
  90.                 tTurnRight()
  91.         end
  92.        
  93.         while tY ~= backY do
  94.                 tForward()
  95.         end
  96.        
  97.         tTurnLeft()
  98.        
  99.         while tX ~= backX do
  100.                 tForward()
  101.         end
  102.        
  103.         if tDirection ~= backDirection then
  104.                 while tDirection ~= backDirection do
  105.                         tTurnLeft()
  106.                 end
  107.         end
  108. end
  109.  
  110. local function dropWheat()
  111.         for slotI = 1, 12 do
  112.                 turtle.select(slotI)
  113.                 if turtle.drop() == false and turtle.getItemCount(slotI) ~= 0 then
  114.                         print("Chest is full!")
  115.                         while turtle.drop() == false and turtle.getItemCount(slotI) ~= 0 do
  116.                                 turtle.drop()
  117.                         end
  118.                 end
  119.         end
  120. end
  121.  
  122. local function turnAround()
  123.         turtle.turnLeft()
  124.         turtle.turnLeft()
  125. end
  126.  
  127. local function isFilled()
  128.         count = 0      
  129.         slot = 1
  130.        
  131.         while slot < 13 do
  132.                 count = count + turtle.getItemSpace(slot)
  133.                 slot = slot + 1
  134.         end
  135.        
  136.         --print("Count: " .. count)
  137.        
  138.         if count ~= 0 then
  139.                 return false
  140.         else
  141.                 return true
  142.         end
  143. end
  144.  
  145. local function isLast()
  146.         if turtle.getItemCount(13) == 1 then
  147.                 return true
  148.         else
  149.                 return false
  150.         end
  151. end
  152.  
  153. local function fillSeeds()
  154.         if isLast() then
  155.                 turtle.select(13)
  156.                 for slot = 1, 12 do
  157.                         if turtle.compareTo(slot) then
  158.                                 turtle.select(slot)
  159.                                 turtle.transferTo(13)
  160.                                 turtle.select(13)
  161.                         end
  162.                        
  163.                         if turtle.getItemSpace(13) == 0 then
  164.                                 break
  165.                         end
  166.                 end
  167.                
  168.                 if isLast() then
  169.                         goToStartPos()
  170.                         turtle.select(13)
  171.                        
  172.                         if turtle.suck() == false then
  173.                                 print("Put seeds in chest!!!")
  174.                                 while isLast() do
  175.                                         turtle.suck()
  176.                                 end
  177.                         end
  178.                         goToOldPos()
  179.                 end
  180.         end
  181. end
  182.  
  183. local function unloading()
  184.         if isFilled() == true then
  185.                 print("Unloading...")
  186.                 goToStartPos()
  187.                 dropWheat()
  188.                 goToOldPos()
  189.         end
  190. end
  191.  
  192. local function plow()
  193.          if turtle.detectDown() == true and turtle.digDown() == true then
  194.                 turtle.digDown()
  195.          end
  196. end
  197.  
  198. while true do
  199.         SelectedSlot = 13
  200.         turtle.select(SelectedSlot)
  201.  
  202.         while j < jmax do
  203.                 while i < imax do              
  204.                         turtle.select(1)
  205.                         unloading()
  206.                         plow()
  207.                         turtle.select(SelectedSlot)
  208.                         fillSeeds()
  209.                         turtle.placeDown()
  210.                         tForward()
  211.                        
  212.                         i = i + 1
  213.                 end
  214.                
  215.                 unloading()
  216.                 plow()
  217.                 fillSeeds()
  218.                 turtle.placeDown()
  219.                
  220.                 if j + 1 ~= jmax then
  221.                         if direction == 0 then
  222.                                 tTurnLeft()
  223.                                 tForward()
  224.                                 tTurnLeft()
  225.                                 direction = 1
  226.                         else
  227.                                 tTurnRight()
  228.                                 tForward()
  229.                                 tTurnRight()
  230.                                 direction = 0
  231.                         end
  232.                 end
  233.          
  234.                 turtle.select(1)
  235.                 unloading()
  236.                 plow()
  237.                 turtle.select(SelectedSlot)
  238.                 fillSeeds()
  239.                 turtle.placeDown()
  240.          
  241.           j = j + 1
  242.           i = 0
  243.         end
  244.          
  245.         i = 0
  246.         j = 0
  247.        
  248.         goToStartPos()
  249.         dropWheat()
  250.         turnAround()
  251.         for wait = 1, waiting do
  252.                 sleep(60)
  253.                 print("Remaining " .. (waiting - wait) .. " minutes.")
  254.         end
  255. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement