Advertisement
Guest User

sdig

a guest
Dec 17th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. -- NAME: SDIG
  2. -- usage SDIG <B> <Z> <S>
  3. -- digs a 1x3 tunnel of Z length in an S-shaped pattern, with B number of branches, with S spaces between each branch
  4. -- digs its way down main trunk to point of origin
  5.  
  6. local tArgs = {...}
  7. local BTarget = tonumber(tArgs[1])
  8. local ZTarget = tonumber(tArgs[2])
  9. local STarget = tonumber(tArgs[3])
  10. local BPass = 0
  11.  
  12. -- Dig a 1x3 chunk
  13. function ZDig()
  14.     while (turtle.detect()) do
  15.         turtle.dig()
  16.     end
  17.     turtle.forward()
  18.     turtle.digUp()
  19.     turtle.digDown()
  20. end
  21.  
  22.  
  23. -- Dig the branch of z length
  24. function Branch()
  25.     for i=1, ZTarget do
  26.         ZDig()
  27.         if i % 8 == 0 then -- places torches every 8 spaces
  28.             turtle.select(16)
  29.             turtle.placeDown()
  30.         end
  31.     end
  32.     BPass = BPass + 1 -- when the branch has been completed, increment the BPass
  33. end
  34.  
  35.  
  36. -- Turn the correct direction at end of branch
  37. function Orient()
  38.     if BPass % 2 == 0 then
  39.         turtle.turnLeft()
  40.     else
  41.         turtle.turnRight()
  42.     end
  43. end
  44.    
  45.    
  46. -- Dig to start of next branch (STarget spaces away)
  47. function GotoBranchStart()
  48.     for i=1, (STarget+1) do
  49.         ZDig()
  50.     end
  51.     Orient() -- point turtle in right direction
  52. end
  53.      
  54.      
  55. -- Return from location on main branch back to Origin
  56. function GotoOrigin()
  57.     if BPass > 1 then
  58.         for i=1, (BPass-1)*(1+STarget) do
  59.             while (turtle.detect()) do
  60.                 turtle.dig()
  61.             end
  62.             turtle.forward()
  63.             turtle.digUp()
  64.             turtle.digDown()
  65.         end
  66.     end
  67. end
  68.        
  69. -- PROGRAM
  70.  
  71.  
  72.  
  73. Branch()
  74. while BPass < BTarget do
  75.     Orient()
  76.     GotoBranchStart()
  77.     Branch()
  78. end
  79. if BPass % 2 ~= 0 then
  80.     turtle.turnRight()
  81.     turtle.turnRight()
  82.     for i=1, ZTarget do
  83.         turtle.forward()
  84.     end -- now back at main branch
  85. end
  86. turtle.turnRight()
  87. GotoOrigin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement