Advertisement
JoshP95

Autotunnel 2x2 - Izzobot

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