Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Mining script
- local mode = ""
- local size = 0
- local cycles = 0
- local currentCycle = 0
- local continue
- function main()
- continue = false
- writeMenu()
- if mode == "e" then
- if continue == false then
- checkEngineeringInventory()
- end
- print("")
- print("Engineering turtle starting")
- for currentCycle = 1, cycles, 1 do
- if continue == true then
- continue = false
- engineering2()
- else
- engineering1()
- end
- saveSettings()
- print("Finished cycle "..currentCycle.."/"..cycles)
- end
- elseif mode == "m" then
- if continue == false then
- checkMiningInventory()
- end
- print("")
- print("Mining turtle starting")
- for currentCycle = 1, cycles, 1 do
- if continue == true then
- continue = false
- mining2()
- else
- mining1()
- end
- saveSettings()
- print("Finished cycle "..currentCycle.."/"..cycles)
- end
- end
- end
- function writeMenu()
- local f = 0;
- local input = "";
- term.clear()
- term.setCursorPos(1, 1)
- print("Turtle miner v0.1")
- print("-----------------")
- f = checkFuel()
- if f == false then
- print("Please feed me a bit of fuel!")
- return
- else
- print(f.." fuel remaining!")
- end
- if peripheral.getType("right") ~= "chunkLoader" then
- print("No chunkloading module found!")
- end
- print("")
- if peripheral.getType("bottom") == "turtle" or peripheral.getType("front") == "tesseract" then
- print("Continue?")
- print("1. Yes")
- print("2. No")
- input = io.read()
- continue = true
- end
- if input == "1" then
- loadSettings()
- print("Mode: "..mode)
- print("Size: "..size)
- print("Cycles: "..cycles)
- print("Current cycle: "..currentCycle)
- return
- end
- print("Please select turtle function:")
- print("1. Engineering turtle")
- print("2. Mining turtle")
- input = io.read()
- if input == "1" then
- mode = "e"
- elseif input == "2" then
- mode = "m"
- else
- print("Invalid input!")
- sleep(2)
- writeMenu()
- end
- term.clear()
- term.setCursorPos(1, 1)
- -- Ask for the size of the mining line
- print("How many miners do you want to deploy?")
- input = io.read()
- if tonumber(input) < 1 then
- print("Have to use more than 0 miners!")
- sleep(2)
- writeMenu()
- elseif tonumber(input) > 63 then
- print("Cannot use more than 63 miners!")
- sleep(2)
- writeMenu()
- else
- size = tonumber(input)
- end
- -- Ask for the number of cycles to make
- print("How many cycles do yo want to make?")
- input = io.read()
- if tonumber(input) < 1 then
- print("You have to make at least 1 cycle!")
- sleep(2)
- writeMenu()
- else
- cycles = tonumber(input)
- end
- saveSettings()
- end
- function engineering1()
- -- Wait for the ender chest to fuel up the turtle
- turtle.turnRight()
- waitFor("front", "ender_chest")
- if turtle.getFuelLevel() < 1000 then
- print("Refueling turtle")
- turtle.select(16)
- suck()
- turtle.refuel()
- end
- turtle.turnLeft()
- -- Move to the end of the line without placing tesseracts
- forward(size, false)
- -- Wait for the 1st pipe to be laid
- turtle.turnRight()
- waitFor("front", "conveyor_belt")
- sleep(2)
- turtle.attack()
- sleep(1)
- turtle.attack()
- sleep(1)
- turtle.turnRight();
- -- Place all the redstone energy conduits
- turtle.select(2)
- for i = 1, size, 1 do
- placeDown()
- forward(1, false)
- end
- -- Place a last redstone energy conduit
- placeDown()
- -- Place down the energy tesseract
- forward(1, false)
- turtle.select(3)
- placeDown()
- -- Go back and wrench the energy conduit
- turnAround()
- forward(1, false)
- turtle.attackDown()
- -- Move to the first minig well to monitor the status
- turtle.turnRight()
- forward(1, false)
- turtle.turnRight()
- -- Place the item tesseract in front of the turtle
- turtle.select(1)
- place(false)
- -- Wait for the mining wells to start up
- while turtle.getItemCount(1) == 0 do
- sleep(1)
- end
- engineering2()
- end
- function engineering2()
- print("Waiting for wells to finish")
- waitForMiningWellsToFinish()
- -- Mining well finished, get the item tesseract
- turtle.select(1)
- turtle.dig()
- forward(1,false)
- turtle.turnRight()
- -- pick up the energy tesseract
- turtle.select(3)
- turtle.forward(1, false)
- turtle.turnRight()
- turtle.digDown()
- -- Pickup the energy conduits
- turtle.select(2)
- forward(1, false)
- turtle.digDown()
- forward(1, false)
- for i = 1, size, 1 do
- turtle.digDown()
- forward(1, false)
- end
- turnAround()
- for i = 1, size, 1 do
- forward(1, false)
- end
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- function mining1()
- print("Waiting for engineering turtle on the left")
- waitFor("left", "turtle")
- -- Fuel up the turtle first
- up(1, true)
- turtle.select(4)
- placeDown()
- if turtle.getFuelLevel() < 10000 then
- print("refuelling!")
- turtle.select(4)
- suckDown()
- turtle.refuel()
- end
- sleep(1)
- turtle.select(3)
- turtle.digDown()
- -- Move out the way for the item tesseract
- forward(1, true)
- down(1, false)
- -- Lay down the mining wells first
- turtle.select(1)
- for i = 1, size, 1 do
- placeDown()
- forward(1, true)
- end
- turnAround()
- up(1, true)
- forward(1, true)
- -- Go back laying the transport pipes
- for i = 1, size, 1 do
- if i == 1 then
- turtle.select(3)
- else
- turtle.select(2)
- end
- placeDown()
- forward(1, true)
- end
- turnAround()
- mining2()
- end
- function mining2()
- waitFor("bottom", "turtle")
- waitForToLeave("bottom", "turtle")
- down(1, false)
- for i = 1, size, 1 do
- forward(1, true)
- if i == size then
- turtle.select(3)
- else
- turtle.select(2)
- end
- turtle.dig()
- turtle.select(1)
- turtle.digDown()
- end
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- for i = 1, size, 1 do
- forward(1, false)
- end
- turnAround()
- end
- function checkEngineeringInventory()
- term.clear()
- term.setCursorPos(1, 1)
- if turtle.getItemCount(1) == 1 then
- print("Slot 1 contains an ITEM tesseract")
- else
- print("Place an ITEM tesseract in slot 1")
- io.read()
- checkEngineeringInventory()
- end
- if turtle.getItemCount(2) == size + 1 then
- print("Slot 2 contains enough energy conduits")
- else
- print("Place "..(size + 1).." energy conduits in slot 2")
- io.read()
- checkEngineeringInventory()
- end
- if turtle.getItemCount(3) == 1 then
- print("Slot 1 contains an ENERGY tesseract")
- else
- print("Place an ENERGY tesseract in slot 1")
- io.read()
- checkEngineeringInventory()
- end
- for i = 4,16,1 do
- if turtle.getItemCount(i) > 0 then
- print("Slot "..i.." must be empty!")
- io.read()
- checkEngineeringInventory()
- end
- end
- end
- function checkMiningInventory()
- term.clear()
- term.setCursorPos(1, 1)
- if turtle.getItemCount(1) == size then
- print("Slot 1 contains enough mining wells")
- else
- print("Place "..(size).." mining wells in slot 1")
- io.read()
- checkMiningInventory()
- end
- if turtle.getItemCount(2) == size - 1 then
- print("Slot 2 contains enough golden pipes")
- else
- print("Place "..(size - 1).." golden pipes slot 2")
- io.read()
- checkMiningInventory()
- end
- if turtle.getItemCount(3) == 1 then
- print("Slot 3 contains a iron pipe")
- else
- print("Place 1 iron pipe slot 3")
- io.read()
- checkMiningInventory()
- end
- if turtle.getItemCount(4) == 1 then
- print("Slot 4 contains ender chest with fuel")
- else
- print("Place 1 ender chest with fuel in slot 4")
- io.read()
- checkMiningInventory()
- end
- for i = 5,16,1 do
- if turtle.getItemCount(i) > 0 then
- print("Slot "..i.." must be empty!")
- io.read()
- checkMiningInventory()
- end
- end
- end
- function forward(places, destruct)
- for i = 1, places, 1 do
- if turtle.forward() == false then
- while turtle.detect() do
- if destruct == true then
- turtle.dig()
- end
- sleep(1)
- end
- turtle.forward()
- end
- end
- end
- function down(places, destruct)
- for i = 1, places, 1 do
- if turtle.down() == false then
- while turtle.detectDown() do
- if destruct == true then
- turtle.digDown()
- end
- sleep(1)
- end
- turtle.down()
- end
- end
- end
- function up(places, destruct)
- for i = 1, places, 1 do
- if turtle.up() == false then
- while turtle.detectUp() do
- if destruct == true then
- turtle.digUp()
- end
- sleep(1)
- end
- turtle.up()
- end
- end
- end
- function suck()
- while turtle.suck() == false do
- sleep(1)
- end
- end
- function suckUp()
- while turtle.suckUp() == false do
- sleep(1)
- end
- end
- function suckDown()
- while turtle.suckDown() == false do
- sleep(1)
- end
- end
- function place(destruct)
- if turtle.place() == false then
- while turtle.detect() do
- if destruct == true then
- turtle.dig()
- end
- sleep(1)
- end
- turtle.place()
- end
- end
- function placeDown(destruct)
- if turtle.placeDown() == false then
- while turtle.detectDown() do
- if destruct == true then
- turtle.digDown()
- end
- sleep(1)
- end
- turtle.placeDown()
- end
- end
- function placeUp(destruct)
- if turtle.placeUp() == false then
- while turtle.detectUp() do
- if destruct == true then
- turtle.digUp()
- end
- sleep(1)
- end
- turtle.placeUp()
- end
- end
- function back(places, destruct)
- turnAround()
- forward(places, destruct)
- turnAround()
- end
- function turnAround()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- Wait for an item to the side to appear
- function waitFor(side, name)
- while true do
- if peripheral.getType(side) == name then
- return;
- else
- sleep(1);
- end
- end
- end
- -- Wait for an item to the side to be gone
- function waitForToLeave(side, name)
- while true do
- if peripheral.getType(side) ~= name then
- return;
- else
- sleep(1);
- end
- end
- end
- -- Wait for the mining wells to finish
- function waitForMiningWellsToFinish()
- local timer = 0;
- while true do
- local c = 0;
- for i = 1, 16, 1 do
- if turtle.getItemCount(i) > 0 then
- c = c + turtle.getItemCount(i);
- turtle.select(i)
- turtle.drop()
- end
- end
- if c == 0 then
- timer = timer + 1
- else
- timer = 0
- end
- if timer > 4 then
- return
- end
- print(timer.." seconds no items found")
- sleep(1)
- end
- end
- function checkFuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel < 100 then
- return false
- else
- return fuelLevel
- end
- end
- function saveSettings()
- fs.makeDir("saves")
- local file = fs.open("saves/mine.sav","w")
- file.writeLine(mode)
- file.writeLine(size)
- file.writeLine(cycles)
- file.writeLine(currentCycle)
- file.close()
- end
- function loadSettings()
- fs.makeDir("saves")
- local file = fs.open("saves/mine.sav","r")
- mode = file.readLine()
- size = tonumber(file.readLine())
- cycles = tonumber(file.readLine())
- currentCycle = tonumber(file.readLine())
- file.close()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment