Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Program to chop trees wider than 1 block. Used for tall, slender trees.
- --Author: Andrew Lalis
- --Tries moving forward until successful.
- function safeForward()
- local success
- repeat
- success = turtle.forward()
- until (success)
- end
- --Chops a vertical pillar of wood.
- function chopPillar()
- local success,data = turtle.inspectUp()
- local woodName = data.name
- local displacement = 0
- repeat
- turtle.digUp()
- turtle.up()
- displacement = displacement + 1
- success,data = turtle.inspectUp()
- until (data == nil or data.name ~= woodName)
- for i=1,displacement do
- turtle.down()
- end
- end
- --Chops one row of the tree.
- function chopRow(treeSize)
- for i=1,treeSize do
- if (turtle.detect()) then
- turtle.dig()
- safeForward()
- if (turtle.detectUp()) then
- chopPillar()
- end
- else
- safeForward()
- end
- end
- end
- --Gets the tree size from the user.
- function getTreeSize(args)
- if (args[1] ~= nil) then
- return tonumber(args[1])
- else
- print("Please enter the diameter of the tree.")
- return tonumber(read())
- end
- end
- local args = {...}
- local treeSize = getTreeSize(args)
- for i=1,treeSize do
- safeForward()
- chopRow(treeSize)
- safeForward()
- if (i % 2 == 1) then
- turtle.turnRight()
- safeForward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- safeForward()
- turtle.turnLeft()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement