Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- local collected = 0
- local turn = 0
- function collect()
- collected = collected+1
- if math.fmod(collected, 25) == 0 then
- print("Mined "..collected.." items.")
- end
- end
- function dig()
- if turtle.detectDown() then
- turtle.digDown()
- collect()
- sleep(0.5)
- else
- return false
- end
- return true
- end
- function select()
- for i = 1,4 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- return true
- else
- return false
- end
- end
- end
- function place()
- if not turtle.detectDown() then
- if select() then
- turtle.placeDown()
- else
- print("No more blocks")
- local function blocks()
- for s = 1, 4 do
- if turtle.getItemCount(s) > 0 then
- return true
- else
- return false
- end
- end
- end
- while true do
- if blocks() then
- turtle.placeDown()
- break
- end
- end
- end
- end
- end
- function forward()
- refuel()
- if turtle.detect() then
- turn()
- else
- turtle.forward()
- sleep(0.5)
- end
- end
- function turn()
- if turtle.detect() then
- if turn == 0 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turn = 1
- elseif turn == 1 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- turn = 0
- end
- end
- end
- function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- sleep(1)
- end
- print( "Resuming Tunnel." )
- end
- end
- local function init()
- while true do
- sleep(0)
- place()
- forward()
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement