mjmac85

tunneler

Dec 31st, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 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. --  Completed
  12. --  Things to add - rednet support
  13.  
  14. write("Length: ")
  15. local length = tonumber(read())
  16.  
  17.  
  18. local function fuel(currentSlot)
  19.     while turtle.getFuelLevel() <= 5 do
  20.         turtle.select(16)
  21.         turtle.refuel(1)
  22.         print(turtle.getFuelLevel())
  23.     end
  24.  
  25.     turtle.select(currentSlot)
  26.  
  27. end
  28.  
  29. local function checkDown(currentSlot)
  30.     if turtle.detectDown() == false then
  31.         turtle.select(1)
  32.         turtle.placeDown()
  33.         turtle.select(currentSlot)
  34.     end
  35.    
  36. end
  37.  
  38.  
  39.  
  40.  
  41.  
  42. --local function inventoryCheck()
  43. --    if turtle.getItemCount(14) > 0 then
  44. --        dropItems()
  45. --    end
  46. --end
  47.  
  48. local function dropItems(distance, currentSlot)
  49. -- Returns back to chest area and drops items
  50.     local selector = 3
  51.     local back = 0
  52.     --turns turtle around and heads back
  53.     turtle.turnRight()
  54.     turtle.turnRight()
  55.     while back <= distance do
  56.         fuel(currentSlot)
  57.         turtle.forward()
  58.         back = back + 1
  59.     end
  60.    
  61.        
  62.     --drops items into chest
  63.     turtle.select(3)
  64.     while selector <= 14 do
  65.         turtle.select(selector)  
  66.         turtle.drop()
  67.         selector = selector + 1
  68.     end
  69.     turtle.select(currentSlot)
  70.     turtle.turnRight()
  71.     turtle.turnRight()
  72.     back = 0
  73.    
  74.     --  Heads back into the mine
  75.     while back <= distance do
  76.         fuel(currentSlot)
  77.         turtle.forward()
  78.         back = back + 1
  79.     end
  80.  
  81. end
  82.  
  83. local function mine(currentSlot)
  84.     fuel(currentSlot)
  85.     while turtle.forward() == false do
  86.         turtle.dig()
  87.     end
  88.     checkDown(currentSlot)
  89.     turtle.digUp()
  90. end
  91.  
  92. local function main()
  93.     local fuelSlot = 16
  94.     local currentSlot = 1
  95.     local bridgeSlot = 1
  96.     local torchSlot = 2
  97.     local distance = 0
  98.     local back = 0
  99.     local selector = 3
  100.     while distance <= length - 1 do
  101.         fuel(currentSlot)
  102.         turtle.select(fuelSlot)
  103.         if turtle.getItemCount(14) > 0 then
  104.             dropItems(distance, currentSlot)
  105.         end
  106.         mine(currentSlot)
  107.         -- Torch Drop
  108.         distance = distance + 1
  109.         if distance % 8 == 0 then
  110.             turtle.select(2)
  111.             turtle.back()
  112.             turtle.placeUp()
  113.             turtle.forward()
  114.             turtle.select(currentSlot)
  115.         end
  116.     -- end main distance loop
  117.     end
  118.    
  119.     -- returns at the end
  120.     turtle.turnRight()
  121.     turtle.turnRight()
  122.     while back <= distance do
  123.         fuel(currentSlot)
  124.         turtle.forward()
  125.         back = back + 1
  126.     end
  127.    
  128.        
  129.     --drops items into chest
  130.     turtle.select(3)
  131.     while selector <= 14 do
  132.         turtle.select(selector)  
  133.         turtle.drop()
  134.         selector = selector + 1
  135.     end
  136.     turtle.select(currentSlot)
  137.     turtle.turnRight()
  138.     turtle.turnRight()
  139. -- end func
  140. end
  141.  
  142. main()
Advertisement
Add Comment
Please, Sign In to add comment