mjmac85

tunnelargs

Jan 1st, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.24 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 do
  62.         fuel(currentSlot)
  63.         turtle.forward()
  64.         back = back + 1
  65.     end
  66.    
  67.        
  68.     --drops items into chest
  69.     turtle.select(3)
  70.     while selector <= 14 do
  71.         turtle.select(selector)  
  72.         turtle.drop()
  73.         selector = selector + 1
  74.     end
  75.     turtle.select(currentSlot)
  76.     turtle.turnRight()
  77.     turtle.turnRight()
  78.     back = 0
  79.    
  80.     --  Heads back into the mine
  81.     while back <= distance do
  82.         fuel(currentSlot)
  83.         turtle.forward()
  84.         back = back + 1
  85.     end
  86.  
  87. end
  88.  
  89. local function mine(currentSlot)
  90.     fuel(currentSlot)
  91.     while turtle.forward() == false do
  92.         turtle.dig()
  93.     end
  94.     checkDown(currentSlot)
  95.     turtle.digUp()
  96. end
  97.  
  98. local function main()
  99.     local fuelSlot = 16
  100.     local currentSlot = 1
  101.     local bridgeSlot = 1
  102.     local torchSlot = 2
  103.     local distance = 0
  104.     local back = 0
  105.     local selector = 3
  106.     while distance <= length - 1 do
  107.         fuel(currentSlot)
  108.         turtle.select(fuelSlot)
  109.         if turtle.getItemCount(14) > 0 then
  110.             dropItems(distance, currentSlot)
  111.         end
  112.         mine(currentSlot)
  113.         -- Torch Drop
  114.         distance = distance + 1
  115.         if distance % 8 == 0 then
  116.             turtle.select(2)
  117.             turtle.back()
  118.             turtle.placeUp()
  119.             turtle.forward()
  120.             turtle.select(currentSlot)
  121.         end
  122.     -- end main distance loop
  123.     end
  124.    
  125.     -- returns at the end
  126.     turtle.turnRight()
  127.     turtle.turnRight()
  128.     while back <= distance do
  129.         fuel(currentSlot)
  130.         turtle.forward()
  131.         back = back + 1
  132.     end
  133.    
  134.        
  135.     --drops items into chest
  136.     turtle.select(3)
  137.     while selector <= 14 do
  138.         turtle.select(selector)  
  139.         turtle.drop()
  140.         selector = selector + 1
  141.     end
  142.     turtle.select(currentSlot)
  143.     turtle.turnRight()
  144.     turtle.turnRight()
  145. -- end func
  146. end
  147.  
  148. main()
Advertisement
Add Comment
Please, Sign In to add comment