Guest User

3x3tunnel

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