Advertisement
swemoney

Quick Tunnel v1.2.0 - qt

Jan 15th, 2015
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.24 KB | None | 0 0
  1. print("Quick Tunnel v1.2.0 - qt")
  2. -- Quick Tunnel
  3. -- Application: qt
  4. -- Description: A turtle tunneler that tries to be quick
  5. -- Usage: qt <length> <height> <torchSpace> <wide>
  6. --   length: How deep you want your tunnel
  7. --   height: How high you want your tunnel
  8. --   torchSpace: How many spaces between torches
  9. --   wide: true= 3 blocks wide. false= 1 block wide.
  10. --  
  11. -- Slots:
  12. --   1: Cobble (or some kind of filler for the ground)
  13. --   2: Torches
  14. --   3: Bucket (to pick up lava and refuel with it)
  15. --
  16. -- TODO:
  17. --   Check for fallen/placed block before trying to move forward
  18.  
  19. local tArgs = { ... }
  20.  
  21. -- Defaults
  22. local torchSpaces  = 11     -- Space between torches
  23. local tunnelLength = 50     -- Tunnel depth
  24. local tunnelHeight = 4      -- Tunnel height
  25. local tunnelWide   = "true" -- Is the tunnel wide? (Not Implemented)
  26.  
  27. -- Other Variables
  28. local currentDepth     = 1
  29. local currentHeight    = 1
  30. local spacesUntilTorch = torchSpaces
  31.  
  32. if tArgs == 0 then
  33.   print("Usage: qt <length> <height> <torchSpace> <wide>")
  34. end
  35.  
  36. if tArgs[1] then
  37.   tunnelLength = tonumber(tArgs[1])
  38. end
  39.  
  40. if tArgs[2] then
  41.   tunnelHeight = tonumber(tArgs[2])
  42. end
  43.  
  44. if tArgs[3] then
  45.   torchSpaces = tonumber(tArgs[3])
  46. end
  47.  
  48. if tArgs[4] then
  49.   if tArgs[4] == "true" or tArgs[4] == "t" or tArgs[4] == 0 then
  50.     tunnelWide = "true"
  51.   else
  52.     tunnelWide = "false"
  53.   end
  54. end
  55.  
  56. function main()
  57.   printSetup()
  58.   for depth=1,tunnelLength do
  59.     currentDepth = depth
  60.     updateDepth()
  61.     spacesUntilTorch = depth % torchSpaces
  62.     updateTorch()
  63.    
  64.     for height=1,tunnelHeight do
  65.       currentHeight = height
  66.       updateHeight()
  67.       turtle.select(1)
  68.       digForward()
  69.      
  70.       -- Place a temporary torch
  71.       if height == 1 then
  72.         turtle.select(2)
  73.         turtle.place()
  74.         turtle.select(1)
  75.       end
  76.      
  77.       -- Dig sides if wide setting is true
  78.       if tunnelWide == "true" then
  79.         digRight()
  80.         digLeft()
  81.       end
  82.      
  83.       if height < tunnelHeight then
  84.         digUp()
  85.         moveUp()
  86.       end
  87.     end
  88.    
  89.     -- Move back down to the bottom
  90.     for height = tunnelHeight - 1, 1, -1 do
  91.       currentHeight = height
  92.       updateHeight()
  93.       moveDown()
  94.     end
  95.    
  96.     -- Place a block below if no ground
  97.     if turtle.detectDown() == false then
  98.       a, d = turtle.detectDown()
  99.       if string.match(d.name, "lava") then
  100.          print("Lava below, refueling")
  101.          turtle.select(3)
  102.          turtle.placeDown()
  103.          turtle.refuel()
  104.          turtle.select(1)
  105.       end
  106.       placeBridge()
  107.     end
  108.    
  109.     -- Place a torch if we need one
  110.     if needTorch() then
  111.       placeTorch()
  112.     end
  113.    
  114.     -- Pick up the torch we placed
  115.     turtle.dig()
  116.    
  117.     -- Move forward to go again
  118.     moveForward()
  119.   end
  120. end
  121.  
  122. -- Inventory
  123. function inventoryFull()
  124.   if turtle.getItemSpace(16) < 1 then
  125.     return true
  126.   else
  127.     return false
  128.   end
  129. end
  130.  
  131. -- Terminal Printing
  132. function clearScreen()
  133.   term.clear()
  134. end
  135.  
  136. function printAt(x, y, text)
  137.   term.setCursorPos(x, y)
  138.   term.write(text)
  139.   term.setCursorPos(1,13)
  140. end
  141.  
  142. function printSetup()
  143.   clearScreen()
  144.   printAt(1,1,"Starting Tunnel...")
  145.   printAt(4,3,"Depth:   "..math.floor(tunnelLength))
  146.   printAt(4,4,"Height:  "..math.floor(tunnelHeight))
  147.   printAt(4,5,"Torches: "..math.floor(torchSpaces))
  148.   printAt(4,6,"Wide:    "..tunnelWide)
  149.   printAt(1,8, "Current Fuel:   "..getFuel())
  150.   printAt(1,9, "Current Depth:  "..getCurrentDepth())
  151.   printAt(1,10,"Current Height: "..getCurrentHeight())
  152.   printAt(1,11,"Next Torch In:  "..getSpacesUntilTorch())
  153. end
  154.  
  155. function updateFuel()
  156.   printAt(17,8,""..getFuel().."      ")
  157. end
  158.  
  159. function updateDepth()
  160.   printAt(17,9,""..getCurrentDepth().."     ")
  161. end
  162.  
  163. function updateHeight()
  164.   printAt(17,10,""..getCurrentHeight().."     ")
  165. end
  166.  
  167. function updateTorch()
  168.   printAt(17,11,""..getSpacesUntilTorch().."     ")
  169. end
  170.  
  171. function getCurrentDepth()
  172.   return math.floor(currentDepth)
  173. end
  174.  
  175. function getCurrentHeight()
  176.   return math.floor(currentHeight)
  177. end
  178.  
  179. function getSpacesUntilTorch()
  180.   return math.floor(torchSpaces - spacesUntilTorch)
  181. end
  182.  
  183. -- Torch
  184. function needTorch()
  185.   return spacesUntilTorch == 0
  186. end
  187.  
  188. function placeTorch()
  189. --  digUp()
  190.   turtle.turnRight()
  191.   turtle.turnRight()
  192.   turtle.select(2)
  193.   turtle.place()
  194.   turtle.select(1)
  195.   turtle.turnRight()
  196.   turtle.turnRight()
  197. end
  198.  
  199. -- Fuel
  200. function getFuel()
  201.   return turtle.getFuelLevel()
  202. end
  203.  
  204. -- Liquid
  205. function tryLiquidUp()
  206.   turtle.select(3)
  207.   turtle.placeUp()
  208.   tryLiquid()
  209. end
  210.  
  211. function tryLiquidDown()
  212.   turtle.select(3)
  213.   turtle.placeDown()
  214.   tryLiquid()
  215. end
  216.  
  217. function tryLiquidForward()
  218.   turtle.select(3)
  219.   turtle.place()
  220.   tryLiquid()
  221. end
  222.  
  223. function tryLiquid()
  224.   turtle.select(3)
  225.   if turtle.refuel() == false then
  226.     turtle.place()
  227.   end
  228.   turtle.select(1)
  229. end
  230.  
  231. function placeBridge()
  232.   turtle.select(1)
  233.   turtle.placeDown()
  234.   placeRight()
  235.   placeLeft()
  236. end
  237.  
  238. function placeRight()
  239.   turtle.turnRight()
  240.   turtle.place()
  241.   turtle.turnLeft()
  242. end
  243.  
  244. function placeLeft()
  245.   turtle.turnLeft()
  246.   turtle.place()
  247.   turtle.turnRight()
  248. end
  249.  
  250. -- Turtle Movement
  251. function forward()
  252.   turtle.forward()
  253.   updateFuel()
  254.   tryLiquidForward()
  255. end
  256.  
  257. function back()
  258.   turtle.back()
  259.   updateFuel()
  260. end
  261.  
  262. function up()
  263.   turtle.up()
  264.   updateFuel()
  265. end
  266.  
  267. function down()
  268.   turtle.down()
  269.   updateFuel()
  270. end
  271.  
  272. function moveUp()
  273.   up()
  274.   tryLiquidUp()
  275. end
  276.  
  277. function moveDown()
  278.   down()
  279.   tryLiquidDown()
  280. end
  281.  
  282. function moveForward()
  283.   forward()
  284. end
  285.  
  286. function moveBack()
  287.   back()
  288. end
  289.  
  290. function moveRight()
  291.   turtle.turnRight()
  292.   forward()
  293.   tryLiquidForward()
  294.   turtle.turnLeft()
  295. end
  296.  
  297. function moveLeft()
  298.   turtle.turnLeft()
  299.   forward()
  300.   tryLiquidForward()
  301.   turtle.turnRight()
  302. end
  303.  
  304. -- Turtle Digging
  305. function digForward()
  306.   while turtle.detect(true) do
  307.     turtle.dig()
  308.     tryLiquidForward()
  309.   end
  310. end
  311.  
  312. function digUp() -- Dig Up
  313.   turtle.digUp()
  314.   tryLiquidUp()
  315. end
  316.  
  317. function digRight() -- Dig Right
  318.   turtle.turnRight()
  319.   digForward()
  320.   turtle.turnLeft()
  321. end
  322.  
  323. function digLeft() -- Dig Left
  324.   turtle.turnLeft()
  325.   digForward()
  326.   turtle.turnRight()
  327. end
  328.  
  329. main() -- Start main loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement