Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Tunneler Beta]]--
- --[[by Burton]]--
- --Fuel Slot is 16
- --Torch slot is 15
- --To do
- --Variable height and width
- --Optional walls
- --Block off water/lava
- --Set default variables
- local distance = 0
- local torches = -1
- local TD = nil
- local length = nil
- --User set variables
- term.clear()
- term.setCursorPos(4,7)
- print("**Welcome to Tunneler by Burton**")
- term.setCursorPos(12,13)
- print("*Tunneler Beta*")
- os.sleep(2)
- term.clear()
- term.setCursorPos(3,2)
- print("Place empty chest behind turtle")
- term.setCursorPos(3,4)
- print("Place Chest with fuel to left of turtle")
- term.setCursorPos(3,6)
- print("Place Chest with Torches to right of turtle")
- term.setCursorPos(3,8)
- print("Place fuel in slot 16")
- term.setCursorPos(3,10)
- print("Place torches in slot 15")
- os.sleep(5)
- term.clear()
- term.setCursorPos(1,1)
- while not length do
- print("Tunnel length?")
- length = tonumber(read())
- if not length then
- print("Please enter a Integer 1,2,3...")
- end
- end
- while not TD do
- print("Blocks between torches?")
- TD = tonumber(read())
- if not TD then
- print("Please enter a Integer 1,2,3...")
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- local torchNum = turtle.getItemCount(15)
- print("Ok starting tunnel...")
- term.setCursorPos(1,3)
- print(length .. " blocks long torches every " .. (TD)+1 .. " blocks")
- term.setCursorPos(1,5)
- print("Hold Ctrl + T at any time to cancel")
- os.sleep(1)
- term.setCursorPos(1,7)
- turtle.select(1)
- --Custom dig function
- function d()
- while turtle.detect(true) do
- turtle.dig()
- end
- end
- --Custom digUp function
- function du()
- while turtle.detectUp(true) do
- turtle.digUp()
- end
- end
- --Custom forward function
- function mf()
- while not turtle.forward() do
- if not turtle.dig() then
- turtle.attack()
- end
- end
- end
- --Custom up function
- function mu()
- while not turtle.up() do
- if not turtle.digUp() then
- turtle.attackUp()
- end
- end
- end
- --Custom down function
- function md()
- while not turtle.down() do
- if not turtle.digDown() then
- turtle.attackDown()
- end
- end
- end
- --Return function
- function back()
- if distance ~= nil then
- distance = tonumber(distance)
- while turtle.getFuelLevel() < distance do
- refuel()
- end
- for i = 1, distance do
- mf()
- end
- end
- end
- --Empty function
- function empty()
- if turtle.getItemCount(14) ~= 0 then
- mu()
- mu()
- turtle.turnRight()
- turtle.turnRight()
- back()
- md()
- md()
- for i = 1,14 do
- turtle.select(i)
- if turtle.detect(true) then
- turtle.drop()
- end
- end
- mu()
- mu()
- turtle.turnRight()
- turtle.turnRight()
- back()
- md()
- md()
- turtle.select(1)
- end
- end
- --Refuel function
- function refuel()
- while tonumber(turtle.getFuelLevel()) < tonumber(length) do
- for i = 1,14 do
- turtle.select(i)
- if turtle.compareTo(16) then
- turtle.transferTo(16)
- turtle.select(1)
- end
- end
- turtle.select(16)
- if turtle.refuel(0) then
- print("Fuel level low ...Refuelling.")
- turtle.refuel(1)
- turtle.select(1)
- else
- mu()
- mu()
- turtle.turnRight()
- turtle.turnRight()
- back()
- md()
- md()
- turtle.turnRight()
- turtle.select(16)
- turtle.suck(64)
- if turtle.getItemCount(16) == 0 then
- local i = 0
- print("FUEL LEVEL LOW")
- print("Place fuel in slot 16 and press ENTER")
- while i == 0 do
- local sEvent, keystroke = os.pullEvent("key")
- if sEvent == "key" then
- if keystroke == 28 then
- refuel()
- i = 1
- end
- end
- end
- end
- turtle.select(1)
- turtle.turnRight()
- mu()
- mu()
- back()
- md()
- md()
- end
- end
- end
- --Torch placing function
- function placeTorch()
- if torchNum > 0 then
- if tonumber(TD) == tonumber(torches) then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(15)
- turtle.place()
- torchNum = torchNum - 1
- turtle.select(1)
- turtle.turnLeft()
- turtle.turnLeft()
- torches = -1
- print("Fuel level is " .. turtle.getFuelLevel())
- end
- else
- mu()
- mu()
- turtle.turnRight()
- turtle.turnRight()
- back()
- md()
- md()
- turtle.turnLeft()
- turtle.select(15)
- turtle.suck(64)
- if turtle.getItemCount(15) == 0 then
- local i = 0
- print("No Torches")
- print("Place Torches in slot 15 and press ENTER")
- while i == 0 do
- local sEvent, keystroke = os.pullEvent("key")
- if sEvent == "key" then
- if keystroke == 28 then
- i = 1
- end
- end
- end
- end
- turtle.select(1)
- turtle.turnLeft()
- mu()
- mu()
- back()
- d()
- md()
- end
- end
- --Main Loop
- while tonumber(distance) < tonumber(length) do
- placeTorch()
- refuel()
- empty()
- d()
- mf()
- torches = torches + 1
- distance = distance + 1
- print("Tunneled " .. distance .. " blocks")
- du()
- turtle.turnLeft()
- d()
- mu()
- du()
- d()
- du()
- mu()
- d()
- turtle.turnRight()
- turtle.turnRight()
- d()
- md()
- d()
- md()
- d()
- turtle.turnLeft()
- turtle.turnLeft()
- d()
- turtle.turnRight()
- end
- --Empty inventory when done
- mu()
- mu()
- turtle.turnRight()
- turtle.turnRight()
- back()
- md()
- md()
- for i = 1,14 do
- turtle.select(i)
- if turtle.detect(true) then
- turtle.drop()
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- term.clear()
- term.setCursorPos(1,1)
- print("Tunnel Complete " .. distance .. " blocks long")
Add Comment
Please, Sign In to add comment