SHARE
TWEET

Untitled

a guest Mar 15th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 turtle.getItemCount(1) < 1 or args[1] == "help" then
  7.   print ("Usage: dig [forward length] [right length] [depth]")
  8.   print ("Put an ender chest in the first slot")
  9.   return
  10. end
  11.  
  12. local tilt = 0
  13. local flength = tonumber(args[1])
  14. local rlength = tonumber(args[2])
  15. local depth = tonumber(args[3])
  16. local blocks = rlength * flength * depth
  17.  
  18. if turtle.getFuelLevel() < blocks + rlength + flength + depth and args[4] ~= "-f" then
  19.   print ("You do not have enough fuel. This job needs ", fuelreq, " fuel.")
  20.   print ("Add more fuel, or append -f to dig anyway.")
  21.   return
  22. end
  23.  
  24. function step()
  25.   while not turtle.forward() do
  26.     turtle.dig()
  27. turtle.digUp()
  28. turtle.digDown()
  29.   end
  30. end
  31.  
  32. function stepUp()
  33.   while not turtle.up() do
  34.     turtle.digUp()
  35.   end
  36. end
  37.  
  38.  
  39. function placeUp()
  40.   while not turtle.placeUp() do
  41.     turtle.digUp()
  42.   end
  43. end
  44.  
  45. function rotateRight()
  46.   turtle.turnRight()
  47.   if vertical then
  48.     stepUp()
  49.   else
  50.     step()
  51.   end
  52.   turtle.turnRight()
  53. end
  54.  
  55. function rotateLeft()
  56.   turtle.turnLeft()
  57.   if vertical then
  58.     stepUp()
  59.   else
  60.     step()
  61.   end
  62.   turtle.turnLeft()
  63. end
  64.  
  65. -- Dump inventory into ender chest.
  66. function dump()
  67.   turtle.select(1)
  68.   placeUp()
  69.   for m = 2, 16, 1 do
  70.     turtle.select(m)
  71.     turtle.dropUp()
  72.   end
  73.   turtle.select(1)
  74.   turtle.digUp()
  75. end
  76.  
  77. -- Dig 'em up.
  78. for i = 1, depth, 1 do
  79.   for j = 1, rlength, 1 do
  80.     for k = 1, flength, 1 do
  81.       if turtle.getItemCount(16) > 1 then
  82.         dump()
  83.       end
  84.       turtle.digDown()
  85.       if k < flength then
  86.         step()
  87.       end
  88.     end
  89.     if j < rlength then
  90.       if (j + tilt) % 2 ~= 0 then
  91.         rotateRight()
  92.       else
  93.         rotateLeft()
  94.       end
  95.     end
  96.   end
  97.   if rlength % 2 == 0 and i % 2 ~= 0 then
  98.     tilt = 1
  99.   else
  100.     tilt = 0
  101.   end
  102.   turtle.turnRight()
  103.   turtle.turnRight()
  104.  turtle.digDown()
  105. os.sleep(1)
  106. turtle.down()
  107. os.sleep(1)
  108. turtle.digDown()
  109. os.sleep(1)
  110. turtle.down()
  111. os.sleep(1)
  112. turtle.digDown()
  113. os.sleep(1)
  114. turtle.down()
  115. end
  116.  
  117. -- Raise to initial height.
  118. for i = 1, depth, 1 do
  119.   stepUp()
  120. end
  121.  
  122. -- Return to origin.
  123. if depth % 2 ~= 0 then
  124.   if rlength % 2 == 0 then
  125.     turtle.turnLeft()
  126.     for i = 1, rlength - 1, 1 do
  127.       step()
  128.     end
  129.   else
  130.     turtle.turnRight()
  131.     for i = 1, rlength - 1, 1 do
  132.       step()
  133.     end
  134.     turtle.turnLeft()
  135.     for i = 1, flength - 1, 1 do
  136.       step()
  137.     end
  138.   end
  139. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top