Advertisement
mathiaas

s02_felling

Aug 2nd, 2020 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. args = {...}
  2.  
  3. assert(loadfile("functions"))()
  4. assert(loadfile("movement"))()
  5.  
  6. branches = {}
  7. startingPosition = getYPos()
  8. twigs = {}
  9. returnPath = {}
  10.  
  11. function checkWalls(checkingBranch)
  12.     for i=1,4 do
  13.  
  14.         local success, data = turtle.inspect()
  15.  
  16.         if  success then
  17.             if  string.match(data.name,"_log") or string.match(data.name,"_leaves") then
  18.                 if checkingBranch then
  19.                     table.insert(branches,1,getPos())-- add block position to memory
  20.                 else
  21.                     table.insert(twigs,1,getPos())-- add block position to memory
  22.                 end
  23.             --else
  24.                 --turtle.dig()-- not a log. KILL IT
  25.             end
  26.         end
  27.  
  28.         move("rt")
  29.     end
  30. end
  31.  
  32. function goToBranch(branch)
  33.     moveY(split(branch)[2])
  34.     moveF(split(branch)[4])
  35. end
  36.  
  37. function killTwigs()
  38.     if  #twigs == 0 then return end-- return if no twiggers
  39.  
  40.     --turn to twig
  41.     turns = moveF(split(twigs[1])[4])
  42.  
  43.     if  type(turns) == "table" then
  44.         for k,v in pairs(turns) do
  45.             table.insert(returnPath,1,v)
  46.         end
  47.     end
  48.  
  49.     --dig twig
  50.     turtle.dig()
  51.     --rmv twig from twigs
  52.     table.remove(twigs,1)
  53.     --move fd
  54.     move("fd")
  55.     --add movement to returnpath
  56.     table.insert(returnPath,1,"fd")
  57.     --checkwalls
  58.     checkWalls(false)
  59.     --if twigs then RECURSE
  60.     if  #twigs>0 then
  61.         killTwigs()
  62.     end
  63. end
  64.  
  65. function stripBranches(branches)
  66.     for k,v in pairs(branches) do
  67.         goToBranch(v)
  68.         turtle.dig()
  69.         move("fd")
  70.         table.insert(returnPath,1,"fd")
  71.         checkWalls(false)
  72.     end
  73. end
  74.  
  75. function Main()
  76.  
  77.     -- move to trunk location
  78.     turtle.dig()
  79.     move("fd")
  80.     checkWalls()
  81.  
  82.     while turtle.inspectUp() do -- core tree and store branch locations
  83.         turtle.digUp()
  84.         move("up")
  85.         checkWalls(true)
  86.     end
  87.  
  88.     goToBranch(branches[1])
  89.     table.insert(twigs,branches[1])
  90.     table.remove(branches,1)
  91.     killTwigs()
  92.     returnPath = reverseList(returnPath)
  93.     moveT(inversePath(returnPath))
  94.     for k,v in pairs(returnPath) do
  95.         print(k,v)
  96.     end
  97. end
  98.  
  99. Main()
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. --branches = reverseList(branches) -- reverse branch-list so we start on top
  107.  
  108. -- move to branch
  109. -- for k,v in pairs(branches) do
  110. --  print(v)
  111. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement