Advertisement
Guest User

TreeFarm

a guest
Dec 28th, 2012
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 KB | None | 0 0
  1. --*****************
  2. --*****************
  3. --**  Tree Farm  **
  4. --** Created By: **
  5. --**   rhyser9   **
  6. --*****************
  7. --*****************
  8.  
  9. local sapling
  10. local bonemeal
  11.  
  12. --******************
  13. --*Gather Materials*
  14. --******************
  15. shell.run('clear')
  16. print "Thank you for using this tree farm."
  17. print "Please place saplings in Slot #1."
  18.   turtle.select(1)
  19.   while turtle.getItemCount(1) == 0 do
  20.     sleep(1)
  21.   end
  22.  
  23. shell.run('clear')
  24. print "Thank you for using this tree farm."
  25. print "Please place bonemeal in Slot #2."
  26.   turtle.select(2)
  27.   while turtle.getItemCount(2) == 0 do
  28.     sleep(1)
  29.   end
  30.  
  31. shell.run('clear')
  32. print "Thank you for using this tree farm."
  33. print "Please place a log of the tree your farming in Slot #15."
  34.   turtle.select(15)
  35.   while turtle.getItemCount(15) == 0 do
  36.     sleep(1)
  37.   end
  38.  
  39. shell.run('clear')
  40. print "Thank you for using this tree farm."
  41. print "Please place some fuel in Slot #16."
  42.   turtle.select(16)
  43.   while turtle.getItemCount(16) == 0 do
  44.     sleep(1)
  45.   end
  46.  
  47. shell.run('clear')
  48. print "All Materials Recieved"
  49.  
  50. --*******************
  51. --*Calculate runtime*
  52. --*******************
  53. sapling = turtle.getItemCount(1) - 1
  54. bonemeal = turtle.getItemCount(2) - 1
  55.  
  56. sleep(1)
  57. if sapling <= bonemeal then
  58.   if sapling == 1 then
  59.     print "The program should run 1 time."
  60.   elseif sapling == 0 then
  61.     print "Not Enough Items to Run"
  62.     sleep(1)
  63.     print "Terminating Program"
  64.     sleep(3)
  65.     print "Program Terminated"
  66.     error()
  67.   else
  68.     write("The program should run "..sapling.." times.\n")
  69.   end
  70. else
  71.   if bonemeal == 1 then
  72.     print "The program should run 1 time."
  73.   elseif bonemeal == 0 then
  74.     print "Not Enough Items to Run"
  75.     sleep(1)
  76.     print "Terminating Program"
  77.     sleep(3)
  78.     print "Program Terminated"
  79.     error()
  80.   else
  81.     write("The program should run "..bonemeal.." times.\n")
  82.   end
  83. end
  84.  
  85. for i=0,4 do
  86.   write("\nThe program will initiate in "..5 - i.." seconds")
  87.   sleep(1)
  88. end
  89. shell.run('clear')
  90.  
  91. --**********************
  92. --*Plant & Grow Sapling*
  93. --**********************
  94. function plant()
  95.   turtle.select(1)
  96.   turtle.place()
  97.   turtle.select(2)
  98.   turtle.place()
  99.   turtle.select(15)
  100.   if turtle.compare() then
  101.     print "  Planting Process Successful"
  102.   else
  103.     print "  Planting Process Failed"
  104.     print "  Possible Causes:"
  105.     print "  * Saplings and Logs don't match"
  106.     print "  * Planting Area Blocked"
  107.     print "Terminating Program"
  108.     sleep(3)
  109.     print "Program Terminated"
  110.     error()
  111.   end
  112. end
  113.  
  114. --**************
  115. --*Harvest Tree*
  116. --**************
  117. function harvest()
  118.   print "  Initiating Harvest"
  119.   select(15)
  120.   while turtle.compare() == true do
  121.     turtle.dig()
  122.     turtle.digUp()
  123.     turtle.up()
  124.   end
  125.   while turtle.detectDown() == false do
  126.     turtle.down()
  127.   end
  128.   print "  Harvest Completed"
  129. end
  130.  
  131. --********
  132. --*Refuel*
  133. --********
  134. function refuel()
  135.   while turtle.getFuelLevel() < 20 do
  136.     print "Low Fuel"
  137.     print "Attempting to Refuel"
  138.     turtle.select(16)
  139.     turtle.refuel(1)
  140.     if turtle.refuel() == false then
  141.       print "Couldn't Refuel"
  142.       print "Terminating Program"
  143.       sleep(2)
  144.       print "Program Terminated"
  145.       error()
  146.     end
  147.   end
  148. end
  149.  
  150. --***********
  151. --*Main Loop*
  152. --***********
  153. while turtle.getItemCount(1) > 1 do
  154.   if turtle.getItemCount(2) > 1 then
  155.     print "\nInitiating Farming Cycle"
  156.     refuel()
  157.     plant()
  158.     harvest()
  159.     print "Farming Cycle Completed"
  160.   else
  161.     print "Program Completed"
  162.     error()
  163.   end
  164. end
  165.  
  166. print "Program Completed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement