rhyser9

Vanilla Tree Farm v3.0 by rhyser9

Dec 29th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.61 KB | None | 0 0
  1. --************
  2. --*Print Logo*
  3. --************
  4. function logo()
  5.   shell.run('clear')
  6.   print "***************************************"
  7.   print "*              Tree Farm              *"
  8.   print "*             Version 3.0             *"
  9.   print "*         Created By: rhyser9         *"
  10.   print "***************************************"
  11.   term.setCursorPos(1,6)
  12. end
  13.  
  14. --*****************
  15. --*Terminate Error*
  16. --*****************
  17. function terminate()
  18.   sleep(1)
  19.   print "Terminating Program..."
  20.   sleep(3)
  21.   print "Program Terminated"
  22.   error()
  23. end
  24.  
  25. --******************
  26. --*Gather Materials*
  27. --******************
  28. logo()
  29. print "Please place Saplings in Slot #1."
  30.   turtle.select(1)
  31.   while turtle.getItemCount(1) == 0 do
  32.     sleep(1)
  33.   end
  34.  
  35. logo()
  36. print "Please place bonemeal in Slot #2."
  37.   turtle.select(2)
  38.   while turtle.getItemCount(2) == 0 do
  39.     sleep(1)
  40.   end
  41.  
  42. logo()
  43. print "Please place a Log in Slot #15."
  44.   turtle.select(15)
  45.   while turtle.getItemCount(15) == 0 do
  46.     sleep(1)
  47.   end
  48.  
  49. logo()
  50. print "Please place fuel in Slot #16."
  51.   turtle.select(16)
  52.   while turtle.getItemCount(16) == 0 do
  53.     sleep(1)
  54.   end
  55.  
  56. --*******************
  57. --*Configure Program*
  58. --*******************
  59. logo()
  60. print "Would you like to enable the Resupply function?"
  61. write("(Y/N): ")
  62. input = read()
  63. if input == "Y" or input == "y" then
  64.   resupply = 1
  65.   print "Resupply Mode Enabled"
  66. elseif input == "N" or input == "n" then
  67.   resupply = 0
  68.   print "Resupply Mode not Enabled"
  69. else
  70.   resupplyOn = 0
  71.   print "Couldn't Understand Input"
  72.   print "Resupply Mode not Enabled"
  73. end
  74. sleep(2)
  75.  
  76. --*******************
  77. --*Calculate Runtime*
  78. --*******************
  79. local sapling = turtle.getItemCount(1) - 1
  80. local bonemeal = turtle.getItemCount(2) - 1
  81.  
  82. logo()
  83. print "Calculating Runtime..."
  84. sleep(2)
  85. if sapling <= bonemeal then
  86.   if sapling == 0 then
  87.     print "Not Enough Items to Run"
  88.     sleep(1)
  89.     print "Terminating Program"
  90.     sleep(3)
  91.     print "Program Terminated"
  92.     error()
  93.   elseif sapling == 1 then
  94.     print "The program should run 1 time."
  95.   else
  96.     write("The program should run "..sapling.." times.\n")
  97.   end
  98. else
  99.   if bonemeal == 0 then
  100.     print "Not Enough Items to Run"
  101.     sleep(1)
  102.     print "Terminating Program"
  103.     sleep(3)
  104.     print "Program Terminated"
  105.     error()
  106.   elseif bonemeal == 1 then
  107.     print "The program should run 1 time."
  108.   else
  109.     write("The program should run "..bonemeal.." times.\n")
  110.   end
  111. end
  112.  
  113. for i=0,4 do
  114.   write("\nThe program will initiate in "..5 - i.." seconds")
  115.   sleep(1)
  116. end
  117. shell.run('clear')
  118.  
  119. --********
  120. --*Refuel*
  121. --********
  122. function refuel()
  123.   while turtle.getFuelLevel() < 50 do
  124.     print "  Low Fuel!"
  125.     print "  Refueling..."
  126.     turtle.select(16)
  127.     turtle.refuel(1)
  128.         sleep(2)
  129.     if turtle.refuel() == false then
  130.       print "  Refueling Failed!"
  131.       terminate()
  132.     else
  133.       print "  Turtle Refueled"
  134.     end
  135.   end
  136. end
  137.  
  138. --**********************
  139. --*Plant & Grow Sapling*
  140. --**********************
  141. function plant()
  142.   print "  Planting Tree..."
  143.   turtle.select(1)
  144.   turtle.place()
  145.   --Bonemeal
  146.   turtle.select(2)
  147.   turtle.place()
  148.   --Verify Process
  149.   turtle.select(15)
  150.   if turtle.compare() then
  151.     print "  Planting Process Successful"
  152.   else
  153.     print "  Planting Process Failed"
  154.     print "  Possible Causes:"
  155.     print "  * Saplings and Logs don't match"
  156.     print "  * Planting Area Blocked"
  157.     terminate()
  158.   end
  159. end
  160.  
  161. --**************
  162. --*Harvest Tree*
  163. --**************
  164. function harvest()
  165.   print "  Harvesting Tree..."
  166.   turtle.select(15)
  167.   while turtle.compare() == true do
  168.     turtle.dig()
  169.     turtle.digUp()
  170.     turtle.up()
  171.   end
  172.   while turtle.detectDown() == false do
  173.     turtle.down()
  174.   end
  175.   turtle.turnRight()
  176.   turtle.turnRight()
  177.   print "  Harvest Completed"
  178. end
  179.  
  180. --**********
  181. --*Resupply*
  182. --**********
  183. function resupply()
  184.   local i = 0
  185.   --Saplings
  186.   turtle.suckDown()
  187.   --Fuel
  188.   turtle.turnRight()
  189.   turtle.suck()
  190.   --Bonemeal
  191.   turtle.turnLeft()
  192.   turtle.turnLeft()
  193.   turtle.suck()
  194.   --Drop Off Extras
  195.   turtle.turnRight()
  196.   while i ~= 10 do
  197.     turtle.select(4 + i)
  198.     turtle.drop()
  199.     i = i + 1
  200.   end
  201.   turtle.select(15)
  202.   turtle.drop(turtle.getItemCount(15) - 1)
  203.   turtle.turnLeft()
  204.   turtle.turnLeft()
  205. end
  206.  
  207. --***********
  208. --*Main Loop*
  209. --***********
  210. local resupplyOn
  211.  
  212. logo()
  213. while turtle.getItemCount(1) > 1 and turtle.getItemCount(2) > 1 do
  214.   logo()
  215.   print "Farming Cycle Initiated"
  216.   refuel()
  217.   plant()
  218.   harvest()
  219.   if resupplyOn == 0 then
  220.     resupply()
  221.   end
  222.   print "Farming Cycle Completed"
  223. end
  224.  
  225. print "Program Completed"
Advertisement
Add Comment
Please, Sign In to add comment