Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local skip = ...
- local sDistance = 2
- if type(tonumber(skip)) == "number" then
- sDistance = tonumber(skip)
- end
- local dist = 0
- local maxDist = 0
- local dug = 0
- local function checkInv()
- local o = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- o = o + 1
- end
- end
- if o >= 15 then return true end
- return false
- end
- local function dropEverything()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- local function revert()
- turtle.up = turtle.native.up
- turtle.down = turtle.native.down
- turtle.dig = turtle.native.dig
- turtle.digDown = turtle.native.digDown
- end
- local function changeTurtleStuff()
- function turtle.down()
- local ok, err = turtle.native.down()
- if ok then
- dist = dist + 1
- if dist > maxDist then
- maxDist = dist
- end
- end
- return ok, err
- end
- function turtle.up()
- local ok, err = turtle.native.up()
- if ok then
- dist = dist - 1
- end
- return ok, err
- end
- function turtle.dig()
- local ok, err = turtle.native.dig()
- if ok then
- dug = dug + 1
- end
- return ok, err
- end
- function turtle.digDown()
- local ok, err = turtle.native.digDown()
- if ok then
- dug = dug + 1
- end
- return ok, err
- end
- end
- local function checkFuel()
- local fuel = turtle.getFuelLevel()
- print("We normally need to dig about 50-100 blocks down.")
- print("That means we normally need about 100-200 fuel.")
- print("We have " .. tostring(fuel) .. " / 200 fuel.")
- if fuel >= 100 and fuel <= 200 then
- print("We may be able to make it, but we may not.")
- print("Wait 10 seconds to start, or terminate now to stop.")
- os.sleep(10)
- end
- if fuel < 100 then
- error("We do not have enough fuel.")
- end
- end
- local function returnToSurface(t)
- print("Made it to " .. tostring(maxDist) .. ", returning.")
- while dist > 0 do
- turtle.up()
- end
- if t then
- local cFlag = false
- for i = 1, 4 do
- local a = peripheral.getType("front")
- if a then
- if a:find("chest") then
- cFlag = true
- break
- end
- end
- turtle.turnRight()
- end
- if cFlag then
- dropEverything()
- else
- error("No chest, inventory too full.")
- end
- checkFuel()
- end
- end
- local function go(distt)
- -- move down two blocks to be just under the top block
- checkFuel()
- local function hopDown(dy)
- for i = 1, dy do
- turtle.digDown()
- turtle.down()
- end
- end
- hopDown(distt)
- -- dig circle then go down
- local fails = 0
- repeat
- if fails == 0 then
- for i = 1, 3 do
- turtle.dig()
- turtle.turnRight()
- end
- turtle.dig()
- turtle.digDown()
- if checkInv() then
- returnToSurface(true)
- checkFuel()
- hopDown(maxDist - 1)
- end
- end
- local f = turtle.down()
- if not f then
- turtle.attackDown()
- turtle.digDown()
- fails = fails + 1
- else
- fails = 0
- end
- until fails > 10
- returnToSurface()
- print("Job complete")
- print("Went " .. tostring(maxDist) .. " blocks down.")
- print("That means " .. tostring(maxDist * 2) .. " fuel was used.")
- print("Dug " .. tostring(dug) .. " blocks total.")
- end
- changeTurtleStuff()
- if skip == "unknown" then
- sDistance = 0
- while turtle.down() do end
- end
- go(sDistance)
- revert()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement