local compass = { ["forw"]=0,["right"]=1,["back"]=2,["left"]=3}local mode = { ["stop"]=0,["work"]=1,["go"]=2,["supl"]=3,["fuel"]=4}local dx,dy,dz,da=0,0,0,compass[paste][/paste]forwlocal processing=falselocal modeNow=mode[paste][/paste]stoplocal l,w,h=0,0,0local x,y,z=0,0,0local suplTurtlelocal function tsave() local name=shell[paste][/paste]getRunningProgram() local file = fs[paste][/paste]open(name[paste][/paste][paste][/paste]"[paste][/paste]st","w") file[paste][/paste]writeLine(dx) file[paste][/paste]writeLine(dy) file[paste][/paste]writeLine(dz) file[paste][/paste]writeLine(da) file[paste][/paste]close()endlocal function qsave() local name=shell[paste][/paste]getRunningProgram() local file = fs[paste][/paste]open(name[paste][/paste][paste][/paste]"[paste][/paste]sq","w") file[paste][/paste]writeLine(modeNow) file[paste][/paste]writeLine(l) file[paste][/paste]writeLine(w) file[paste][/paste]writeLine(h) file[paste][/paste]writeLine(x) file[paste][/paste]writeLine(y) file[paste][/paste]writeLine(z) file[paste][/paste]writeLine(processing) file[paste][/paste]close()endlocal function refuel(needed) local lvl = turtle[paste][/paste]getFuelLevel() if lvl == "unlimited" then return false end if lvl <= (needed) then turtle[paste][/paste]select(1) local amount = turtle[paste][/paste]getItemCount(1) if amount >=2 then turtle[paste][/paste]refuel(amount-1) lvl = turtle[paste][/paste]getFuelLevel() end if lvl <= (needed) then modeNow = mode[paste][/paste]fuel qsave() return true end end return falseendlocal function fullSlots() if ((turtle[paste][/paste]getItemCount(15) ~= 0) and (turtle[paste][/paste]getItemCount(16) ~= 0)) then modeNow = mode[paste][/paste]supl qsave() return true end return falseendlocal function turtleturn(ang) if not(da==ang) then local dd=ang-da if dd==1 or dd==-3 then da=ang tsave() turtle[paste][/paste]turnRight() elseif dd==-1 or dd==3 then da=ang tsave() turtle[paste][/paste]turnLeft() else da=da+1 if da==4 then da=compass[paste][/paste]forw end tsave() turtle[paste][/paste]turnRight() da=ang tsave() turtle[paste][/paste]turnRight() end end endlocal function turtlemove() while true do if turtle[paste][/paste]suck() then sleep(0[paste][/paste]1) elseif turtle[paste][/paste]detect() then if turtle[paste][/paste]dig() then if (modeNow == mode[paste][/paste]work and fullSlots()) then x=dx y=dy z=dz qsave() suplTurtle() return false end else processing=false qsave() return false end elseif turtle[paste][/paste]attack() then sleep(0[paste][/paste]5) else if modeNow == mode[paste][/paste]work then turtle[paste][/paste]digDown() if fullSlots() then x=dx y=dy z=dz qsave() suplTurtle() return false end end local tx,tz=dx,dz if da==compass[paste][/paste]forw then dx=dx+1 elseif da==compass[paste][/paste]right then dz=dz+1 elseif da==compass[paste][/paste]back then dx=dx-1 else dz=dz-1 end tsave() if turtle[paste][/paste]forward() then if (modeNow == mode[paste][/paste]work and refuel(dx+dy+dz+10)) then x=dx y=dy z=dz qsave() suplTurtle() end return true else dx=tx dz=tz tsave() sleep(3) end end endendlocal function turtledown() while true do if turtle[paste][/paste]suckDown() then sleep(0[paste][/paste]1) elseif turtle[paste][/paste]detectDown() then if turtle[paste][/paste]digDown() then if (modeNow == mode[paste][/paste]work and fullSlots()) then x=dx y=dy z=dz qsave() suplTurtle() return false end else processing=false qsave() return false end elseif turtle[paste][/paste]attackDown() then sleep(0[paste][/paste]5) else local ty=dy dy=dy+1 tsave() if turtle[paste][/paste]down() then if (modeNow == mode[paste][/paste]work and refuel(dx+dy+dz+10)) then x=dx y=dy z=dz qsave() suplTurtle() end return true else dy=ty tsave() sleep(3) end end endendlocal function turtleup() while true do if turtle[paste][/paste]digUp() then sleep(0[paste][/paste]5) elseif turtle[paste][/paste]attackUp() then sleep(0[paste][/paste]5) else local ty=dy dy=dy-1 tsave() if turtle[paste][/paste]up() then return true else dy=ty tsave() sleep(3) end end endendlocal function turtlegoto(tx,ty,tz) while dy>ty do turtleup() end while dx>tx do turtleturn(compass[paste][/paste]back) turtlemove() end while dx<tx do turtleturn(compass[paste][/paste]forw) turtlemove() end while dz>tz do turtleturn(compass[paste][/paste]left) turtlemove() end while dz<tz do turtleturn(compass[paste][/paste]right) turtlemove() end while dy<ty do turtledown() endendlocal function load() local name=shell[paste][/paste]getRunningProgram() if fs[paste][/paste]exists(name[paste][/paste][paste][/paste]"[paste][/paste]st") then local file = fs[paste][/paste]open(name[paste][/paste][paste][/paste]"[paste][/paste]st","r") dx = tonumber(file[paste][/paste]readLine()) dy = tonumber(file[paste][/paste]readLine()) dz = tonumber(file[paste][/paste]readLine()) da = tonumber(file[paste][/paste]readLine()) file[paste][/paste]close() local file = fs[paste][/paste]open(name[paste][/paste][paste][/paste]"[paste][/paste]sq","r") modeNow = tonumber(file[paste][/paste]readLine()) l = tonumber(file[paste][/paste]readLine()) w = tonumber(file[paste][/paste]readLine()) h = tonumber(file[paste][/paste]readLine()) x = tonumber(file[paste][/paste]readLine()) y = tonumber(file[paste][/paste]readLine()) z = tonumber(file[paste][/paste]readLine()) if file[paste][/paste]readLine() == "true" then processing = true else processing = false end file[paste][/paste]close() if modeNow == mode[paste][/paste]work then x,y,z = dx,dy,dz end return true else return false endendlocal function runQuarry() if fs[paste][/paste]exists("startup") then fs[paste][/paste]delete("startup") end local name = shell[paste][/paste]getRunningProgram() local file = fs[paste][/paste]open("startup","w") file[paste][/paste]write("shell[paste][/paste]run(\""[paste][/paste][paste][/paste]name[paste][/paste][paste][/paste]"\")") file[paste][/paste]close()endlocal function stopQuarry() if fs[paste][/paste]exists("startup") then fs[paste][/paste]delete("startup") end local name = shell[paste][/paste]getRunningProgram() if fs[paste][/paste]exists(name[paste][/paste][paste][/paste]"[paste][/paste]sq") then fs[paste][/paste]delete(name[paste][/paste][paste][/paste]"[paste][/paste]sq") end if fs[paste][/paste]exists(name[paste][/paste][paste][/paste]"[paste][/paste]st") then fs[paste][/paste]delete(name[paste][/paste][paste][/paste]"[paste][/paste]st") endendfunction suplTurtle() if dy>h then turtlegoto(0,h,0) end turtlegoto(0,0,0) turtleturn(compass[paste][/paste]back) if not turtle[paste][/paste]detect() then print("no detect chest") while not turtle[paste][/paste]detect() do sleep(1) end end for i=2,16 do turtle[paste][/paste]select(i) if (turtle[paste][/paste]getItemCount(i)>0 and not(turtle[paste][/paste]drop())) then print("chest is full") while not(turtle[paste][/paste]drop()) do sleep(1) end end end refuel((l+1)*(h+1)+y+10) if modeNow == mode[paste][/paste]fuel then print("need fuel") while refuel((l+1)*(h+1)+y+10) do sleep(1) end end turtle[paste][/paste]select(2) if processing then modeNow = mode[paste][/paste]go qsave() turtlegoto(0,h,0) turtlegoto(x,y,z) modeNow = mode[paste][/paste]work qsave() endendlocal function turtlemining() local n,m,c,i,j=0,0,0,1,1 while processing do if math[paste][/paste]fmod(dy-h,2)==0 then if math[paste][/paste]fmod(dy-h,4)==0 then n = w - dz c = 0 else n = dz + 1 c = 1 end j=1 while j<=n do if math[paste][/paste]fmod(dz+c,2)==0 then m = l - dx - 1 else m = dx end i=1 while i<=m do if math[paste][/paste]fmod(dz+c,2)==0 then turtleturn(compass[paste][/paste]forw) else turtleturn(compass[paste][/paste]back) end if turtlemove() then i=i+1 end if not(processing) then return end end if j<n then if math[paste][/paste]fmod(dy-h,4)==0 then turtleturn(compass[paste][/paste]right) else turtleturn(compass[paste][/paste]left) end if turtlemove() then j=j+1 end else j=j+1 end end if processing then turtledown() turtledown() end else turtleup() print("error coord") end endendvvod = { [paste][/paste][paste][/paste][paste][/paste] }if not (load()) then if #vvod == 1 then l = tonumber( vvod[1] ) w = l h = 0 y = h elseif #vvod == 2 then l = tonumber( vvod[1] ) w = l h = tonumber( vvod[2] ) y = h elseif #vvod == 3 then l = tonumber( vvod[1] ) w = tonumber( vvod[3] ) h = tonumber( vvod[2] ) y = h else print("error of input") local name = shell[paste][/paste]getRunningProgram() print(name[paste][/paste][paste][/paste]" <lenght> [<height>] [<width>]") return end if (l<1 or w<1 or h<0) then print("error of input") print("Quarry size must be positive") return end processing=true modeNow=mode[paste][/paste]go qsave() tsave() runQuarry() refuel((l+1)*(w+1)+y+10)endif modeNow == mode[paste][/paste]go then if dy<h then turtlegoto(0,h,0) end turtlegoto(x,y,z) modeNow = mode[paste][/paste]work qsave()endif (modeNow == mode[paste][/paste]supl or modeNow == mode[paste][/paste]fuel) then suplTurtle()endif modeNow == mode[paste][/paste]work then turtlemining() suplTurtle() turtleturn(compass[paste][/paste]forw) print("mining complete[paste][/paste][paste][/paste][paste][/paste]")endstopQuarry()