Advertisement
agilag

FirstTestTunnel

May 27th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. --[[
  2.     Author
  3.         Rasmus Sommer mod by me
  4.    
  5.     How to use:
  6.         Slot 1 - Fuel
  7.         Slot 2 - Bridge material
  8.         Slot 3 - Torches
  9.    
  10.         torchedtunnel <length>
  11. --]]
  12.  
  13. local tArgs = { ... }
  14. if #tArgs ~= 1 then
  15.     print( "Usage: torchedtunnel <length>" )
  16.     return
  17. end
  18.  
  19. local length = tonumber( tArgs[1] )
  20. if length < 1 then
  21.     print( "Tunnel length must be positive" )
  22.     return
  23. end
  24.  
  25. local function tryRefuel()
  26.     if turtle.getFuelLevel() == 0 then
  27.         turtle.select(1)
  28.         turtle.refuel(1)
  29.     end
  30. end
  31.  
  32. local function tryDig()
  33.     while turtle.detect() == true do
  34.         turtle.dig()
  35.         sleep(0.5)
  36.     end
  37. end
  38.  
  39. local function tryDigUp()
  40.     while turtle.detectUp() == true do
  41.         turtle.digUp()
  42.         sleep(0.5)
  43.     end
  44. end
  45.  
  46. local function tryUp()
  47.     tryDigUp()
  48.     tryRefuel()
  49.     turtle.up()
  50. end
  51.  
  52. local function tryDown()
  53.     while turtle.detectDown() == true do
  54.         turtle.digDown()
  55.         sleep(0.5)
  56.     end
  57.     tryRefuel()
  58.     turtle.down()
  59. end
  60.  
  61. local function tryForward()
  62.     tryDig()
  63.     tryRefuel()
  64.     turtle.forward()
  65. end
  66.  
  67. local function tryBackward()
  68.     tryRefuel()
  69.     turtle.back()
  70. end
  71.  
  72. local function makeBridge()
  73.     if turtle.detectDown() == false then
  74.         turtle.select(2)
  75.         turtle.placeDown()
  76.     turtle.turnLeft()
  77.     if turtle.detect() == false then
  78.         turtle.place()
  79.     end
  80.     turtle.turnRight()
  81.     turtle.turnRight()
  82.     if turtle.detect() == false then
  83.         turtle.place()
  84.     end
  85.     turtle.turnLeft()
  86.     end
  87. end
  88.  
  89. local count = 1
  90. while true do
  91.     tryForward()
  92.     makeBridge()
  93.     tryDigUp()
  94.     if count % 8 == 0 then
  95.         turtle.select(3)
  96.         turtle.placeUp()
  97.     end
  98.     count = count + 1
  99. end
  100.  
  101. for i = 1, length do
  102.     tryBackward()
  103. end
  104. for i = 4, 16 do
  105.     turtle.select(i)
  106.     turtle.dropDown()
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement