tofran

Rainbow Tree Farm Program [Computercraft] by ToFran

Sep 19th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.17 KB | None | 0 0
  1. --by ToFran
  2.  
  3. local function DigAndForward(times)
  4.         times = times or 1
  5.         for i = 1,times do
  6.             turtle.dig()
  7.             turtle.forward()
  8.         end
  9. end
  10.  
  11. local function DigDownAndForward(times)
  12.         times = times or 1
  13.         for i = 1,times do
  14.             turtle.digDown()
  15.             turtle.dig()
  16.             turtle.forward()
  17.         end
  18. end
  19.  
  20. local function DigUpDownAndForward(times)
  21.         times = times or 1
  22.         for i = 1,times do
  23.             turtle.digUp()
  24.             turtle.digDown()
  25.             turtle.dig()
  26.             turtle.forward()
  27.         end
  28. end
  29.  
  30.  
  31. local function Leftarino()
  32.         turtle.turnLeft()
  33.         DigAndForward()
  34.         turtle.turnLeft()
  35. end
  36.  
  37. local function Rightarino()
  38.         turtle.turnRight()
  39.         DigAndForward()
  40.         turtle.turnRight()
  41. end
  42.  
  43. local function SpecialRightarino()
  44.         turtle.digUp()
  45.         turtle.digDown()
  46.         turtle.turnRight()
  47.         DigUpDownAndForward()
  48.         turtle.turnRight()
  49.         DigUpDownAndForward()
  50. end
  51.  
  52. local function clearConsole()
  53.         term.clear()
  54.         term.setCursorPos(1,1)
  55. end
  56. local function MineBase()
  57.         DigAndForward(2)
  58.         turtle.forward()
  59.         Rightarino()
  60.         DigDownAndForward(1)
  61.         DigUpDownAndForward(2)
  62.         DigDownAndForward(1)
  63.         Leftarino()
  64.         DigAndForward(1)
  65.         DigUpDownAndForward(4)
  66.         Rightarino()
  67.         DigAndForward(1)
  68.         DigUpDownAndForward(4)
  69.         Leftarino()
  70.         DigAndForward(1)
  71.         DigUpDownAndForward(4)
  72.         Rightarino()
  73.         DigAndForward(3)
  74.         -- 2 layer
  75.         turtle.up()
  76.         turtle.up()
  77.         turtle.turnRight()
  78.         DigAndForward(2)
  79.         turtle.turnLeft()
  80.         DigAndForward(1)
  81.         Rightarino()
  82.         DigAndForward(1)
  83.         turtle.turnLeft()
  84.         DigAndForward(1)
  85.         Rightarino()
  86.         DigAndForward(1)
  87.         turtle.turnLeft()
  88.         DigAndForward(1)
  89.         Rightarino()
  90.         DigAndForward(1)
  91.         turtle.turnLeft()
  92.         turtle.dig()
  93.         turtle.turnRight()
  94. end
  95.  
  96. local function UpLoop(times)
  97.         times = times or 1
  98.         for i = 1,times do
  99.             turtle.digUp()
  100.             turtle.up()
  101.             turtle.dig()
  102.         end
  103. end
  104.  
  105. local function DownLoop(times)
  106.         times = times or 1
  107.         for i = 1,times do
  108.             turtle.digDown()
  109.             turtle.down()
  110.             turtle.dig()
  111.         end
  112. end
  113.  
  114. local function LoopDerivation()
  115.         turtle.turnLeft()
  116.         DigAndForward(3)
  117.         Rightarino()
  118.         DigAndForward(3)
  119. end
  120.  
  121. local function MineDerivation()
  122.         turtle.digUp()
  123.         turtle.up()
  124.         LoopDerivation()
  125.         LoopDerivation()
  126.         LoopDerivation()
  127.         LoopDerivation()
  128. end
  129.  
  130. local function GoToTheOtherSideOfTheLogOnTop()
  131.         turtle.turnRight()
  132.         DigAndForward()
  133.         turtle.turnLeft()
  134.         turtle.dig()
  135. end
  136.  
  137. local function GoToTheOtherSideOfTheLogOnBottom()
  138.         turtle.turnLeft()
  139.         DigAndForward()
  140.         turtle.turnRight()
  141.         turtle.dig()
  142. end
  143.  
  144.  
  145. local function RemoveRootAndCreateItemCavity()
  146.         turtle.digDown()
  147.         turtle.down()
  148.         turtle.digDown()
  149.         turtle.down()
  150.         DigDownAndForward(2)
  151.         SpecialRightarino()
  152.         DigDownAndForward(2)
  153.         turtle.turnRight()
  154.         DigDownAndForward(3)
  155.         turtle.turnRight()
  156.         DigDownAndForward(3)
  157.         SpecialRightarino()
  158.         DigDownAndForward(2)
  159. end
  160.  
  161. local function PlaceAndforward(times)
  162.         times = times or 1
  163.         for i = 1,times do
  164.             turtle.placeDown()
  165.             turtle.forward()
  166.         end
  167. end
  168.  
  169. local function Replant()
  170.         turtle.up()
  171.         turtle.up()
  172.         --
  173.         turtle.up()
  174.         print("Sleeping to allow items to flow.")
  175.         clearConsole()
  176.         sleep(10)
  177.         turtle.down()
  178.         --
  179.         turtle.turnLeft()
  180.         turtle.select(16) -- Select the dirt
  181.         PlaceAndforward(2)
  182.         turtle.turnLeft()
  183.         PlaceAndforward(3)
  184.         turtle.turnLeft()
  185.         PlaceAndforward(1)
  186.         turtle.turnLeft()
  187.         PlaceAndforward(2)
  188.         turtle.turnRight()
  189.         PlaceAndforward(1)
  190.         turtle.turnRight()
  191.         PlaceAndforward(2)
  192.         turtle.turnLeft()
  193.         PlaceAndforward(1)
  194.         turtle.turnLeft()
  195.         PlaceAndforward(3)
  196.         turtle.placeDown()
  197.         -- End of Placing Dirt, lets plant!
  198.         turtle.up()
  199.         turtle.turnLeft()
  200.         turtle.forward()
  201.         turtle.turnLeft()
  202.         turtle.forward()
  203.         turtle.select(15) -- Select The Saplings
  204.         PlaceAndforward(1)
  205.         turtle.turnRight()
  206.         PlaceAndforward(1)
  207.         turtle.turnRight()
  208.         PlaceAndforward(1)
  209.         turtle.placeDown()
  210. end
  211.  
  212. local function GoToChest()
  213.     turtle.turnLeft()
  214.     DigAndForward(2)
  215.     turtle.turnLeft()
  216.     DigAndForward(10)
  217.     -- Drop The Wood
  218.     turtle.select(1)
  219.     turtle.drop()
  220.     turtle.select(2)
  221.     turtle.drop()
  222.     turtle.select(3)
  223.     turtle.drop()
  224.     turtle.select(4)
  225.     turtle.drop()
  226.     turtle.select(5)
  227.     turtle.drop() -- Drop remaining dirt
  228.     turtle.select(1)
  229.     -- Go to the chopping spot
  230.     turtle.turnRight()
  231.     turtle.turnRight()
  232.     DigAndForward(8)
  233.     turtle.down()
  234. end
  235.  
  236. local function TreeCheck()
  237.         notreeWarning = 0
  238.         turtle.select(1)
  239.         while turtle.compare() do
  240.             sleep(1)
  241.             if notreeWarning==0 then
  242.                 print("No tree detected, waiting...")
  243.                 notreeWarning = 1
  244.             end
  245.         end
  246.         if notreeWarning==1 then
  247.             print("Detected! Chopping started.")
  248.         end
  249. end
  250.                
  251. -- UI Stuff
  252. clearConsole()
  253. print("Rainbow Tree Chopper by ToFran\nChoose one of the following options:\n [1] Chop down the tree.\n [2] Start the tree farm.")
  254. local input = read()
  255. clearConsole()
  256.  
  257. if input=="1" then -- Chop down the tree.
  258.     if turtle.getFuelLevel() > 155 then
  259.         write("Fuel level is ")
  260.         write(turtle.getFuelLevel())
  261.         write("\n")
  262.         MineBase()
  263.         UpLoop(6)
  264.         MineDerivation()
  265.         UpLoop(4)
  266.         MineDerivation()
  267.         UpLoop(10)
  268.         GoToTheOtherSideOfTheLogOnTop()
  269.         DownLoop(27)
  270.         GoToTheOtherSideOfTheLogOnBottom()
  271.         UpLoop(2)
  272.         turtle.back()
  273.     else
  274.         print("Not enough fuel :(")
  275.     end
  276. elseif input=="2" then
  277.     if turtle.getFuelLevel() > 200 then
  278.         print("Please place dirt on slot 16 and rainbow saplings on slot 15. \nPress enter to continue...")
  279.         local input = read()   
  280.             while true do -- Its an farm, so its infinite :P
  281.                 if turtle.getItemCount(15) < 4 or turtle.getItemCount(16) < 1 then
  282.                 print("Unable to continue, lack of resources\nTerminating!")
  283.                 print(turtle.getItemCount(15))
  284.                 print(turtle.getItemCount(16))
  285.                 return
  286.                 end
  287.                
  288.                 clearConsole()
  289.                 write("Fuel level is ")
  290.                 write(turtle.getFuelLevel())
  291.                 write("\n")
  292.                 TreeCheck() -- Sleeps the program until a tree is detected
  293.                 MineBase()
  294.                 UpLoop(6)
  295.                 MineDerivation()
  296.                 UpLoop(4)
  297.                 MineDerivation()
  298.                 UpLoop(10)
  299.                 GoToTheOtherSideOfTheLogOnTop()
  300.                 DownLoop(24)
  301.                 RemoveRootAndCreateItemCavity()
  302.                 Replant()
  303.                 GoToChest()
  304.             end    
  305.     else
  306.         print("Not enough fuel :(")
  307.     end
  308. end
  309.  
  310. write("Remaining fuel: ")
  311. write(turtle.getFuelLevel())
  312. write("\n")
  313.  
  314.  
  315. --by ToFran
Advertisement
Add Comment
Please, Sign In to add comment