Advertisement
JoshP95

Autotunnel 1x2 - Izzobot

Jun 13th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. --[[
  2. Autotunnel Program
  3. Created by Izzobot
  4.  
  5. Mines out a 1x2 tunnel and surrounds tunnel with material in slots 2-16.
  6. ]]--
  7.  
  8. FUEL_SLOT = 1
  9.  
  10. -- Functions
  11.  
  12. function refuel()
  13.     turtle.select(FUEL_SLOT)
  14.     items = turtle.getItemCount(FUEL_SLOT)
  15.     fuel = turtle.getFuelLevel(FUEL_SLOT)
  16.     if fuel == 0 then   -- When no fuel
  17.         if items ~= 0 then
  18.             print("Refuelling...")
  19.             turtle.refuel(FUEL_SLOT)
  20.             print("Refueled!")
  21.         else    -- If no fuel present
  22.             print("Add more fuel to slot " .. FUEL_SLOT)
  23.          error()
  24.         end
  25.     else
  26.         print("Fuel level sufficient")
  27.     end
  28. end
  29.  
  30. function digForward()
  31.     while turtle.detect() do
  32.         turtle.dig()
  33.     end
  34. end
  35.  
  36. function moveForward()
  37.     if turtle.getFuelLevel() == 0 then
  38.         refuel()
  39.     end
  40.  
  41.  while turtle.forward() == false do
  42.     digForward()
  43.     turtle.attack()
  44.  end  
  45.  
  46. end
  47.  
  48. function placeDown()
  49.     changeSlot()
  50.     turtle.placeDown()
  51. end
  52.  
  53. function placeUp()
  54.     changeSlot()
  55.     turtle.placeUp()
  56. end
  57.  
  58. function placeForward()
  59.     changeSlot()
  60.     turtle.place()
  61. end
  62.  
  63. function moveUp()
  64.     if turtle.getFuelLevel() == 0 then
  65.         refuel()
  66.     end
  67.  
  68.     while turtle.up() == false do
  69.         turtle.digUp()
  70.     end  
  71. end
  72.  
  73. function moveDown()
  74.     if turtle.getFuelLevel() == 0 then
  75.         refuel()
  76.     end
  77.  
  78.     while turtle.down() == false do
  79.         turtle.digDown()
  80.     end
  81. end
  82.  
  83. function enoughItems()
  84.     total = 0
  85.         for slot=2,16 do -- Count the number of blocks
  86.         total = total + turtle.getItemCount(slot)
  87.         end
  88.     if total < l*6 then
  89.         print("More blocks required.")
  90.         if total ~= 0 then
  91.             io.write("Continue? (y/n): ")
  92.             answer = io.read()
  93.             if answer == "y" then
  94.                 print("Continuing...")
  95.             else
  96.                 print("Cancelled.")
  97.                 error()
  98.             end
  99.         else
  100.             print("No blocks in inventory.")
  101.             error()
  102.         end
  103.     end
  104. end
  105.  
  106. function changeSlot()
  107.     if turtle.getItemCount() == 0 then
  108.         for i=2,16 do
  109.             turtle.select(i)
  110.             if turtle.getItemCount(i) ~= 0 then
  111.                 break
  112.             end
  113.         end
  114.     end
  115. end
  116.  
  117. -- Start of Code
  118. turtle.select(2)
  119. print(" ")
  120. print("[Auto-tunnel]\n")
  121. io.write("Length: ")
  122. l = io.read()
  123. print(" ")
  124. enoughItems()
  125. print("Building...")
  126.  
  127. for i=1,l do
  128.     digForward()
  129.     moveForward()
  130.     placeDown()
  131.     turtle.turnLeft()
  132.     placeForward()
  133.     moveUp()
  134.     placeForward()
  135.     turtle.turnRight()
  136.     placeUp()
  137.     turtle.turnRight()
  138.     placeForward()
  139.     moveDown()
  140.     placeForward()
  141.     turtle.turnLeft()
  142. end
  143.  
  144. print("Tunnel complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement