Skaruts

ComputerCraft farmOaks Program [wip 1.1]

Jan 3rd, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = {...}
  2.  
  3. if #tArgs < 1 then
  4.     print("Rong usage.")
  5.     print("Syntax: farmoaks <number of oaks to farm>")
  6.     return
  7. end
  8.  
  9. local iterations = tonumber(tArgs[1])
  10. local Hpos = 0
  11. local Vpos = 0
  12.  
  13. local function plantSapling()
  14.     turtle.select(1)
  15.     if not turtle.place() then
  16.         print("No saplings! Aborting.")
  17.         return
  18.     end
  19. end
  20.  
  21. local function applyBoneMeal()
  22.     turtle.select(1) -- Sapling
  23.    
  24.     while turtle.compare(1) do
  25.         turtle.select(2) -- Bone Meal
  26.         if not turtle.place() then
  27.             print ("No Bone Meal! Aborting.")
  28.             return
  29.         end
  30.         turtle.select(1) -- Sapling
  31.     end
  32. end
  33.  
  34. local function cutTree()
  35.     while not turtle.forward do
  36.         if not turtle.dig() then
  37.             print("Something's Rong! No tree to cut. Aborting")
  38.             return
  39.         end
  40.        
  41.         fuel = turtle.getFuelLevel()
  42.        
  43.         if fuel < 1 then
  44.             while not turtle.refuel() do
  45.                 print ("Waiting for fuel...")
  46.             end
  47.         end
  48.        
  49.         if not turtle.dig() then
  50.             print("Something's Rong! No tree to cut. Aborting")
  51.             return
  52.         end
  53.     end
  54.    
  55.     -- Hpos = Hpos + 1
  56.     turtle.select(3) -- wood
  57.    
  58.     while turtle.compareUp(3) do
  59.         turtle.digUp()
  60.         turtle.up()
  61.         Vpos = Vpos + 1
  62.     end
  63.    
  64.     while Vpos > 0 do
  65.         if not turtle.down() then
  66.             print("Tried to go down further and couldn't.")
  67.         end
  68.         Vpos = Vpos - 1
  69.     end
  70.     turtle.back()
  71. end
  72.  
  73. local function returnWood()
  74.     turtle.turnLeft()
  75.     turtle.turnLeft()
  76.     for n=4,16 do
  77.         turtle.select(n)
  78.         turtle.drop()
  79.     end
  80.     turtle.turnLeft()
  81.     turtle.turnLeft()
  82. end
  83.  
  84. for i = 1, iterations do
  85.     plantSapling()
  86.     applyBoneMeal()
  87.     cutTree()
  88.     returnWood()
  89. end
Advertisement
Add Comment
Please, Sign In to add comment