Skaruts

ComputerCraft farmOaks Program [wip]

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