Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --name MiningWellTurtle
- --version 1.3
- -- Turtle in the front with pickaxe and gate reader
- local version = "1.3"
- local size = 16
- local posX = 1
- local posY = 1
- local turnRightNext = true
- local turning = false
- local args = {...}
- local startTime = os.clock()
- if #args > 0 then
- size = tonumber(args[1])
- end
- if #args > 2 then
- posX = tonumber(args[2])
- posY = tonumber(args[3])
- end
- local function doScreen(str)
- term.clear()
- term.setCursorPos(1,1)
- write("Mining Well Turtle - v")
- print(version)
- print("------------------------------")
- print(string.format("Fuel: %d", turtle.getFuelLevel()))
- print(string.format("Pos: %d/%d, %d", posX, size, posY))
- print()
- print(str)
- end
- local function loopBack()
- local dirX = 1
- if posY % 2 == 0 then dirX = -1 end
- posX = posX + dirX
- if (posX > size) or (posX < 1) then
- if posY == size then
- doScreen(string.format("Completed in %d seconds", os.clock()-startTime))
- while true do
- os.sleep(120)
- end
- end
- if posY % 2 == 0 then turtle.turnLeft()
- else turtle.turnRight()
- end
- turning = true
- posX = posX - dirX
- posY = posY + 1
- elseif turning then
- if posY % 2 == 0 then turtle.turnRight()
- else turtle.turnLeft()
- end
- turning = false
- end
- end
- -- Special functions to handle gravel/sand
- local function forward()
- turtle.select(1)
- while not turtle.forward() do
- turtle.dig()
- end
- end
- local function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- os.sleep(0.5)
- end
- end
- -- Empty into Ender Chest
- local function empty()
- doScreen("Emptying turtle...")
- -- Place ender chest
- if turtle.detectUp() then
- digUp()
- end
- turtle.select(15)
- turtle.placeUp()
- for i=1,16 do
- if turtle.getItemCount(i) > 0 and i ~= 14 then
- turtle.select(i)
- turtle.dropUp()
- end
- end
- turtle.select(15)
- turtle.digUp()
- end
- local function replaceCell()
- doScreen("Replacing redstone cell...")
- turtle.select(1)
- -- Place ender chest
- if turtle.detectUp() then
- digUp()
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(14)
- turtle.placeUp()
- turtle.suck()
- turtle.dropUp()
- os.sleep(2)
- while not turtle.suckUp() do
- os.sleep(0.5)
- end
- turtle.drop()
- turtle.digUp()
- turtle.turnRight()
- turtle.turnRight()
- while not redstone.getInput("back") do
- os.sleep(0.5)
- end
- end
- -- Wrap the gate detector
- local gate = peripheral.wrap("right")
- doScreen("Place items as follows...")
- print("-------------------------")
- print("| Red EnderChest in 14")
- print("| White EnderChest in 15")
- print("| Mining Well in 16")
- while (turtle.getItemCount(14)==0) or (turtle.getItemCount(15)==0) or (turtle.getItemCount(16)==0) do
- os.sleep(0.1)
- end
- redstone.setOutput("back", true)
- while true do
- for i=1,size do
- turtle.digDown()
- turtle.select(16)
- turtle.placeDown()
- turtle.select(1)
- digUp()
- empty()
- doScreen("Waiting for cell turtle...")
- while not redstone.getInput("back") do
- os.sleep(0.1)
- end
- doScreen("Mining...")
- while not gate.get()["Work Done"] do
- if not redstone.getInput("back") then
- replaceCell()
- end
- os.sleep(0.1)
- end
- redstone.setOutput("back",false)
- doScreen("Moving...")
- turtle.select(16)
- turtle.digDown()
- turtle.select(1)
- loopBack()
- forward()
- redstone.setOutput("back",true)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment