Advertisement
rachel8973

tunneller2.lua

Feb 11th, 2022 (edited)
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------------
  2. -- TUNNELER2
  3. -----------------------------------------------------------------------------------------------
  4. -- Rachel
  5. -- Create a 3x3 tunnel for n blocks
  6. -----------------------------------------------------------------------------------------------
  7.  
  8. -- Program Initialisation
  9.  
  10. -- Check running in turtle
  11. if not turtle then
  12.   printError("Requires a Turtle")
  13.   return
  14. end
  15.  
  16. -- Check input
  17. local tArgs = { ... }
  18. if #tArgs ~= 1 then
  19.    print("Usage: tunneller2 <distance>")
  20.    return
  21. end
  22.  
  23. local tLength = tonumber(tArgs[1])
  24. if tLength < 1 then
  25.   printError("Tunnel length must be positive")
  26.   return
  27. end
  28.  
  29. -- Check fuel
  30. if turtle.getFuelLevel() < 100 then
  31.    print("Refuel turtle!")
  32.    return
  33. end
  34.  
  35. -- Initialise Variables  
  36. pos = 0
  37.  
  38. -- Torch placing
  39. -- Assume torches in slot 16
  40. ts = 5   -- space between torches
  41. tc = 0   -- counter
  42.  
  43. -- March Onwards
  44. function goForwards()
  45.   if turtle.detect() then turtle.dig() end
  46.   turtle.attack()
  47.   turtle.forward()
  48. end
  49.  
  50. -- try Torch Place
  51. function torchPlace()
  52.   -- assume torches in slot 16
  53.   turtle.select(16)
  54.   if turtle.getItemCount() > 0 then
  55.     if not(turtle.detectDown()) then
  56.       turtle.placeDown()
  57.     end  
  58.   end
  59. end
  60.  
  61. -- Dig out section
  62. function digSection()
  63.   goForwards()
  64.   turtle.digUp()
  65.   turtle.digDown()
  66.   turtle.turnLeft()
  67.   goForwards()
  68.   turtle.digUp()
  69.   turtle.digDown()
  70.   turtle.back()
  71.   turtle.turnRight()
  72.   turtle.turnRight()
  73.   goForwards()
  74.   turtle.digUp()
  75.   turtle.digDown()
  76.   turtle.back()
  77.   turtle.turnLeft()
  78. end
  79.  
  80. -- Main function
  81. print("+-------------------------------+")
  82. print("+-----    Tunneler 2  ---------+")
  83. print("+-------------------------------+")
  84.  
  85. tc = ts
  86.  
  87. turtle.up()
  88. for pos = 1,tLength,1 do
  89.   digSection()
  90.   if math.fmod(pos,7) == 0 then
  91.     torchPlace()
  92.   end
  93. end
  94. turtle.down()
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement