Advertisement
wolfd

Untitled

Aug 16th, 2014
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. -- Build Tools
  2. -- dig v1
  3.  
  4. local args = { ... }
  5.  
  6. if args[1] == nil or args[2] == nil or args[3] == nil or args[1] == "help" then
  7.   print ("Usage: dig [forward length] [right length] [height]")
  8.   return
  9. end
  10.  
  11. local tilt = 0
  12. local flength = tonumber(args[1])
  13. local rlength = tonumber(args[2])
  14. local height = tonumber(args[3])
  15. local blocks = rlength * flength * height
  16.  
  17. function step()
  18.   while not turtle.forward() do
  19.     turtle.dig()
  20.   end
  21. end
  22.  
  23. function stepUp()
  24.   while not turtle.up() do
  25.     turtle.digUp()
  26.   end
  27. end
  28.  
  29. function stepDown()
  30.   while not turtle.down() do
  31.     turtle.digDown()
  32.   end
  33. end
  34.  
  35. function placeUp()
  36.   while not turtle.placeUp() do
  37.     turtle.digUp()
  38.   end
  39. end
  40.  
  41. function rotateRight()
  42.   turtle.turnRight()
  43.   if vertical then
  44.     stepDown()
  45.   else
  46.     step()
  47.   end
  48.   turtle.turnRight()
  49. end
  50.  
  51. function rotateLeft()
  52.   turtle.turnLeft()
  53.   if vertical then
  54.     stepDown()
  55.   else
  56.     step()
  57.   end
  58.   turtle.turnLeft()
  59. end
  60.  
  61. -- Dump inventory into ender chest.
  62. function dump()
  63.   turtle.select(1)
  64.   placeUp()
  65.   for m = 2, 16, 1 do
  66.     turtle.select(m)
  67.     turtle.dropUp()
  68.   end
  69.   turtle.select(1)
  70.   turtle.digUp()
  71. end
  72.  
  73. -- Dig 'em up.
  74. for i = 1, height, 1 do
  75.   for j = 1, rlength, 1 do
  76.     for k = 1, flength, 1 do
  77.       if turtle.getItemCount(16) > 1 then
  78.         -- dump()
  79.       end
  80.       turtle.digUp()
  81.       if k < flength then
  82.         step()
  83.       end
  84.     end
  85.     if j < rlength then
  86.       if (j + tilt) % 2 ~= 0 then
  87.         rotateRight()
  88.       else
  89.         rotateLeft()
  90.       end
  91.     end
  92.   end
  93.   if rlength % 2 == 0 and i % 2 ~= 0 then
  94.     tilt = 1
  95.   else
  96.     tilt = 0
  97.   end
  98.   turtle.turnRight()
  99.   turtle.turnRight()
  100.   stepUp()
  101. end
  102.  
  103. -- Raise to initial height.
  104. for i = 1, height, 1 do
  105.   stepDown()
  106. end
  107.  
  108. -- Return to origin.
  109. if height % 2 ~= 0 then
  110.   if rlength % 2 == 0 then
  111.     turtle.turnLeft()
  112.     for i = 1, rlength - 1, 1 do
  113.       step()
  114.     end
  115.   else
  116.     turtle.turnRight()
  117.     for i = 1, rlength - 1, 1 do
  118.       step()
  119.     end
  120.     turtle.turnLeft()
  121.     for i = 1, flength - 1, 1 do
  122.       step()
  123.     end
  124.   end
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement