Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Begin runChest function
- local function runChest()
- if useChests == "Y" or useChests == "y" then
- max = 15
- chests = turtle.getItemCount(chestSlot)
- if chests == 0 then
- print("\nPlease input chests into slot ",max+1,"...")
- while chests == 0 do
- chests = turtle.getItemCount(chestSlot)
- sleep(1)
- end
- end
- continue = true
- elseif useChests == "N" or useChests == "n" then
- continue = true
- else
- continue = false
- print("\nInvalid")
- sleep(2)
- end
- end
- --End runChest function
- --Begin runTorch function
- local function runTorch()
- if useTorches == "Y" or useTorches == "y" then
- if useChests == "Y" or useChests == "y" then
- torchSlot = 15
- torches = turtle.getItemCount(torchSlot)
- max = 14
- else
- torchSlot = 16
- torches = turtle.getItemCount(torchSlot)
- max = 15
- end
- if torches == 0 then
- print("\nPlease input torches into slot ",max+1,"...")
- while torches == 0 do
- if useChests == "Y" or useChests == "y" then
- torches = turtle.getItemCount(15)
- else
- torches = turtle.getItemCount(16)
- end
- sleep(1)
- end
- end
- continue = true
- elseif useTorches == "N" or useTorches == "n" then
- continue = true
- else
- continue = false
- print("\nInvalid")
- sleep(2)
- end
- end
- --End runTorch function
- --Begin dropoff function
- local function dropOff()
- turtle.digDown()
- turtle.select(chestSlot)
- turtle.placeDown()
- for i = 1,max do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- --End dropoff function
- --Begin dig function
- local function dig()
- while turtle.detect() do
- turtle.dig()
- end
- end
- --End dig function
- --Begin up function
- function up(num)
- curUp = 1
- if num == nil then
- num = 1
- end
- while curUp <= num do
- if not turtle.up() then
- turtle.digUp()
- turtle.attackUp()
- else
- curUp = curUp+1
- end
- end
- end
- --End up function
- --Begin forward function
- function forward(num)
- curForw = 1
- if num == nil then
- num = 1
- end
- while curForw <= num do
- if not turtle.forward() then
- turtle.dig()
- turtle.attack()
- else
- curForw = curForw+1
- end
- end
- end
- --End forward function
- --Begin down function
- function down(num)
- curDown = 1
- if num == nil then
- num = 1
- end
- while curDown <= num do
- if not turtle.down() then
- turtle.digDown()
- turtle.attackDown()
- else
- curDown = curDown+1
- end
- end
- end
- --End down function
- --Begin the tryRefuel function
- local function tryRefuel()
- for i = 1,max do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if turtle.refuel(1) then
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- --End the tryRefuel function
- --Begin refuel function
- local function refuel()
- curFuel = turtle.getFuelLevel()
- if curFuel == "unlimited" or curFuel >= 10 then
- return
- else
- if not tryRefuel() then
- print("Please supply more fuel to coninue...")
- while not tryRefuel() do
- sleep(1)
- end
- end
- end
- end
- --End refuel function
- --Begin tunnel function
- local function tunnel(num)
- if useTorches == "Y" or useTorches == "y" then
- turtle.digDown()
- turtle.select(torchSlot)
- turtle.placeDown()
- turtle.select(1)
- end
- torch = 1
- for i = 1,num do
- print("Current tunnel length: ",curLength-1)
- refuel()
- turtle.turnLeft()
- dig()
- up()
- dig()
- turtle.turnRight()
- turtle.turnRight()
- dig()
- down()
- dig()
- turtle.turnLeft()
- refuel()
- if useChests == "Y" or useChests == "y" then
- if turtle.getItemCount(max) > 0 then
- dropOff()
- end
- end
- turtle.select(1)
- turtle.dig()
- forward()
- curLength = curLength+1
- if useTorches == "Y" or useTorches == "y" then
- if torch == 9 then
- turtle.digDown()
- turtle.select(torchSlot)
- turtle.placeDown()
- turtle.select(1)
- torch = 1
- else
- torch = torch+1
- end
- end
- end
- end
- --End tunnel function
- --Begin Main code
- rednet.open("right")
- --Declare Variables
- max = 16
- invalid = true
- torchSlot = 15
- chestSlot = 16
- curLength = 1
- useSettings = false
- torches = turtle.getItemCount(torchSlot)
- chests = turtle.getItemCount(chestSlot)
- term.clear()
- term.setCursorPos(1,1)
- print("Better Tunnel v1.0")
- sleep(2.5)
- --If a settings file exists, ask the user if they want to load it
- if fs.exists("btSettings") then
- repeat
- term.clear()
- term.setCursorPos(1,1)
- print("A settings file was found.")
- print("Would you like to load it?(Y/N): ")
- load = read()
- if load == "Y" or load == "y" then
- useSettings = true
- invalid = false
- elseif load == "N" or load == "n" then
- useSettings = false
- invalid = false
- else
- invalid = true
- print("\nInvalid")
- sleep(2)
- end
- until invalid == false
- else
- useSettings = false
- end
- --If they chose to load it, it will load the setting from the file
- if useSettings == true then
- h = fs.open("btSettings", "r")
- comment1 = h.readLine()
- comment2 = h.readLine()
- orders = h.readLine()
- useChests = h.readLine()
- useTorches = h.readLine()
- compID = h.readLine()
- h.close()
- max = 16
- runChest()
- runTorch()
- else--If the file didn't exist or the user chose not to load it, the program will ask the user for settings
- --Begin the orders loop
- repeat
- term.clear()
- term.setCursorPos(1,1)
- write("Will I be receiving orders via User or Rednet?(U/R): ")
- orders = read()
- vType = type(orders)
- if vType == "string" then
- if orders ~= "U" and orders ~= "u" and orders ~= "R" and orders ~= "r" then
- print("\nInvalid")
- sleep(2)
- invalid = true
- else
- invalid = false
- end
- else
- print("\nInvalid")
- sleep(2)
- invalid = true
- end
- until invalid == false
- --End the orders loop
- --If Rednet was chosen ask the user what ID to be listening for
- if orders == "R" or orders == "r" then
- print("\nTo receive using rednet, use rednet.send() with the message of how long the tunnel should be in blocks.")
- write("\nWhich computer ID should I accept messages from?: ")
- compID = tonumber(read())
- end
- --Begin the useChests loop
- repeat
- term.clear()
- term.setCursorPos(1,1)
- write("Should I use chests?(Y/N): ")
- useChests = read()
- vType = type(useChests)
- if vType == "string" then
- runChest()
- else
- continue = false
- print("\nInvalid")
- sleep(2)
- end
- until continue == true
- --End the useChests loop
- continue = false
- --Begin the useTorches loop
- repeat
- term.clear()
- term.setCursorPos(1,1)
- write("Should I use torches?(Y/N): ")
- useTorches = read()
- vType = type(useTorches)
- if vType == "string" then
- runTorch()
- else
- continue = false
- print("\nInvalid")
- sleep(2)
- end
- until continue == true
- --End the useTorches loop
- end
- --Run the tunnel function based on the orders chosen
- if orders == "R" or orders == "r" then
- term.clear()
- term.setCursorPos(1,1)
- print("You chose to receive orders via Rednet.")
- print("I will listen for orders from the computer with id: "..compID)
- id, msg = rednet.receive()
- if id == tonumber(compID) then
- length = msg
- print("Beginning tunnel with length: "..length)
- tunnel(length)
- end
- elseif orders == "U" or orders == "u" then
- repeat
- term.clear()
- term.setCursorPos(1,1)
- print("You chose to receive orders via User.")
- write("How long would you like the tunnel to be?(In blocks): ")
- num = tonumber(read())
- vType = type(num)
- if vType == "number" then
- length = num
- print("Beginning tunnel with length: "..length)
- invalid = false
- tunnel(length)
- else
- print("\nInvalid")
- sleep(2)
- invalid = true
- end
- until invalid == false
- end
- term.clear()
- term.setCursorPos(1,1)
- print("I'm done!")
- print("I completed a tunnel with length: "..length)
- if not useSettings then
- print("Would you like to save these settings for use in the next tunnel?(Y/N): ")
- save = read()
- if save == "Y" or save == "y" then
- h = fs.open("btSettings","w")
- h.writeLine("--Better Tunnel Settings")
- h.writeLine("--Deleting will reset settings")
- h.close()
- h = fs.open("btSettings","a")
- h.writeLine(orders)
- h.writeLine(useChests)
- h.writeLine(useTorches)
- h.writeLine(compID)
- h.close()
- print("Settings have been saved")
- sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment