Advertisement
Blackhome

TreeFeller

Jul 4th, 2025 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | Gaming | 0 0
  1. -- pastebin get L28U4CAd Treefeller
  2.  
  3. -- === Basic Movement ===
  4.  
  5. local function moveForward()
  6.     if turtle.forward() then
  7.         --turtlePos = add(turtlePos, direction)
  8.         return true
  9.     end
  10.     return false
  11. end
  12. local function moveUp()
  13.     if turtle.up() then
  14.         --turtlePos.y = turtlePos.y + 1
  15.         return true
  16.     end
  17.     return false
  18. end
  19.  
  20. local function moveDown()
  21.     if turtle.down() then
  22.         --turtlePos.y = turtlePos.y - 1
  23.         return true
  24.     end
  25.     return false
  26. end
  27.  
  28. local function forceMoveForward()
  29.     while not moveForward() do turtle.dig() end
  30. end
  31.  
  32. local function forceMoveUp()
  33.     while not moveUp() do turtle.digUp() end
  34. end
  35.  
  36. local function forceMoveDown()
  37.     while not moveDown() do turtle.digDown() end
  38. end
  39.  
  40. local function isLog(item)
  41.     if not item or not item.name then return false end
  42.  
  43.     local saplingSuffix = "_log"
  44.     return item.name:match(":.*" .. saplingSuffix .. "$") ~= nil
  45. end
  46.  
  47.  
  48. local function fellTree()
  49.     local success, item = turtle.inspect()
  50.  
  51.     if success and isLog(item) then
  52.         forceMoveForward()
  53.         local cnt = 0
  54.         while true do
  55.             local suc, itemUp = turtle.inspectUp()
  56.             if not isLog(itemUp) then
  57.                 break
  58.             end
  59.             forceMoveUp()
  60.             cnt = cnt + 1
  61.         end
  62.         while cnt > 0 do
  63.             forceMoveDown()
  64.             cnt = cnt - 1
  65.         end
  66.         if not fellTree() then
  67.             turtle.turnRight()
  68.             fellTree()
  69.         end
  70.         return true
  71.     end
  72.     return false
  73. end
  74.  
  75. fellTree()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement