Advertisement
GooGoo

Wheat/Barley Farm

Aug 29th, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.38 KB | None | 0 0
  1. --[[
  2. 9 x 9 Farm Program for ComputerCraft Turtles.
  3. by GooGoo on Pastebin.
  4. Wade Catrett @ Youtube.
  5. ThaWade every where else.
  6.  
  7. Caution: Be sure your wheat is fully grown before you start the program.
  8. It has no way to check if the wheat is fully grown or not.
  9. After the first harvest it waits 1 hour before harvesting again.
  10. Gives status updates of 30, 10, 5, and 1 minutes and final of 30 seconds.
  11. status updates = time until next harvest. Found at the very end of the code.
  12.  
  13. Put a minium of 3 seeds in slot 1 and 2
  14. Put a minium of 2 coal in slot 16.
  15.  
  16. Note: this is for a 9x9 farm
  17. D's are dirt/farmland.
  18. W is water.  
  19. T = Turtle start position.
  20. C = Chest
  21.   D D D D D D D D D
  22.   D D D D D D D D D
  23.   D D D D D D D D D
  24.   D D D D D D D D D
  25.   D D D D W D D D D
  26.   D D D D D D D D D
  27.   D D D D D D D D D
  28.   D D D D D D D D D
  29.   D D D D D D D D D
  30.   C C
  31.   ^
  32.  Turtle goes on top of the left chest               T C
  33.  Right chest goes on the right side of the turtle.      C <-GROWN_WHEAT->
  34.  After you place him on the left most chest         D D D D D D D D D
  35. ]]
  36. --HARVEST ROW START--
  37. local spot1 = turtle.getItemCount(1)
  38. local spot2 = turtle.getItemCount(2)
  39.  
  40. function cropRow()
  41.     turtle.select(1)
  42.     turtle.forward()
  43.     turtle.digDown()
  44.    
  45.     if spot1 > 1 then
  46.         turtle.select(1)
  47.         turtle.placeDown()
  48.     elseif spot1 < 2 and spot2 > 1 then
  49.         turtle.select(2)
  50.         turtle.placeDown()
  51.     elseif spot2 < 2 and spot1 > 1 then
  52.         turtle.select(1)
  53.         turtle.placeDown()
  54.     else print("Not enough seeds to continue! Add atleast 3 seeds to slot 1 and 2.")
  55.     end
  56. end
  57. --HARVEST ROW END--
  58.  
  59. --TURN RIGHT START--
  60. function rightTurn()
  61.     turtle.turnRight()
  62.     turtle.select(2)
  63.     turtle.forward()
  64.     turtle.digDown()
  65.     turtle.select(1)
  66.     turtle.placeDown()
  67.     turtle.turnRight()
  68. end
  69. --TURN RIGHT END--
  70.  
  71. --TURN LEFT START--
  72. function leftTurn()
  73.     turtle.turnLeft()
  74.     turtle.select(2)
  75.     turtle.forward()
  76.     turtle.digDown()
  77.     turtle.select(1)
  78.     turtle.placeDown()
  79.     turtle.turnLeft()
  80. end
  81. --TURN LEFT END--
  82.  
  83. --RETURN HOME START--
  84. function returnHome()
  85.     turtle.turnLeft()
  86.    
  87.     for i = 1, 8 do
  88.         turtle.forward()
  89.     end
  90.     turtle.turnLeft()
  91.    
  92.     for i = 1, 9 do
  93.     turtle.forward()
  94.     end
  95.    
  96.     turtle.turnRight()
  97.     turtle.turnRight()
  98. end
  99. --RETURN HOME END--
  100.  
  101. --REFUEL START--
  102. function refuel()
  103.  
  104.         turtle.select(16)
  105.         print("Selecting slot 16 for fuel check.")
  106.         sleep(3)
  107.        
  108.     if turtle.getFuelLevel() < 100 and turtle.refuel(0) == true then
  109.         print("Fuel level is " ..turtle.getFuelLevel().. " Need atleast 100 for a full harvest.")
  110.         sleep(3)
  111.         print("Refueling")
  112.         sleep(3)
  113.         turtle.refuel(2)
  114.         print("Refueled")
  115.     end
  116.    
  117.     if turtle.getFuelLevel() < 100 and turtle.refuel(0) == false then
  118.         print("Fuel level is " ..turtle.getFuelLevel().. " Need atleast 100 for a full run.")
  119.         sleep(3)
  120.         print("Please add fuel to slot 16.")
  121.         sleep(2)
  122.         print("Waiting 10 seconds for fuel.")
  123.         sleep(10)
  124.         turtle.refuel(2)
  125.     end
  126.    
  127.     if turtle.getFuelLevel() < 100 and turtle.refuel(2) == false then
  128.         print("TIMES UP! Come back when you have fuel! Exiting Program!")
  129.         sleep(2)
  130.         exit()
  131.         else print("Fuel level is " ..turtle.getFuelLevel().. " Starting Work!")
  132.     end
  133. end
  134.  
  135. --REFUEL END--
  136.  
  137. --COMPARE1&2 START--
  138. function compareOneToTwo() 
  139.    
  140.     if turtle.select(1) == false then
  141.         turtle.select(1)
  142.         print("selecting slot 1")
  143.     end
  144.    
  145.     if turtle.compareTo(2) == true then
  146.         print("Items match!")
  147.    
  148.         elseif turtle.compareTo(2) == false then
  149.             turtle.select(1)
  150.             turtle.dropDown()
  151.             print("Getting rid of mismatch items")
  152.    
  153.         else
  154.             print("ERROR")
  155.     end
  156. end
  157.     --COMPARE1&2 END--
  158.  
  159.  
  160. local seeds1 = turtle.getItemCount(1)
  161. local seeds2 = turtle.getItemCount(2)
  162. local firstSlot,lastSlot = 3,15
  163. local firstSeed,lastSeed = 1,2
  164. local excess1, excess2  = 3,4
  165.  
  166. --FILL SEEDS START--
  167. function grabSeeds()
  168.    
  169.     for i=firstSeed,lastSeed do
  170.         if seeds1 < 64 then
  171.             turtle.select(firstSeed)
  172.             turtle.suck()
  173.             print("Filling slot 1 with seeds!")
  174.         elseif seeds2 < 64 then
  175.             turtle.select(lastSeed)
  176.             turtle.suck()
  177.             print("Filling slot 2 with seeds!")
  178.         else
  179.             print("I have plenty of seeds!")
  180.         end
  181.     end
  182. end
  183. --FILL SEEDS END--
  184.  
  185. --EMPTY INVENTORY START--
  186. function emptyInventory()  
  187.     for i=firstSlot,lastSlot do
  188.         if turtle.select(i) and turtle.compareTo(lastSeed) == true then
  189.             turtle.drop()
  190.             print("Emptying inventory 'seeds'!")
  191.             elseif turtle.select(i) and turtle.compareTo(2) == false then
  192.                 turtle.dropDown()
  193.                 print("Getting rid of everything but seeds!")
  194.         end
  195.     end
  196. end
  197. --EMPTY INVENTORY END--
  198.  
  199. --EMPTY SEED OVERFLOW START--
  200. function emptyExcessSeeds()
  201.   print("Getting rid of seed overflow!")
  202.     for i = excess1,excess2 do
  203.         if turtle.select(i) and turtle.compareTo(firstSeed,lastSeed) == true then
  204.         turtle.drop()
  205.         end
  206.     end
  207. end
  208. --EMPTY SEED OVERFLOW END--
  209. --INVENTORY CLEANUP END--
  210.  
  211. while true do
  212.     refuel()
  213.    
  214.     print("Harvesting row 1.")
  215.     for i = 1, 9 do
  216.         cropRow()
  217.     end
  218.    
  219.     for i = 1, 1 do
  220.         rightTurn()
  221.     end
  222.    
  223.     print("Harvesting row 2.")
  224.     for i = 1, 8 do
  225.         cropRow()
  226.     end
  227.    
  228.     for i = 1, 1 do
  229.         leftTurn()
  230.     end
  231.    
  232.     print("Harvesting row 3.")
  233.     for i = 1, 8 do
  234.         cropRow()
  235.     end
  236.    
  237.     for i = 1, 1 do
  238.         rightTurn()
  239.     end
  240.    
  241.     print("Harvesting row 4.")
  242.     for i = 1, 8 do
  243.         cropRow()
  244.     end
  245.    
  246.     for i = 1, 1 do
  247.         leftTurn()
  248.     end
  249.    
  250.     print("Harvesting row 5.")
  251.     for i = 1, 8 do
  252.         cropRow()
  253.     end
  254.    
  255.     for i = 1, 1 do
  256.         rightTurn()
  257.     end
  258.    
  259.     print("Harvesting row 6.")
  260.     for i = 1, 8 do
  261.         cropRow()
  262.     end
  263.    
  264.     for i = 1, 1 do
  265.         leftTurn()
  266.     end
  267.    
  268.     print("Harvesting row 7.")
  269.     for i = 1, 8 do
  270.         cropRow()
  271.     end
  272.    
  273.     for i = 1, 1 do
  274.         rightTurn()
  275.     end
  276.    
  277.     print("Harvesting row 8.")
  278.     for i = 1, 8 do
  279.         cropRow()
  280.     end
  281.    
  282.     for i = 1, 1 do
  283.         leftTurn()
  284.     end
  285.    
  286.     print("Harvesting row 9.")
  287.     for i = 1, 8 do
  288.         cropRow()
  289.     end
  290.    
  291.     print("Returning Home")
  292.     for i = 1, 1 do
  293.         returnHome()
  294.     end
  295.    
  296.     turtle.turnRight()
  297.    
  298.     while compareOneToTwo() do
  299.     end
  300.    
  301.     while emptyInventory() do
  302.         return true
  303.     end
  304.    
  305.     while grabSeeds() do
  306.         return true
  307.     end
  308.  
  309.     while emptyExcessSeeds() do
  310.         return true
  311.     end
  312.    
  313.     turtle.turnLeft()
  314.     --status message Start
  315.     print("Next harvest in 1 hour!")
  316.     print("Resting!")
  317.     os.sleep(1800)
  318.    
  319.     print("30 minutes remaining!")
  320.     os.sleep(1200)
  321.    
  322.     print("10 minutes remaining!")
  323.     os.sleep(300)
  324.    
  325.     print("5 minutes remaining!")
  326.     os.sleep(240)
  327.    
  328.     print("1 minute remaining!")
  329.     os.sleep(30)
  330.    
  331.     print("harvesting in 30 seconds.")
  332.     sleep(30)
  333.     --Status message End
  334. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement