Skaruts

ComputerCraft CutRedWood [wip] v0.1 drafty

Aug 20th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. local tArgs = {...}
  2.  
  3. if #tArgs < 1 then
  4.     print("Rong usage.")
  5.     print("Syntax: cutWood <number of trees to iterate through>")
  6.     return
  7. end
  8.  
  9. local iterations = tonumber(tArgs[1])
  10. local Vpos = 0
  11.  
  12. local function left()
  13.     turtle.turnLeft()
  14. end
  15.  
  16. local function right()
  17.     turtle.turnRight()
  18. end
  19.  
  20. local function up()
  21.     turtle.up()
  22. end
  23.  
  24. local function down()
  25.     turtle.down()
  26. end
  27.  
  28. local function forward()
  29.     turtle.forward()
  30. end
  31.  
  32. local function back()
  33.     turtle.back()
  34. end
  35.  
  36. local function returnToGroundPosition()
  37.     while Vpos > 0 do
  38.         if not turtle.down() then
  39.             print("Tried to go down further and couldn't.")
  40.         end
  41.         Vpos = Vpos - 1
  42.     end
  43. end
  44.  
  45. local function placeSapling()
  46.    
  47. end
  48.  
  49. local function plantSaplings()
  50.     turtle.select(1)
  51.    
  52.     forward()
  53.     forward()
  54.     left()
  55.     -- Sapling 01
  56.     if not turtle.place() then
  57.         return false
  58.     end
  59.  
  60.     left()
  61.     forward()
  62.     right()
  63.     -- Sapling 02
  64.     if not turtle.place() then
  65.         return false
  66.     end
  67.    
  68.     right()
  69.     -- Sapling 03
  70.     if not turtle.place() then
  71.         return false
  72.     end
  73.    
  74.     back()
  75.     -- Sapling 04
  76.     if not turtle.place() then
  77.         return false
  78.     end
  79.    
  80. end
  81.  
  82. local function applyBoneMeal()
  83.     turtle.select(1) -- Sapling
  84.    
  85.     while turtle.compare(1) do
  86.         turtle.select(2) -- Bone Meal
  87.         if not turtle.place() then
  88.             return false
  89.         end
  90.         turtle.select(1) -- Sapling
  91.     end
  92. end
  93.  
  94. local function clearFirstLayer()
  95.     turtle.dig()
  96.     forward()
  97.     turtle.dig()
  98.     forward()
  99.     left()
  100.     turtle.dig()
  101.     forward()
  102.     left()
  103.     turtle.dig()
  104.     forward()
  105.     left()
  106.     forward()
  107.     left()
  108. end
  109.  
  110. local function clearNextLayer()
  111.     turtle.digUp()
  112.     turtle.up()
  113.    
  114.     Vpos = Vpos + 1
  115.  
  116.     turtle.dig()
  117.     forward()
  118.     left()
  119.     turtle.dig()
  120.     forward()
  121.     left()
  122.     turtle.dig()
  123.     forward()
  124.     left()
  125.     forward()
  126.     left()
  127. end
  128.  
  129. local function cutTree()
  130.  
  131.     clearFirstLayer()
  132.    
  133.     while turtle.detectUp() do
  134.         clearNextLayer()
  135.     end
  136.  
  137.         -- fuel = turtle.getFuelLevel()
  138.        
  139.         -- if fuel < 1 then
  140.         --  while not turtle.refuel() do
  141.         --      print ("Waiting for fuel...")
  142.         --  end
  143.         -- end
  144.        
  145.         -- if not turtle.dig() then
  146.         --  print("Something's wrong! No tree to cut. Aborting")
  147.         --  return
  148.         -- end
  149.    
  150.     returnToGroundPosition()
  151. end
  152.  
  153. local function returnWood()
  154.     right()
  155.     right()
  156.     forward()
  157.     for n=3,16 do
  158.         turtle.select(n)
  159.         turtle.drop()
  160.     end
  161.     left()
  162.     left()
  163.  
  164. end
  165.  
  166. for i = 1, iterations do
  167.     plantSaplings()
  168.     applyBoneMeal()
  169.     cutTree()
  170.     returnWood()
  171.    
  172. end
Advertisement
Add Comment
Please, Sign In to add comment