Advertisement
cowslaw

3x3 Tunnel Miner

Jun 10th, 2013
111
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.
  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 ~= 1 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() <= 10 then
  44.     turtle.select(1)
  45.     turtle.refuel(1)
  46.     turtle.select(1)
  47.   end
  48. end
  49.  
  50. function turnAround()
  51.   turtle.turnRight()
  52.   turtle.turnRight()
  53. end
  54.  
  55. function checkTopBottom()
  56.   if turtle.detectUp() then
  57.     turtle.digUp()
  58.   end
  59.   if turtle.detectDown() then
  60.     turtle.digDown()
  61.   end
  62. end
  63.  
  64. function checkFront()
  65.   if turtle.forward() == false then
  66.     repeat
  67.       turtle.attack()
  68.       turtle.dig()
  69.       sleep(0.25)
  70.     until turtle.forward() == true
  71.   end
  72. end
  73.  
  74. function checkInventoryFull(currentDistance)
  75.   if turtle.getItemCount(16) > 60 then
  76.     turnAround()
  77.  
  78.     for b = 1, currentDistance do
  79.       checkFuel()
  80.       checkFront()
  81.     end
  82.  
  83.     for e = 3, 16 do
  84.       turtle.select(e)
  85.       turtle.dropDown()
  86.     end
  87.  
  88.     turnAround()
  89.  
  90.     for b = 1, currentDistance do
  91.       checkFuel()
  92.       checkFront()
  93.     end
  94.   end
  95. end
  96.  
  97. -- Main Script
  98. checkFuel()
  99.  
  100. if offset > 0 then
  101.   for o = 1, offset do
  102.     turtle.forward()
  103.   end
  104. end
  105.  
  106. for i = 1, togo do
  107.   amount = amount + 1
  108.   torch = torch + 1
  109.   percentage = percentage + 1
  110.   outcome = percentage / togo * 100
  111.   term.clear()
  112.   term.setCursorPos(1, 1)
  113.   print("On block " .. amount .. " of " .. togo .. ".")
  114.   print(round(outcome, 3) .. "% complete.")
  115.   checkFuel()
  116.   digForward()
  117.   checkTopBottom()
  118.   turtle.turnRight()
  119.   digForward()
  120.   checkTopBottom()
  121.   turnAround()
  122.   checkFront()
  123.   digForward()
  124.   checkTopBottom()
  125.   turnAround()
  126.   checkFront()
  127.   turtle.turnLeft()
  128.  
  129.   if torch == placement then
  130.     turtle.select(2)
  131.     turtle.down()
  132.     turnAround()
  133.     turtle.place()
  134.     turnAround()
  135.     turtle.up()
  136.     turtle.select(1)
  137.     torch = 0
  138.   end
  139.  
  140.   checkInventoryFull((offset + amount))
  141.  
  142.   outcome = 0
  143. end
  144.  
  145. turnAround()
  146.  
  147. for b = 1, (togo + offset) do
  148.   checkFuel()
  149.   checkFront()
  150. end
  151.  
  152. for e = 3, 16 do
  153.   turtle.select(e)
  154.   turtle.dropDown()
  155. end
  156.  
  157. turnAround()
  158.  
  159. print("Tunnel finished.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement