Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- simp_tree.lua: Enhanced tree felling with branch handling for 1x1 and 2x2 trees
- -- Array of valid wood block IDs (expand as needed for ATM 10 trees)
- -- Credit: derivative from Grok's original work, second iteration of second version (first version being 1x1 only as 'simp_tree.lua'
- -- Usage: place at base of tree, in bottom-left corner of 2x2 trunk (or at 1x1 trunk), facing east (into trunk).
- local woodBlocks = {
- "minecraft:oak_log",
- "minecraft:spruce_log",
- "minecraft:birch_log",
- "minecraft:jungle_log",
- "minecraft:acacia_log",
- "minecraft:dark_oak_log",
- "regions_unexplored:blackwood_log"
- -- Add modded wood types here, e.g., "biomesoplenty:mahogany_log"
- }
- -- Function to check if a block is a wood block
- local function isWoodBlock(blockName)
- for _, wood in ipairs(woodBlocks) do
- if blockName == wood then
- return true
- end
- end
- return false
- end
- -- Function to handle a single branch in the current direction (1x1 branches)
- local function handleBranch()
- local counter = 0
- local success, data = turtle.inspect()
- -- Check if the block in front is wood
- if success and isWoodBlock(data.name) then
- while true do
- -- Dig and move forward
- turtle.dig()
- if turtle.forward() then
- counter = counter + 1
- else
- break -- Can't move forward (obstruction)
- end
- -- Check the next block
- success, data = turtle.inspect()
- if not success or not isWoodBlock(data.name) then
- break -- Hit non-wood block (leaves, air, etc.)
- end
- end
- -- Turn around (180 degrees)
- turtle.turnRight()
- turtle.turnRight()
- -- Move back to starting position
- for i = 1, counter do
- turtle.forward()
- end
- -- Face original direction
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- -- Function to detect if the tree is 2x2 by checking adjacent blocks
- local function is2x2Tree()
- local success, data = turtle.inspect() -- Block in front (east)
- if not (success and isWoodBlock(data.name)) then
- return false -- Not even a trunk in front
- end
- local woodType = data.name -- Store the wood type for comparison
- -- Turn right to check south block
- turtle.turnRight()
- success, data = turtle.inspect() -- Block to south
- if not (success and data.name == woodType) then
- turtle.turnLeft() -- Restore orientation
- return false
- end
- -- Move forward and check southeast block
- turtle.dig()
- if not turtle.forward() then
- turtle.turnLeft()
- return false
- end
- success, data = turtle.inspect() -- Block to south (from new position)
- if not (success and data.name == woodType) then
- turtle.back()
- turtle.turnLeft()
- return false
- end
- -- Return to starting position
- turtle.back()
- turtle.turnLeft()
- return true
- end
- -- Function to mine 2x2 trunk at current height and check branches
- local function mine2x2Trunk()
- -- Assume turtle is in bottom-left (southwest) corner, facing east
- -- Path: mine bottom-left, move to bottom-right, top-right, top-left, return to bottom-left
- turtle.dig() -- Mine bottom-left
- turtle.turnLeft() -- Face north to check branch
- handleBranch() -- Check south (left relative to east)
- turtle.turnRight() -- Face east
- turtle.forward() -- Move to bottom-right
- turtle.dig() -- Mine bottom-right
- turtle.turnRight() -- Face south to check branch
- handleBranch() -- Check east (left relative to north)
- turtle.turnLeft() -- Face north
- turtle.forward() -- Move to top-right
- turtle.dig() -- Mine top-right
- turtle.turnRight() -- Face west to check branch
- handleBranch() -- Check north (left relative to west)
- turtle.turnLeft() -- Face west
- turtle.forward() -- Move to top-left
- turtle.dig() -- Mine top-left
- turtle.turnRight() -- Face north to check branch
- handleBranch() -- Check west (left relative to south)
- turtle.turnLeft() -- Face south
- turtle.forward() -- Move to bottom-left
- turtle.turnRight() -- Face east (restore starting orientation)
- end
- -- Main tree felling function
- local function fellTree()
- -- Detect tree type
- local is2x2 = is2x2Tree()
- if is2x2 then
- -- 2x2 tree logic
- while true do
- mine2x2Trunk()
- -- Dig up in bottom-left position and try to move up
- turtle.digUp()
- if not turtle.up() then
- break -- Can't move up anymore
- end
- -- Dig up in other three positions to clear trunk
- turtle.forward()
- turtle.digUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.digUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.digUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft() -- Back to bottom-left, facing east
- end
- else
- -- 1x1 tree logic (your corrected version)
- turtle.dig()
- turtle.forward()
- while true do
- turtle.digUp()
- -- Check for branches in all four directions
- for i = 1, 4 do
- handleBranch()
- turtle.turnRight() -- Check next direction
- end
- if not turtle.up() then
- break -- Can't move up
- end
- end
- end
- -- Return to ground
- while turtle.down() do
- -- Do nothing, just go down
- end
- end
- -- Main program
- print("Starting simp_tree with 1x1 and 2x2 tree handling...")
- fellTree()
- print("Tree felling complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement