Advertisement
cowslaw

3x3 Tunnel

Nov 29th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. -- 3x3 tunnel script by cowslaw. (Nov. 29, 2015)
  2. -- Usage: tunnel <distance> <offset> <torch>.
  3.  
  4. -- Arguments:
  5. --   distance: Distance turtle will dig.
  6. --   offset: Distance between starting point and start of tunnel.
  7. --   torch: How far apart torches are placed (default 10).
  8.  
  9. -- Slottage:
  10. --   Slot 1: Fuel (preferably coal)
  11. --   Slot 2: Torches (optional)
  12.  
  13. -- Variables (do not change):
  14. turtle.select(1)
  15. tArgs      = { ... }
  16.  
  17. if #tArgs ~= 3 then
  18.   print("Usage:\n  tunnel <distance> <offset> <torch>\n    Edit for argument descriptions.")
  19.   return
  20. end
  21.  
  22. togo       = tonumber(tArgs[1]) or 1
  23. offset     = tonumber(tArgs[2]) or 0
  24. placement  = (((tonumber(tArgs[3])) or 10) + 1) or 6
  25. torch      = 0
  26. amount     = 0
  27. percentage = 0
  28. outcome    = 0
  29.  
  30. -- Functions
  31. function digForward()
  32.   checkFuel()
  33.  
  34.   repeat
  35.     turtle.dig()
  36.     sleep(0.25)
  37.   until turtle.detect() == false
  38.  
  39.   checkFront()
  40. end
  41.  
  42. function checkFuel()
  43.   if turtle.getFuelLevel() <= 500 then
  44.     turtle.select(1)
  45.     turtle.refuel(1)
  46.   end
  47. end
  48.  
  49. function turnAround()
  50.   turtle.turnRight()
  51.   turtle.turnRight()
  52. end
  53.  
  54. function checkTopBottom()
  55.   if turtle.detectUp() then
  56.     turtle.digUp()
  57.   end
  58.   if turtle.detectDown() then
  59.     turtle.digDown()
  60.   end
  61. end
  62.  
  63. function checkFront()
  64.   if turtle.forward() == false then
  65.     repeat
  66.       turtle.attack()
  67.       turtle.dig()
  68.       sleep(0.25)
  69.     until turtle.forward() == true
  70.   end
  71. end
  72.  
  73. function checkInventoryFull(currentDistance)
  74.   if turtle.getItemCount(16) > 0 then
  75.     turnAround()
  76.  
  77.     for b = 1, currentDistance do
  78.       checkFuel()
  79.       checkFront()
  80.     end
  81.  
  82.     for e = 3, 16 do
  83.       turtle.select(e)
  84.       turtle.dropDown()
  85.     end
  86.  
  87.     turnAround()
  88.  
  89.     for b = 1, currentDistance do
  90.       checkFuel()
  91.       checkFront()
  92.     end
  93.   end
  94. end
  95.  
  96. -- Main Script
  97. checkFuel()
  98.  
  99. if offset > 0 then
  100.   for o = 1, offset do
  101.     turtle.forward()
  102.   end
  103. end
  104.  
  105. for i = 1, togo do
  106.   amount = amount + 1
  107.   torch = torch + 1
  108.   percentage = percentage + 1
  109.   outcome = percentage / togo * 100
  110.   term.clear()
  111.   term.setCursorPos(1, 1)
  112.   print("On block " .. amount .. " of " .. togo .. ".")
  113.   print(math.floor(outcome, 3) .. "% complete.")
  114.   checkFuel()
  115.   digForward()
  116.   checkTopBottom()
  117.   turtle.turnRight()
  118.   digForward()
  119.   checkTopBottom()
  120.   turnAround()
  121.   checkFront()
  122.   digForward()
  123.   checkTopBottom()
  124.   turnAround()
  125.   checkFront()
  126.   turtle.turnLeft()
  127.  
  128.   if torch == placement then
  129.     turtle.select(2)
  130.     turtle.down()
  131.     turnAround()
  132.     turtle.place()
  133.     turnAround()
  134.     turtle.up()
  135.     turtle.select(1)
  136.     torch = 0
  137.   end
  138.  
  139.   checkInventoryFull((offset + amount))
  140.  
  141.   outcome = 0
  142. end
  143.  
  144. turnAround()
  145.  
  146. for b = 1, (togo + offset) do
  147.   checkFuel()
  148.   checkFront()
  149. end
  150.  
  151. for e = 3, 16 do
  152.   turtle.select(e)
  153.   turtle.dropDown()
  154. end
  155.  
  156. turnAround()
  157.  
  158. print("Tunnel finished.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement