Advertisement
Guest User

3x3tunnel

a guest
Sep 1st, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.21 KB | None | 0 0
  1.  
  2. local tArgs={...}
  3. if tArgs[1] == nil then
  4.   term.clear()
  5.   term.setCursorPos(1, 1)
  6.   print("How far do you want to go?")
  7.   tArgs[1] = read()
  8. end
  9.  
  10. local function clear()
  11.     term.clear()
  12.     term.setCursorPos(1, 1)
  13. end
  14.  
  15. local function timesfuelcheck()
  16.   term.clear()
  17.   term.setCursorPos(1, 1)
  18.   print("turtle will stop when this number reaches zero: "..m)
  19.   print("fuel remaining: "..turtle.getFuelLevel())
  20.   print("blocks dug: "..dignumb)
  21.   if extrainfonumb ~= 0 then
  22.     print(extrainfo)
  23.   elseif extrainfonumb == 0 then
  24.   end  
  25.   term.setCursorPos(1, 12)
  26.   print("Bottom right slot needs to have torches")
  27. end
  28.  
  29. local function checkdig()
  30.   while turtle.detect() do
  31.     turtle.dig()
  32.     dignumb=dignumb+1
  33.     timesfuelcheck()
  34.     sleep(.5)
  35.   end
  36.   while turtle.suck() do
  37.   end
  38. end
  39.  
  40. local function checkdigUp()
  41.   while turtle.suckUp() do
  42.   end
  43.   while turtle.detectUp() do
  44.     turtle.digUp()
  45.     dignumb=dignumb+1
  46.     timesfuelcheck()
  47.     sleep(.5)
  48.   end
  49. end
  50.  
  51. local function checkdigDown()
  52.   while turtle.suckDown() do
  53.   end
  54.   while turtle.detectDown() do
  55.     turtle.digDown()
  56.     dignumb=dignumb+1
  57.     timesfuelcheck()
  58.     sleep(.5)
  59.   end
  60. end
  61.  
  62. local function checkdigLeft()
  63.   turtle.turnLeft()
  64.   checkdig()
  65.   turtle.turnRight()
  66. end
  67.  
  68. local function checkdigRight()
  69.   turtle.turnRight()
  70.   checkdig()
  71.   turtle.turnLeft()
  72. end
  73.  
  74. local function checkplaceDown()
  75. turtle.select(1)
  76.   while not turtle.detectDown() do
  77.     if turtle.placeDown() == true then
  78.       turtle.placeDown()
  79.     elseif turtle.placeDown() == false then
  80.       x = 1
  81.       repeat
  82.         print("Something failed. Attempting to fix it.")
  83.         x=x+1
  84.         turtle.select(x)
  85.         sleep(.3)
  86.       until
  87.         x==15 or turtle.placeDown() == true
  88.           if x==15 then
  89.             term.clear()
  90.             term.setCursorPos(1, 1)
  91.             print("no placeable items in any of the slots")
  92.             print("rechecking in four seconds.")
  93.             print("4")
  94.             sleep(1)
  95.             print("3")
  96.             sleep(1)
  97.             print("2")
  98.             sleep(1)
  99.             print("1")
  100.             sleep(1)
  101.             print("rechecking")
  102.             sleep(.5)
  103.             checkplaceDown()
  104.           elseif turtle.placeDown() == true then
  105.             sleep(.3)
  106.             print("continuing")
  107.           end
  108.     end
  109.   end
  110. end
  111.  
  112.  
  113. BlocksNeeded = 10
  114. TorchesNeeded = tArgs[1] / 5
  115.  
  116. local i = 0
  117. local timer = os.startTimer(1)
  118. clear()
  119. while math.ceil(TorchesNeeded - turtle.getItemCount(16)-1) >= 0 do
  120.     clear()
  121.     if BlocksNeeded-turtle.getItemCount(1)-1 >= 0 then
  122.       print("I recommend "..BlocksNeeded-turtle.getItemCount(1).." more blocks.")
  123.     end
  124.     if math.ceil(TorchesNeeded - turtle.getItemCount(16)) >= 0 then
  125.       print("Need "..math.ceil(TorchesNeeded-turtle.getItemCount(16)).." more torches in the bottom right slot.")
  126.     else
  127.       print("Enough torches")
  128.     end
  129.     print()
  130.     print("       Press any letter to skip")
  131.  
  132.     local evt, arg = os.pullEvent()
  133.     if evt == "timer" then
  134.         if arg == timer then
  135.             i = i + 1
  136.             print(i)
  137.             timer = os.startTimer(1)
  138.         end
  139.     elseif evt == "char" then
  140.             break
  141.     end
  142. end
  143.  
  144. clear()
  145. turtle.select(1)
  146. dignumb = 0
  147. extrainfonumb = 0
  148. m = tArgs[1]
  149. torch = 5
  150. for i = 1, tArgs[1] do
  151.     timesfuelcheck()
  152.     checkdig()
  153.     turtle.forward()
  154.     checkdigLeft()
  155.     checkdigRight()
  156.     checkdigUp()
  157.     turtle.up()
  158.     checkdigLeft()
  159.     if torch == 5 then
  160.         turtle.turnRight()
  161.         checkdig()
  162.         turtle.select(16)
  163.         if turtle.place() == true then
  164.             extrainfonumb = 3
  165.             extrainfo = "placing torch"
  166.             timesfuelcheck()
  167.             turtle.place()
  168.             torch = 0
  169.         else
  170.           extrainfonumb = 3
  171.           extrainfo = "unable to place"
  172.           timesfuelcheck()
  173.           torch = 0
  174.         end
  175.         turtle.turnLeft()
  176.         turtle.select(1)
  177.     else
  178.         checkdigRight()
  179.     end
  180.     checkdigDown()
  181.     turtle.down()
  182.     checkdigDown()
  183.     turtle.down()
  184.     checkplaceDown()
  185.     checkdigLeft()
  186.     checkdigRight()
  187.     turtle.up()
  188.     torch = torch+1
  189.       if extrainfonumb ~= 0 then
  190.         extrainfonumb = extrainfonumb-1
  191.       end
  192.     m = m-1
  193.     timesfuelcheck()
  194. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement