Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Quick Tunnel v1.2.0 - qt")
- -- Quick Tunnel
- -- Application: qt
- -- Description: A turtle tunneler that tries to be quick
- -- Usage: qt <length> <height> <torchSpace> <wide>
- -- length: How deep you want your tunnel
- -- height: How high you want your tunnel
- -- torchSpace: How many spaces between torches
- -- wide: true= 3 blocks wide. false= 1 block wide.
- --
- -- Slots:
- -- 1: Cobble (or some kind of filler for the ground)
- -- 2: Torches
- -- 3: Bucket (to pick up lava and refuel with it)
- --
- -- TODO:
- -- Check for fallen/placed block before trying to move forward
- local tArgs = { ... }
- -- Defaults
- local torchSpaces = 11 -- Space between torches
- local tunnelLength = 50 -- Tunnel depth
- local tunnelHeight = 4 -- Tunnel height
- local tunnelWide = "true" -- Is the tunnel wide? (Not Implemented)
- -- Other Variables
- local currentDepth = 1
- local currentHeight = 1
- local spacesUntilTorch = torchSpaces
- if tArgs == 0 then
- print("Usage: qt <length> <height> <torchSpace> <wide>")
- end
- if tArgs[1] then
- tunnelLength = tonumber(tArgs[1])
- end
- if tArgs[2] then
- tunnelHeight = tonumber(tArgs[2])
- end
- if tArgs[3] then
- torchSpaces = tonumber(tArgs[3])
- end
- if tArgs[4] then
- if tArgs[4] == "true" or tArgs[4] == "t" or tArgs[4] == 0 then
- tunnelWide = "true"
- else
- tunnelWide = "false"
- end
- end
- function main()
- printSetup()
- for depth=1,tunnelLength do
- currentDepth = depth
- updateDepth()
- spacesUntilTorch = depth % torchSpaces
- updateTorch()
- for height=1,tunnelHeight do
- currentHeight = height
- updateHeight()
- turtle.select(1)
- digForward()
- -- Place a temporary torch
- if height == 1 then
- turtle.select(2)
- turtle.place()
- turtle.select(1)
- end
- -- Dig sides if wide setting is true
- if tunnelWide == "true" then
- digRight()
- digLeft()
- end
- if height < tunnelHeight then
- digUp()
- moveUp()
- end
- end
- -- Move back down to the bottom
- for height = tunnelHeight - 1, 1, -1 do
- currentHeight = height
- updateHeight()
- moveDown()
- end
- -- Place a block below if no ground
- if turtle.detectDown() == false then
- a, d = turtle.detectDown()
- if string.match(d.name, "lava") then
- print("Lava below, refueling")
- turtle.select(3)
- turtle.placeDown()
- turtle.refuel()
- turtle.select(1)
- end
- placeBridge()
- end
- -- Place a torch if we need one
- if needTorch() then
- placeTorch()
- end
- -- Pick up the torch we placed
- turtle.dig()
- -- Move forward to go again
- moveForward()
- end
- end
- -- Inventory
- function inventoryFull()
- if turtle.getItemSpace(16) < 1 then
- return true
- else
- return false
- end
- end
- -- Terminal Printing
- function clearScreen()
- term.clear()
- end
- function printAt(x, y, text)
- term.setCursorPos(x, y)
- term.write(text)
- term.setCursorPos(1,13)
- end
- function printSetup()
- clearScreen()
- printAt(1,1,"Starting Tunnel...")
- printAt(4,3,"Depth: "..math.floor(tunnelLength))
- printAt(4,4,"Height: "..math.floor(tunnelHeight))
- printAt(4,5,"Torches: "..math.floor(torchSpaces))
- printAt(4,6,"Wide: "..tunnelWide)
- printAt(1,8, "Current Fuel: "..getFuel())
- printAt(1,9, "Current Depth: "..getCurrentDepth())
- printAt(1,10,"Current Height: "..getCurrentHeight())
- printAt(1,11,"Next Torch In: "..getSpacesUntilTorch())
- end
- function updateFuel()
- printAt(17,8,""..getFuel().." ")
- end
- function updateDepth()
- printAt(17,9,""..getCurrentDepth().." ")
- end
- function updateHeight()
- printAt(17,10,""..getCurrentHeight().." ")
- end
- function updateTorch()
- printAt(17,11,""..getSpacesUntilTorch().." ")
- end
- function getCurrentDepth()
- return math.floor(currentDepth)
- end
- function getCurrentHeight()
- return math.floor(currentHeight)
- end
- function getSpacesUntilTorch()
- return math.floor(torchSpaces - spacesUntilTorch)
- end
- -- Torch
- function needTorch()
- return spacesUntilTorch == 0
- end
- function placeTorch()
- -- digUp()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(2)
- turtle.place()
- turtle.select(1)
- turtle.turnRight()
- turtle.turnRight()
- end
- -- Fuel
- function getFuel()
- return turtle.getFuelLevel()
- end
- -- Liquid
- function tryLiquidUp()
- turtle.select(3)
- turtle.placeUp()
- tryLiquid()
- end
- function tryLiquidDown()
- turtle.select(3)
- turtle.placeDown()
- tryLiquid()
- end
- function tryLiquidForward()
- turtle.select(3)
- turtle.place()
- tryLiquid()
- end
- function tryLiquid()
- turtle.select(3)
- if turtle.refuel() == false then
- turtle.place()
- end
- turtle.select(1)
- end
- function placeBridge()
- turtle.select(1)
- turtle.placeDown()
- placeRight()
- placeLeft()
- end
- function placeRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- end
- function placeLeft()
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- end
- -- Turtle Movement
- function forward()
- turtle.forward()
- updateFuel()
- tryLiquidForward()
- end
- function back()
- turtle.back()
- updateFuel()
- end
- function up()
- turtle.up()
- updateFuel()
- end
- function down()
- turtle.down()
- updateFuel()
- end
- function moveUp()
- up()
- tryLiquidUp()
- end
- function moveDown()
- down()
- tryLiquidDown()
- end
- function moveForward()
- forward()
- end
- function moveBack()
- back()
- end
- function moveRight()
- turtle.turnRight()
- forward()
- tryLiquidForward()
- turtle.turnLeft()
- end
- function moveLeft()
- turtle.turnLeft()
- forward()
- tryLiquidForward()
- turtle.turnRight()
- end
- -- Turtle Digging
- function digForward()
- while turtle.detect(true) do
- turtle.dig()
- tryLiquidForward()
- end
- end
- function digUp() -- Dig Up
- turtle.digUp()
- tryLiquidUp()
- end
- function digRight() -- Dig Right
- turtle.turnRight()
- digForward()
- turtle.turnLeft()
- end
- function digLeft() -- Dig Left
- turtle.turnLeft()
- digForward()
- turtle.turnRight()
- end
- main() -- Start main loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement