Advertisement
JoshP95

Autotunnel 2x2 - Izzobot

Jun 13th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1. --[[
  2. Autotunnel Program
  3. Created by Izzobot
  4.  
  5. Mines out a 2x2 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 moveBack()
  49.     if turtle.getFuelLevel() == 0 then
  50.         refuel()
  51.     end
  52.  
  53.  while turtle.back() == false do
  54.     digForward()
  55.     turtle.attack()
  56.  end  
  57.  
  58. end
  59.  
  60. function placeDown()
  61.     changeSlot()
  62.     turtle.placeDown()
  63. end
  64.  
  65. function placeUp()
  66.     changeSlot()
  67.     turtle.placeUp()
  68. end
  69.  
  70. function placeForward()
  71.     changeSlot()
  72.     turtle.place()
  73. end
  74.  
  75. function moveUp()
  76.     if turtle.getFuelLevel() == 0 then
  77.         refuel()
  78.     end
  79.  
  80.     while turtle.up() == false do
  81.         turtle.digUp()
  82.     end  
  83. end
  84.  
  85. function moveDown()
  86.     if turtle.getFuelLevel() == 0 then
  87.         refuel()
  88.     end
  89.  
  90.     while turtle.down() == false do
  91.         turtle.digDown()
  92.     end
  93. end
  94.  
  95. function enoughItems()
  96.     total = 0
  97.         for slot=2,16 do -- Count the number of blocks
  98.         total = total + turtle.getItemCount(slot)
  99.         end
  100.     if total < l*8 then
  101.         print("More blocks required.")
  102.         if total ~= 0 then
  103.             io.write("Continue? (y/n): ")
  104.             answer = io.read()
  105.             if answer == "y" then
  106.                 print("Continuing...")
  107.             else
  108.                 print("Cancelled.")
  109.                 error()
  110.             end
  111.         else
  112.             print("No blocks in inventory.")
  113.             error()
  114.         end
  115.     end
  116. end
  117.  
  118. function changeSlot()
  119.     if turtle.getItemCount() == 0 then
  120.         for i=2,16 do
  121.             turtle.select(i)
  122.             if turtle.getItemCount(i) ~= 0 then
  123.                 break
  124.             end
  125.         end
  126.     end
  127. end
  128.  
  129. -- Start of Code
  130. turtle.select(2)
  131. print(" ")
  132. print("[Auto-tunnel]\n")
  133. io.write("Length: ")
  134. l = io.read()
  135. print(" ")
  136. enoughItems()
  137. print("Building...")
  138.  
  139. for i=1,l do
  140.     digForward()
  141.     moveForward()
  142.     placeDown()
  143.     turtle.turnLeft()
  144.     placeForward()
  145.     moveUp()
  146.     placeForward()
  147.     placeUp()
  148.     turtle.turnRight()
  149.     turtle.turnRight()
  150.     moveForward()
  151.     placeUp()
  152.     placeForward()
  153.     moveDown()
  154.     placeForward()
  155.     turtle.turnLeft()
  156.     placeDown()
  157.     turtle.turnLeft()
  158.     moveForward()
  159.     turtle.turnRight()
  160. end
  161.  
  162. print("Tunnel complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement