Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local dim = tonumber(tArgs[1])
- local flip = false
- an.resetGPS()
- function readIn(q)
- term.clear()
- term.setCursorPos(1,1)
- print(q)
- return read()
- end
- local mx = readIn("X?")
- local my = readIn("Y?")
- local mz = readIn("Z?")
- term.clear()
- term.setCursorPos(1,1)
- print(mx.."/"..my.."/"..mz.."?")
- local inp = read()
- if inp ~= "y" then error("") end
- an.setBaseData("fuelSlot",16)
- an.setBaseData("navOrigin",vector.new(mx,my,mz))
- local wps = {}
- function regWP(name,x,y,z,dir)
- wps[name] = {vector.new(x,y,z),dir}
- end
- function moveWP(name,moveOrder)
- an.goToWorld(wps[name][1],moveOrder)
- if wps[name][2] ~= nil then
- an.turnDir(wps[name][2])
- end
- end
- regWP("home",mx,my,mz,1)
- regWP("drop_chest",-288,57,39)
- regWP("drop_chest_queue",-288,57,55)
- function goHome()
- moveWP("home",{"y","x","z"})
- end
- function savePos()
- local vec = an.localToWorld(an.getLoc())
- --print("saving: "..vec.y)
- --print("local: "..an.getLoc().y)
- --read()
- regWP("saved",vec.x,vec.y,vec.z,an.getDir())
- end
- function goBack()
- moveWP("saved",{"y","x","z"})
- --print("moved back") read()
- end
- local quarryBounds = {vector.new(0,0,0),vector.new(dim-1,0,dim-1)}
- function blockAllowed(blockPos)
- local localPos = an.worldToLocal(blockPos)
- if localPos.x < quarryBounds[1].x or localPos.z < quarryBounds[1].z or localPos.x > quarryBounds[2].x or localPos.z > quarryBounds[2].z then return false end
- if localPos.y >= 0 then return false end
- return true
- end
- function restockFuel()
- if turtle.getItemCount(16) < 64 then
- for i=1,15,1 do
- an.select(16)
- if turtle.compareTo(i) then
- an.select(i)
- turtle.transferTo(16)
- break
- end
- end
- end
- an.select(1)
- end
- function dropOff()
- savePos()
- goHome()
- moveWP("drop_chest_queue",{"y","z","x"})
- moveWP("drop_chest",{"x","z","y"})
- restockFuel()
- for i=1,15,1 do
- an.select(i)
- turtle.dropDown()
- end
- an.select(1)
- goHome()
- goBack()
- end
- function homeDist()
- return math.abs(an.getLoc().y)+10
- end
- function getRowOff()
- local r = an.getLoc().x
- return r
- end
- function getRowEnd(row)
- row = row or getRowOff()
- if (row % 2 == 0 ) then return (flip and 0 or dim-1)
- else return (flip and dim-1 or 0) end
- end
- function translatePos(tPos)
- --print("translate: " .. type(tPos))
- return an.localToWorld(an.getLoc())+tPos
- end
- function tryDig()
- if blockAllowed(translatePos(an.getVecMod())) then
- local r = turtle.dig()
- return true,(r or not turtle.detect() )
- end
- return false
- end
- function tryDigDown()
- if blockAllowed(translatePos(vector.new(0,-1,0))) then
- local r = turtle.digDown()
- return true,(r or not turtle.detectDown())
- end
- return false
- end
- function tryRefuel()
- if turtle.getItemCount(16) > 0 then
- an.select(16)
- local r = turtle.refuel(1)
- if r then return true end
- end
- for i=1,15,1 do
- if turtle.getItemCount(i) > 0 then
- an.select(i)
- local r = turtle.refuel(1)
- if r then return true end
- end
- end
- an.select(1)
- return false
- end
- function waitFuel()
- while true do
- print("Need fuel")
- read()
- local r = tryRefuel()
- if r then break end
- end
- end
- function doRow()
- local row = getRowOff()
- print("clearing row: "..row)
- local rowDir = (flip and 3 or 1)
- if row % 2 == 1 then rowDir = (flip and 1 or 3) end
- an.turnDir(rowDir)
- print("check "..an.getLoc().z .. " == "..getRowEnd())
- while an.getLoc().z ~= getRowEnd() do
- --print("MOVE")
- local _,r1 = tryDig()
- local _,r2 = tryDigDown()
- if turtle.getItemCount(15) > 0 then print("dropOff") dropOff() end
- if homeDist() >= turtle.getFuelLevel() then
- print("going home => out of fuel")
- local rf = tryRefuel()
- if not rf then savePos() goHome() waitFuel() goBack() end
- end
- if r1 == false or r2 == false then print("bedrock") return false end
- an.forward()
- end
- print("row ended")
- tryDigDown()
- return true
- end
- function exitKey()
- while true do
- local ev,p1 = os.pullEvent("char")
- if ev == "char" and p1 == "x" then break end
- end
- end
- function quarry()
- while true do
- local r = doRow()
- if not r then break end
- --local wPos = an.localToWorld(an.getLoc())
- local xMod = 1
- if flip then xMod = -1 end
- if getRowOff() == (flip and 0 or dim-1) then
- local _,rb = tryDigDown()
- if rb == false then break end
- an.down()
- _rb = tryDigDown()
- if rb == false then break end
- an.down()
- flip = not flip
- else
- --print("turning")
- an.turnDir(an.getDirFromVec(vector.new(xMod,0,0)))
- --print("digging")
- tryDig()
- an.goTo(vector.new(xMod,0,0),{"x"})
- end
- end
- end
- print("starting") read()
- parallel.waitForAny(exitKey,quarry)
- goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement