dealingwith

Tunnel Program

May 27th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. function placeFloorBlock()
  2.   if not turtle.detectDown() then
  3.     turtle.select(3)
  4.     if turtle.placeDown() then
  5.       return true
  6.     end
  7.     print("Placing floor failed")
  8.     return false
  9.   end
  10. end
  11.  
  12. function fuel()
  13.   if turtle.getFuelLevel() < 25 then
  14.     turtle.select(1)
  15.     if turtle.refuel(1) then
  16.       return true
  17.     end
  18.     print ("Refuelling failed")
  19.     return false
  20.   end
  21. end
  22.  
  23. function DigAndMove()
  24.   while not turtle.forward() do
  25.     if not turtle.dig() then
  26.       turtle.attack()
  27.     end
  28.   end
  29.   while turtle.detectUp() do
  30.     turtle.digUp()
  31.     sleep(0.5)
  32.   end
  33.   placeFloorBlock()
  34. end
  35.  
  36. function turnAround()
  37.   turtle.turnLeft()
  38.   turtle.turnLeft()
  39. end
  40.  
  41. function placeTorch()
  42.   turtle.turnRight()
  43.   turtle.dig()
  44.   if not turtle.detect() then
  45.     turtle.select(2)
  46.     if turtle.place() then
  47.       turtle.turnLeft()
  48.       return true
  49.     end
  50.   end
  51.   print("Place torch failed")
  52.   turtle.turnLeft()
  53.   return false
  54. end
  55.  
  56. local tArgs = { ... }
  57. local length = tonumber(tArgs[1])
  58. local moveBack = 0
  59.  
  60. local blocksMovedForward = 0
  61. while blocksMovedForward < length do
  62.   fuel()
  63.   DigAndMove()
  64.   blocksMovedForward = blocksMovedForward + 1
  65.  
  66.   -- add torches
  67.   if (blocksMovedForward % 8) == 0 then
  68.     placeTorch()
  69.   end
  70.  
  71.   if blocksMovedForward == length then
  72.     turnAround()
  73.     while moveBack < length do
  74.       fuel()
  75.       turtle.forward()
  76.       moveBack = moveBack + 1
  77.     end
  78.   end
  79. end
  80.  
  81. turnAround()
Advertisement
Add Comment
Please, Sign In to add comment