Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Example of recursion to dig branched or large trees
- -- ensure there is a log of the tree type in slot 1
- function isTree(direction)
- result = false
- turtle.select(1) --select slot 1 which contains wood
- if direction == "up" then -- check block above
- if turtle.compareUp() then -- wood block above
- result = true
- end
- elseif direction == "down" then -- check block down
- if turtle.compareDown() then -- wood block below
- result = true
- end
- elseif direction == "forward" then -- check block ahead
- if turtle.compare() then -- wood block ahead
- result = true
- end
- end
- return result -- true/false
- end
- function mineTree(direction)
- --RECURSIVE FUNCTION - BEWARE!
- -- check if block in front is valuable. If so dig it
- -- direction only set to up/down if already called recursively
- if direction == "up" then
- if isTree("up") then
- turtle.digUp()
- end
- -- move up into space dug out
- turtle.up()
- -- check if item in front is valuable
- if isTree("forward") then
- mineTree("forward")
- end
- --check right side
- turtle.turnRight()
- if isTree("forward") then
- mineTree("forward")
- end
- --check behind
- turtle.turnRight()
- if isTree("forward") then
- mineTree("forward")
- end
- --check left side
- turtle.turnRight()
- if isTree("forward") then
- mineTree("forward")
- end
- --return to front
- turtle.turnRight()
- -- end of recursion so return to previous position
- turtle.down()
- end
- if direction == "down" then
- if isTree("down") then
- turtle.digDown()
- end
- -- move down into space dug out
- turtle.down()
- -- check if item in front is valuable
- if isTree("forward") then
- mineTree("forward")
- end
- --check right side
- turtle.turnRight()
- if isTree("forward") then
- mineTree("forward")
- end
- --check behind
- turtle.turnRight()
- if isTree("forward") then
- mineTree("forward")
- end
- --check left side
- turtle.turnRight()
- if isTree("forward") then
- mineTree("forward")
- end
- --return to front
- turtle.turnRight()
- -- end of recursion so return to previous position
- turtle.up()
- end
- if direction == "forward" then
- if isTree("forward") then
- turtle.dig()
- turtle.forward()
- if isTree("up") then
- mineTree("up")
- end
- if isTree("down") then
- mineTree("down")
- end
- -- check if item in front is valuable
- if isTree("forward") then
- mineTree("forward")
- end
- --check left side
- turtle.turnLeft()
- if isTree("forward") then
- mineTree("forward")
- end
- -- check right side
- turtle.turnRight()
- turtle.turnRight()
- if isTree("forward") then
- mineTree("forward")
- end
- turtle.turnLeft()
- -- end of recursion so return to previous position
- turtle.back()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement