Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variable Declarations
- local mainShaftDim = "3x2"
- local sideShaftDim = "2x1"
- local shaftFreq = "3"
- local totalCost = 0
- local input = ""
- local length = 0
- local currentPos = 1
- local chestDist = 0
- local doFuel = false
- --Function Declarations
- function oreDetect()
- --[[ This function is a WIP system for the turtle to detect ores when it
- is mining and dig out the entire vein. It will do so by comparing items
- around it to specific slots in its inventory which will contain common
- blocks such as smooth stone, gravel, dirt, etc.
- If one of these ores is identified, then the turtle will dig out the block
- and then move into the space that the block occupied and 'sense' the blocks
- around it again to try and find the continuation of the vein.
- Once the turtle has finished identifying the vein, it will return to it's
- initial position. This last task may either be completed by recording
- movement as the turtle moves or by using a GPS wireless system and a
- basic 'goto' function for the initial coordinates.
- ]]
- end
- function refuel()
- for i=1,15,1 do
- turtle.select(i)
- turtle.refuel(turtle.getItemCount(i))
- end
- turtle.select(1)
- end
- function mainShaft()
- turtle.select(1)
- for i=1,4,1 do
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.forward()
- if not turtle.detectDown() then
- turtle.placeDown()
- end
- while turtle.detectUp() do
- turtle.digUp()
- end
- turtle.turnRight()
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.forward()
- if not turtle.detectDown() then
- turtle.placeDown()
- end
- while turtle.detectUp() do
- turtle.digUp()
- end
- turtle.turnRight()
- turtle.turnRight()
- while turtle.detect() do
- turtle.dig()
- end
- turtle.forward()
- if not turtle.detectDown() then
- turtle.placeDown()
- end
- turtle.turnRight()
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(16)
- turtle.forward()
- turtle.placeUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.placeUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- end
- function sideShaft()
- turtle.select(1)
- for i=0,20,1 do
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.forward()
- if turtle.detectDown() == false then
- turtle.placeDown()
- end
- while turtle.detectUp() == true do
- turtle.digUp()
- end
- end
- turtle.select(16)
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(1)
- for i=0,20,1 do
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.forward()
- if turtle.detectDown() == false then
- turtle.placeDown()
- end
- while turtle.detectUp() == true do
- turtle.digUp()
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(16)
- turtle.place()
- turtle.up()
- for i=1,23,1 do
- while turtle.detect() do
- turtle.dig()
- end
- turtle.forward()
- end
- turtle.down()
- end
- function deposit()
- for i=1, (chestDist), 1 do
- turtle.forward()
- end
- for i=1, 15, 1 do
- turtle.select(i)
- turtle.drop()
- end
- refuel()
- if turtle.getItemCount(16) < 6 then
- stopMining()
- end
- if turtle.getFuelLevel() < (108 + 2 * chestDist) then
- stopMining()
- end
- turtle.turnRight()
- turtle.turnRight()
- for i=1, (chestDist), 1 do
- turtle.forward()
- end
- end
- function stopMining()
- if turtle.getFuelLevel() < (108 + 2 * chestDist) then
- print("I am low on fuel.")
- local remainFuel = 0
- for i=currentPos, length, 1 do
- remainFuel = (108 + 2 * (4 * i + 1))
- end
- print("I need "..remainFuel.." to finish.")
- print("That's "..(remainFuel/80).." coal or "..(remainFuel/1000).." lava.")
- print("Type (cont) to refuel & continue mining.")
- doFuel = true
- end
- if turtle.getItemCount(16) < 6 then
- print("I am low on torches.")
- print("Place more in slot 16...")
- while turtle.getItemCount(16) < 6 do
- sleep(1)
- end
- print("Type (cont) to continue mining.")
- doFuel = false
- end
- local cont = false
- while cont == false do
- --[[if rs.getInput("right") == true then --Flickers RS torch on right of chest
- rs.setOutput("right", false)
- else
- rs.setOutput("right", true)
- end]]
- local input = io.read()
- if input == "cont" then
- if doFuel then
- refuel()
- end
- turtle.turnRight()
- turtle.turnRight()
- for i=1, chestDist, 1 do
- turtle.forward()
- end
- currentPos = currentPos + 1
- run()
- else
- print("Incorrect input.")
- end
- end
- end
- function run()
- while currentPos < length do
- chestDist = (currentPos * 4 + 4)
- mainShaft()
- turtle.turnLeft()
- sideShaft()
- sideShaft()
- turtle.turnLeft()
- deposit()
- currentPos = currentPos + 1
- end
- end
- function idle()
- print("Mining Complete")
- print("Type (end) to terminate program")
- local input = "null"
- rs.setOutput("right", true)
- while input ~= "end" do
- input = io.read()
- end
- rs.setOutput("right", false)
- end
- --Execution
- print("----------------------------------")
- print("Branch Mine Turtle Activated")
- print("----------------------------------")
- sleep(2)
- print("Beginning Mine w. Following Specs:")
- print("Main Shaft: "..mainShaftDim)
- print("Side Shafts: "..sideShaftDim)
- print("Branch Frequency: "..shaftFreq)
- print("----------------------------------")
- print("Number of Shafts:")
- length = tonumber(read())
- currentPos = 0
- print("----------------------------------")
- for x = length, 0, -1 do
- totalCost = totalCost + (108 + 2 * (4 * x + 1))
- end
- print("Current Fuel: "..turtle.getFuelLevel())
- print("Fuel cost: "..totalCost)
- print("Coal cost: "..(totalCost/80))
- print("Lava cost: "..(totalCost/1000))
- sleep(2)
- print("----------------------------------")
- print("Would you like to refuel now (y/n)?")
- input = io.read()
- if input == "y" then
- refuel()
- print("Refueled.")
- else
- print("Did not refuel.")
- end
- print("Turtle now has "..turtle.getFuelLevel().." fuel.")
- print("----------------------------------")
- print("Now beginning mining!")
- run()
- turtle.turnRight()
- turtle.turnRight()
- for i=1, chestDist, 1 do
- turtle.forward()
- end
- idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement