Advertisement
Ubidibity

simp_tree.lua

Apr 22nd, 2025 (edited)
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | Gaming | 0 0
  1. -- simp_tree.lua: Enhanced tree felling with branch handling
  2. -- Array of valid wood block IDs (expand as needed for ATM 10 trees) for use with 1x1 girth trees
  3. -- credit: derivative from Grok's original work
  4. -- usage:  place at base of tree facing 'into' trunk, it'll step forward and move up.
  5.  
  6. local woodBlocks = {
  7.     "minecraft:oak_log",
  8.     "minecraft:cherry_log",
  9.     "minecraft:spruce_log",
  10.     "minecraft:birch_log",
  11.     "minecraft:jungle_log",
  12.     "minecraft:acacia_log",
  13.     "minecraft:dark_oak_log",
  14.     "regions_unexplored:blackwood_log",
  15.     "regions_unexplored:redwood_log",
  16.     "regions_unexplored:larch_log",
  17.     "regions_unexplored:maple_log",
  18.     "regions_unexplored:silver_birch_log",
  19.     "biomeswevegone:aspen_log",
  20.     "biomeswevegone:pine_log",
  21.     "biomeswevegone:maple_log",
  22.     "biomeswevegone:cika_log",
  23.     "integrateddynamics:menril_log",
  24.     "integrateddynamics:menril_log_filled"
  25.     -- Add modded wood types here, e.g., "some_mod:some_tree_log"
  26. }
  27.  
  28. -- Function to check if a block is a wood block
  29. local function isWoodBlock(blockName)
  30.     for _, wood in ipairs(woodBlocks) do
  31.         if blockName == wood then
  32.             return true
  33.         end
  34.     end
  35.     return false
  36. end
  37.  
  38. -- Function to handle a single branch in the current direction
  39. local function handleBranch()
  40.     local counter = 0
  41.     local success, data = turtle.inspect()
  42.    
  43.     -- Check if the block in front is wood
  44.     if success and isWoodBlock(data.name) then
  45.         while true do
  46.             -- Dig and move forward
  47.             turtle.dig()
  48.             if turtle.forward() then
  49.                 counter = counter + 1
  50.             else
  51.                 break -- Can't move forward (obstruction)
  52.             end
  53.            
  54.             -- Check the next block
  55.             success, data = turtle.inspect()
  56.             if not success or not isWoodBlock(data.name) then
  57.                 break -- Hit non-wood block (leaves, air, etc.)
  58.             end
  59.         end
  60.        
  61.         -- Turn around (180 degrees)
  62.         turtle.turnRight()
  63.         turtle.turnRight()
  64.        
  65.         -- Move back to starting position
  66.         for i = 1, counter do
  67.           turtle.forward()
  68.         end
  69.        
  70.     end
  71. end
  72.  
  73. -- Main tree felling function
  74. local function fellTree()
  75.     turtle.dig()
  76.     turtle.forward()
  77.     while not turtle.up() do
  78.         -- Try to dig and move up
  79.         turtle.digUp()
  80.         -- Check for branches in all four directions
  81.         for i = 1, 4 do
  82.             handleBranch()
  83.             turtle.turnRight() -- Check next direction
  84.         end
  85.     turtle.up() -- move up into block we just mined to finish this level.
  86.     end
  87.    while turtle.down() do
  88.      -- do nothing just go down.
  89.    end
  90. end
  91.  
  92. -- Main program
  93. print("Starting simp_tree with branch handling...")
  94. fellTree()
  95. print("Tree felling complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement