rhyser9

Redwood Tree Farm v1.0 by rhyser9

Dec 29th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.59 KB | None | 0 0
  1. --************
  2. --*Print Logo*
  3. --************
  4. function logo()
  5.   shell.run('clear')
  6.   print "***************************************"
  7.   print "*          Redwood Tree Farm          *"
  8.   print "*             Version 1.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 dirt in Slot #3."
  44.   turtle.select(3)
  45.   while turtle.getItemCount(3) == 0 do
  46.     sleep(1)
  47.   end
  48.  
  49. logo()
  50. print "Please place a Redwood Log in Slot #15."
  51.   turtle.select(15)
  52.   while turtle.getItemCount(15) == 0 do
  53.     sleep(1)
  54.   end
  55.  
  56. logo()
  57. print "Please place fuel in Slot #16."
  58.   turtle.select(16)
  59.   while turtle.getItemCount(16) == 0 do
  60.     sleep(1)
  61.   end
  62.  
  63. --*******************
  64. --*Calculate Runtime*
  65. --*******************
  66. local sapling =   math.floor((turtle.getItemCount(1) - 1) / 4)
  67. local bonemeal = turtle.getItemCount(2) - 1
  68.  
  69. logo()
  70. print "Calculating Runtime..."
  71. sleep(2)
  72. if sapling <= bonemeal then
  73.   if sapling == 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.   elseif sapling == 1 then
  81.     print "The program should run 1 time."
  82.   else
  83.     write("The program should run "..sapling.." times.\n")
  84.   end
  85. else
  86.   if bonemeal == 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 bonemeal == 1 then
  94.     print "The program should run 1 time."
  95.   else
  96.     write("The program should run "..bonemeal.." times.\n")
  97.   end
  98. end
  99.  
  100. for i=0,4 do
  101.   write("\nThe program will initiate in "..5 - i.." seconds")
  102.   sleep(1)
  103. end
  104. shell.run('clear')
  105.  
  106. --********
  107. --*Refuel*
  108. --********
  109. function refuel()
  110.   while turtle.getFuelLevel() < 50 do
  111.     print "  Low Fuel!"
  112.     print "  Refueling..."
  113.     turtle.select(16)
  114.     turtle.refuel(1)
  115.         sleep(2)
  116.     if turtle.refuel() == false then
  117.       print "  Refueling Failed!"
  118.       terminate()
  119.     else
  120.       print "  Turtle Refueled"
  121.     end
  122.   end
  123. end
  124.  
  125. --**********************
  126. --*Plant & Grow Sapling*
  127. --**********************
  128. function plant()
  129.   print "  Planting Tree..."
  130.   turtle.select(1)
  131.   --First Sapling
  132.   turtle.up()
  133.   turtle.forward()
  134.   turtle.placeDown()
  135.   --Second Sapling
  136.   turtle.forward()
  137.   turtle.placeDown()
  138.   --Third Sapling
  139.   turtle.turnRight()
  140.   turtle.forward()
  141.   turtle.placeDown()
  142.   --Fourth Sapling
  143.   turtle.turnRight()
  144.   turtle.forward()
  145.   turtle.placeDown()
  146.   --Return to Start
  147.   turtle.turnRight()
  148.   turtle.forward()
  149.   turtle.turnLeft()
  150.   turtle.forward()
  151.   turtle.turnRight()
  152.   turtle.turnRight()
  153.   turtle.down()
  154.   --Bonemeal
  155.   turtle.select(2)
  156.   turtle.place()
  157.   --Verify Process
  158.   turtle.select(15)
  159.   if turtle.compare() then
  160.     print "  Planting Process Successful"
  161.   else
  162.     print "  Planting Process Failed"
  163.     print "  Possible Causes:"
  164.     print "  * Saplings and Logs don't match"
  165.     print "  * Planting Area Blocked"
  166.     terminate()
  167.   end
  168. end
  169.  
  170. --**************
  171. --*Harvest Tree*
  172. --**************
  173. function harvest()
  174.   print "  Harvesting Tree..."
  175.   turtle.select(15)
  176.   --Chop First Side
  177.   turtle.select(15)
  178.   turtle.dig()
  179.   turtle.forward()
  180.   while turtle.compareUp() == true do
  181.     turtle.dig()
  182.     turtle.digUp()
  183.     turtle.up()
  184.   end
  185.   turtle.dig()
  186.   --Chop Second Side
  187.   turtle.select(3)
  188.   turtle.turnRight()
  189.   turtle.dig()
  190.   turtle.forward()
  191.   turtle.turnLeft()
  192.   while turtle.compareDown() == false do
  193.     turtle.dig()
  194.     turtle.digDown()
  195.     turtle.down()
  196.   end
  197.   turtle.dig()
  198.   --Return to Start
  199.   turtle.turnLeft()
  200.   turtle.forward()
  201.   turtle.turnLeft()
  202.   turtle.forward()
  203.   print "  Harvest Completed"
  204. end
  205.  
  206. --***********
  207. --*Main Loop*
  208. --***********
  209. logo()
  210. while turtle.getItemCount(1) > 1 and turtle.getItemCount(2) > 1 do
  211.   logo()
  212.   print "Farming Cycle Initiated"
  213.   refuel()
  214.   plant()
  215.   harvest()
  216.   print "Farming Cycle Completed"
  217.   print "Waiting for Leaf Despawn..."
  218.   sleep(400)
  219. end
  220.  
  221. print "Program Completed"
Advertisement
Add Comment
Please, Sign In to add comment