Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Turtle tunnel miner for computer craft.
- Anti gravel mode can effectively counter up to 4 blocks
- of gravel on top of the tunnel on default settings
- (optimal perfomance/stability balance).
- *updated: 19.01.23
- ]]--
- --settings
- local torch_distance = 10
- local torches_slot = 1
- local delay = 0.7
- local function dig_step()
- repeat
- turtle.dig()
- until not turtle.detect()
- turtle.forward()
- turtle.digUp()
- sleep(delay)
- turtle.digDown()
- end
- local function get_args()
- term.clear()
- term.setCursorPos(1,1)
- if #args == 0 or tonumber(args[1]) == nil then
- print("Distance not set")
- print("Usage: " .. shell.getRunningProgram() .. " distance [r] [t] [d]")
- print("r - return to start".."\n".."t - disable torches placing".."\n".."d - disable digging".."s - immediate start")
- return false
- end
- for i = 2, #args do
- if args[i] == "r" or args[i] == "R" then
- return_mode = true
- print("Return mode activated")
- end
- if args[i] == "t" or args[i] == "T" then
- torches = false
- print("Torches placing disabled")
- end
- if args[i] == "d" or args[i] == "D" then
- digging = false
- print("Digging disabled")
- end
- if args[i] == "s" or args[i] == "S" then
- autoStart = true
- end
- end
- return true
- end
- local function check_torches_count()
- local need_torches = math.floor(args[1]/(torch_distance+1))
- print(need_torches.." torch(es) required")
- while (turtle.getItemCount(torches_slot) < need_torches) do
- term.setCursorPos(1,4)
- print(" ")
- sleep(0.5)
- term.setCursorPos(1,4)
- print("Not enought torches in "..tostring(torches_slot).." slot")
- sleep(0.5)
- end
- return need_torches
- end
- local function place_torch()
- turtle.select(torches_slot)
- while not turtle.down() do
- turtle.digDown()
- end
- if not turtle.detectDown() then
- if torches_slot > 1 then
- turtle.select(1)
- else
- turtle.select(2)
- end
- turtle.placeDown()
- end
- turtle.up()
- turtle.select(torches_slot)
- turtle.placeDown()
- end
- local function writeProgress(cDist, fDist, tDist)
- local left = math.ceil(cDist/fDist*100)
- term.setCursorPos(1, 1)
- term.clear()
- print("Done "..left.."%")
- if tDist then
- term.write("Next torch in "..tDist.." blocks")
- end
- end
- --main
- args = { ... }
- return_mode = false
- torches = true
- digging = true
- autoStart = false
- if not get_args(args) then return end
- local needTorches = 0
- if torches then
- light_level = torch_distance
- needTorches = check_torches_count()
- end
- local neededFuel = needTorches * 2 + args[1]
- if return_mode then neededFuel = neededFuel * 2 end
- print(" ")
- term.write("Fuel: "..turtle.getFuelLevel().." / "..neededFuel)
- if turtle.getFuelLevel() < neededFuel then
- print("\n\nNot enought fuel.\nProgram will be aborted")
- return nil
- else print(" ...OK")
- end
- if not autoStart then
- print("\nPress <Enter> to start".."\n".."Or hold <Ctrl + T> to abort")
- read()
- end
- for i = 1, args[1] do
- if digging then
- dig_step()
- else
- turtle.forward()
- end
- if torches then
- if light_level == 0 then
- place_torch()
- light_level = torch_distance
- else
- light_level = light_level - 1
- end
- end
- writeProgress(i, args[1], light_level)
- end
- if return_mode == true then
- turtle.up()
- for i = 1, args[1] do
- turtle.back()
- end
- turtle.down()
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement