Advertisement
Guest User

TreeFarm

a guest
Dec 28th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 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. if sapling <= bonemeal then
  57.   if sapling == 1 then
  58.     print "The program should run 1 time."
  59.   else
  60.     write("The program should run "..sapling.." times.\n")
  61.   end
  62. else
  63.   if bonemeal == 1 then
  64.     print "The program should run 1 time."
  65.   else
  66.     write("The program should run "..bonemeal.." times.\n")
  67.   end
  68. end
  69.  
  70. --**********************
  71. --*Plant & Grow Sapling*
  72. --**********************
  73. function plant()
  74.   turtle.select(1)
  75.   turtle.place
  76.   turtle.select(2)
  77.   turtle.place
  78.   turtle.select(15)
  79.   if turtle.compare() then
  80.     print "Planting Successful"
  81.   else
  82.     print "Planting Unsuccessful"
  83.     print "Possible Causes:"
  84.     print " * Saplings (2) and Logs (15) don't match"
  85.     print " * Planting Area Blocked"
  86.     print "Terminating Program"
  87.     sleep(2)
  88.     print "Program Terminated"
  89.     error()
  90.   end
  91. end
  92.  
  93. --**************
  94. --*Harvest Tree*
  95. --**************
  96. function harvest()
  97.   print "Initiating Harvest"
  98.   select(15)
  99.   while turtle.compare do
  100.     turtle.dig
  101.     turtle.digUp
  102.     turtle.up
  103.   end
  104.   turtle.down
  105.   while turtle.detectDown() == false do
  106.     turtle.down
  107.   end
  108.   print "Harvest Completed"
  109. end
  110.  
  111. --********
  112. --*Refuel*
  113. --********
  114. function refuel()
  115.   while turtle.getFuelLevel() < 20 then
  116.     print "Low Fuel"
  117.     print "Attempting to Refuel"
  118.     turtle.select(16)
  119.     turtle.refuel(1)
  120.     if turtle.refuel() == false then
  121.       print "Couldn't Refuel"
  122.       print "Terminating Program"
  123.       sleep(2)
  124.       print "Program Terminated"
  125.       error()
  126.     end
  127.   end
  128. end
  129.  
  130. --***********
  131. --*Main Loop*
  132. --***********
  133. while turtle.getItemCount(1) > 1 & turtle.getItemCount(2) > 1 do
  134.   refuel()
  135.   plant()
  136.   harvest()
  137. end
  138.  
  139. print "Program Completed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement