arbarr3

stairs3x3

Nov 23rd, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | None | 0 0
  1. local args = { ... }
  2.  
  3. numArgs = table.getn(args)
  4.  
  5. TORCH_INTERVAL = 5
  6.  
  7. function fuel ()
  8.   if turtle.getFuelLevel() == 0 then
  9.     turtle.select(1)
  10.     turtle.refuel(1)
  11.   end
  12. end
  13.  
  14. function plantTunnelTorch ()
  15.   turtle.select(2)
  16.   turtle.placeDown()
  17. end
  18.  
  19. function goodDig ()
  20.   while turtle.detect() do
  21.     fuel()
  22.     turtle.dig()
  23.     sleep(0.5)
  24.   end
  25.   fuel()
  26. end
  27.  
  28. function goodDigUp ()
  29.   while turtle.detectUp() do
  30.     fuel()
  31.     turtle.digUp()
  32.     sleep(0.5)
  33.   end
  34.   fuel()
  35. end
  36.  
  37. function threeByThree ()
  38.   goodDigUp()
  39.   turtle.digDown()
  40.   fuel()
  41.   turtle.turnLeft()
  42.   goodDig()
  43.   turtle.forward()
  44.   goodDigUp()
  45.   turtle.digDown()
  46.   fuel()
  47.   turtle.back()
  48.   fuel()
  49.   turtle.turnRight()
  50.   fuel()
  51.   turtle.turnRight()
  52.   goodDig()
  53.   turtle.forward()
  54.   fuel()
  55.   goodDigUp()
  56.   turtle.digDown()
  57.   fuel()
  58.   turtle.back()
  59.   fuel()
  60.   turtle.turnLeft()
  61. end
  62.  
  63. function twoByTwo()
  64.   goodDigUp()
  65.   turtle.digDown()
  66.   fuel()
  67.   turtle.turnRight()
  68.   goodDig()
  69.   turtle.forward()
  70.   fuel()
  71.   goodDigUp()
  72.   turtle.digDown()
  73.   fuel()
  74.   turtle.back()
  75.   fuel()
  76.   turtle.turnLeft()
  77. end
  78.  
  79. function tunnel (len)
  80.   count = 0
  81.   torch = TORCH_INTERVAL
  82.   while count < len do
  83.     threeByThree()
  84.  
  85.     --Stairs
  86.     fuel()
  87.     turtle.up()
  88.     threeByThree()
  89.     turtle.up()
  90.     threeByThree()
  91.     turtle.down()
  92.     --EndStairs
  93.    
  94.     if torch == TORCH_INTERVAL then
  95.       plantTunnelTorch()
  96.       torch = 0
  97.     end
  98.     goodDig()
  99.     turtle.forward()    
  100.     fuel()
  101.     count = count+1
  102.     torch = torch+1
  103.   end
  104. end
  105.  
  106. function leftOrRight (dire)
  107.   threeByThree()
  108.   goodDig()
  109.   turtle.forward()
  110.   threeByThree()
  111.   turtle.back()
  112.   fuel()
  113.   if dire == 'l' then
  114.     turtle.turnLeft()
  115.   elseif dire == 'r' then
  116.     turtle.turnRight()
  117.   else
  118.     term.write("Error, bad direction.")
  119.   end
  120. end
  121.  
  122. --================Main===============--
  123.  
  124. if numArgs == 1.0 then
  125.   digNum = tonumber(args[1])
  126.   tunnel(digNum)
  127. elseif numArgs == 2.0 or numArgs == 3.0 then
  128.  
  129.   if numArgs == 3.0 then
  130.     intervalWidth = tonumber(args[3])
  131.   else
  132.     intervalWidth = TORCH_INTERVAL
  133.   end
  134.  
  135.   digNum = tonumber(args[1])
  136.   direction = args[2]
  137.   if direction ~= 'r' and direction ~= 'l' then
  138.     error("Second argument must be 'r' or 'l'")
  139.   end
  140.   tunnel(digNum)
  141.   leftOrRight(direction)
  142.   tunnel(intervalWidth)
  143.   leftOrRight(direction)
  144.   tunnel(digNum)
  145. else
  146.   error("Usage: dig [int] opt[l | r]")
  147. end
Advertisement
Add Comment
Please, Sign In to add comment