mjmac85

Basic Tunnel Finished

Jan 1st, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.52 KB | None | 0 0
  1. print("--------------------------------------")
  2. print("Tunnel program - Created by Mjmac85")
  3. print("Bridge materials in slot 1")
  4. print("Torches in slot 2")
  5. print("Fuel in slot 16")
  6. print("--------------------------------------")
  7. --  Make checks for all the items
  8. --  Torch placement works
  9. --  Length works
  10. --  return trip completed
  11. --  Args support
  12. --  Things to add - rednet support
  13. args = {...}
  14. if args[1] == nil then
  15.     write("Length: ")
  16.     local length = tonumber(read())
  17. end
  18.  
  19. if args[1] ~= nil then
  20.     length = tonumber(args[1])
  21. end
  22.  
  23.  
  24. local function fuel(currentSlot)
  25.     while turtle.getFuelLevel() <= 5 do
  26.         turtle.select(16)
  27.         turtle.refuel(1)
  28.         print(turtle.getFuelLevel())
  29.     end
  30.  
  31.     turtle.select(currentSlot)
  32.  
  33. end
  34.  
  35. local function checkDown(currentSlot)
  36.     if turtle.detectDown() == false then
  37.         turtle.select(1)
  38.         turtle.placeDown()
  39.         turtle.select(currentSlot)
  40.     end
  41.    
  42. end
  43.  
  44.  
  45.  
  46.  
  47.  
  48. --local function inventoryCheck()
  49. --    if turtle.getItemCount(14) > 0 then
  50. --        dropItems()
  51. --    end
  52. --end
  53.  
  54. local function dropItems(distance, currentSlot)
  55. -- Returns back to chest area and drops items
  56.     local selector = 3
  57.     local back = 0
  58.     --turns turtle around and heads back
  59.     turtle.turnRight()
  60.     turtle.turnRight()
  61.     while back <= distance - 1 do
  62.         fuel(currentSlot)
  63.         while turtle.forward() == false do
  64.             turtle.dig()
  65.         end
  66.         checkDown(currentSlot)
  67.         back = back + 1
  68.     end
  69.    
  70.        
  71.     --drops items into chest
  72.     turtle.select(3)
  73.     while selector <= 14 do
  74.         turtle.select(selector)  
  75.         turtle.drop()
  76.         selector = selector + 1
  77.     end
  78.     turtle.select(currentSlot)
  79.     turtle.turnRight()
  80.     turtle.turnRight()
  81.     back = 0
  82.    
  83.     --  Heads back into the mine
  84.     while back <= distance - 1 do
  85.         fuel(currentSlot)
  86.         while turtle.forward() == false do
  87.             turtle.dig()
  88.         end
  89.         checkDown(currentSlot)
  90.         back = back + 1
  91.     end
  92.  
  93. end
  94.  
  95. local function mine(currentSlot)
  96.     fuel(currentSlot)
  97.     while turtle.forward() == false do
  98.         turtle.dig()
  99.     end
  100.     checkDown(currentSlot)
  101.     turtle.digUp()
  102. end
  103.  
  104. local function main()
  105.     local fuelSlot = 16
  106.     local currentSlot = 1
  107.     local bridgeSlot = 1
  108.     local torchSlot = 2
  109.     local distance = 0
  110.     local back = 0
  111.     local selector = 3
  112.     while distance <= length - 1 do
  113.         fuel(currentSlot)
  114.         turtle.select(fuelSlot)
  115.         if turtle.getItemCount(14) > 0 then
  116.             dropItems(distance, currentSlot)
  117.         end
  118.         mine(currentSlot)
  119.         -- Torch Drop
  120.         distance = distance + 1
  121.         if distance % 8 == 0 then
  122.             turtle.select(2)
  123.             turtle.back()
  124.             turtle.placeUp()
  125.             turtle.forward()
  126.             turtle.select(currentSlot)
  127.         end
  128.     -- end main distance loop
  129.     end
  130.    
  131.     -- returns at the end
  132.     turtle.turnRight()
  133.     turtle.turnRight()
  134.     while back <= distance - 1 do
  135.         fuel(currentSlot)
  136.         while turtle.forward() == false do
  137.             turtle.dig()
  138.         end
  139.         checkDown(currentSlot)
  140.         back = back + 1
  141.     end
  142.    
  143.        
  144.     --drops items into chest
  145.     turtle.select(3)
  146.     while selector <= 14 do
  147.         turtle.select(selector)  
  148.         turtle.drop()
  149.         selector = selector + 1
  150.     end
  151.     turtle.select(currentSlot)
  152.     turtle.turnRight()
  153.     turtle.turnRight()
  154. -- end func
  155. end
  156.  
  157. main()
Advertisement
Add Comment
Please, Sign In to add comment