Advertisement
HandieAndy

BigTreeChop

Dec 16th, 2017
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. --Program to chop trees wider than 1 block. Used for tall, slender trees.
  2. --Author: Andrew Lalis
  3.  
  4. --Tries moving forward until successful.
  5. function safeForward()
  6.     local success
  7.     repeat
  8.         success = turtle.forward()
  9.     until (success)
  10. end
  11.  
  12. --Chops a vertical pillar of wood.
  13. function chopPillar()
  14.     local success,data = turtle.inspectUp()
  15.     local woodName = data.name
  16.     local displacement = 0
  17.     repeat
  18.         turtle.digUp()
  19.         turtle.up()
  20.         displacement = displacement + 1
  21.         success,data = turtle.inspectUp()
  22.     until (data == nil or data.name ~= woodName)
  23.     for i=1,displacement do
  24.         turtle.down()
  25.     end
  26. end
  27.  
  28. --Chops one row of the tree.
  29. function chopRow(treeSize)
  30.     for i=1,treeSize do
  31.         if (turtle.detect()) then
  32.             turtle.dig()
  33.             safeForward()
  34.             if (turtle.detectUp()) then
  35.                 chopPillar()
  36.             end
  37.         else
  38.             safeForward()
  39.         end
  40.     end
  41. end
  42.  
  43. --Gets the tree size from the user.
  44. function getTreeSize(args)
  45.     if (args[1] ~= nil) then
  46.         return tonumber(args[1])
  47.     else
  48.         print("Please enter the diameter of the tree.")
  49.         return tonumber(read())
  50.     end
  51. end
  52.  
  53. local args = {...}
  54. local treeSize = getTreeSize(args)
  55. for i=1,treeSize do
  56.     safeForward()
  57.     chopRow(treeSize)
  58.     safeForward()
  59.     if (i % 2 == 1) then
  60.         turtle.turnRight()
  61.         safeForward()
  62.         turtle.turnRight()
  63.     else
  64.         turtle.turnLeft()
  65.         safeForward()
  66.         turtle.turnLeft()
  67.     end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement