Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Blacklist = {}
- Whitelist = {}
- function Black(...)
- local stuff = {...}
- for i,v in pairs(stuff) do Blacklist[tostring(v):lower()]=true end
- end
- function White(...)
- local stuff = {...}
- for i,v in pairs(stuff) do Whitelist[tostring(v):lower()]=true end
- end
- Black("Copper","Dirt","Stone","Gravel","Flint","Sand","Rack","Apatite")
- White("Red")
- Position = {x=0,y=0,z=0}
- Forward = {x=1,y=0,z=0}
- function OnBlack(tx)
- for i,v in pairs(Blacklist) do
- if tx:find(i) then
- return true
- end
- end
- end
- function OnWhite(tx)
- for i,v in pairs(Whitelist) do
- if tx:find(i) then
- return true
- end
- end
- end
- function Dig(dir)
- if dir == "forward" then
- if turtle.detect() then repeat turtle.dig() until not turtle.detect() end
- end
- if dir == "up" then
- if turtle.detectUp() then repeat turtle.digUp() until not turtle.detectUp() end
- end
- if dir == "down" then
- if turtle.detectDown() then repeat turtle.digDown() until not turtle.detectDown() end
- end
- end
- function ShiftOffsetForward()
- Position.x=Position.x+Forward.x
- Position.y=Position.y+Forward.y
- Position.z=Position.z+Forward.z
- end
- function shift(direction)
- local x,z = Forward.x,Forward.z
- if direction=="right" then
- Forward.x = (z == 1 and -1) or (z == -1 and 1) or (x ~= 0 and 0)
- Forward.z = (x == 1 and 1) or (x == -1 and -1) or (z ~= 0 and 0)
- end
- if direction=="left" then
- Forward.z = (x == 1 and -1) or (x == -1 and 1) or (z ~= 0 and 0)
- Forward.x = (z == 1 and 1) or (z == -1 and -1) or (x ~= 0 and 0)
- end
- end
- function GetDirection()
- if Forward.x==1 then
- return "forward"
- elseif Forward.x==-1 then
- return "backwards"
- elseif Forward.z==1 then
- return "right"
- elseif Forward.z==-1 then
- return "left"
- end
- end
- function IsFull()
- local f = true
- for i = 1,16 do
- if turtle.getItemCount(i) == 0 then
- f=false
- end
- end
- return f
- end
- function SetDirection(dir)
- local DIR = GetDirection()
- if DIR~=dir:lower() then
- local l,r = 0,0
- if DIR == "left" then
- l,r = ((dir=="backwards"and 1)or 0),((dir=="forward"and 1)or(dir=="right"and 2)or 0)
- elseif DIR == "right" then
- l,r = ((dir=="forward"and 1)or 0),((dir=="backwards"and 1)or(dir=="left"and 2)or 0)
- elseif DIR == "backwards" then
- l,r = ((dir=="right"and 1)or 0),((dir=="left"and 1)or(dir=="forward"and 2)or 0)
- elseif DIR == "forward" then
- l,r = ((dir=="left"and 1)or 0),((dir=="right"and 1)or(dir=="backwards"and 2)or 0)
- end
- for i = 1,r do shift("right") turtle.turnRight() end
- for i = 1,l do shift("left") turtle.turnLeft() end
- end
- end
- function Move(direction)
- CheckFuel()
- local tcheck = false
- if direction =="up" then
- Dig("up")
- repeat local t,e = turtle.up() if t then tcheck=true else Display("Error: Movement obstructed","Error Details: "..tostring(e)) Dig("up") end until tcheck
- Position.y=Position.y+1
- elseif direction == "down" then
- Dig("down")
- repeat local t,e = turtle.down() if t then tcheck=true else Display("Error: Movement obstructed","Error Details: "..tostring(e)) Dig("down") end until tcheck
- Position.y=Position.y-1
- else
- SetDirection(direction)
- if GetDirection()==direction then
- Dig("forward")
- repeat local t,e = turtle.forward() if t then tcheck=true else Display("Error: Movement obstructed","Error Details: "..tostring(e)) Dig("forward") end until tcheck
- ShiftOffsetForward()
- end
- end
- end
- function GoTo(x,y,z)
- local x,y,z = x,y,z
- repeat
- if Position.x>x then
- Move("backwards")
- elseif Position.x<x then
- Move("forward")
- end
- until Position.x == x
- repeat
- if Position.z<z then
- Move("right")
- elseif Position.z>z then
- Move("left")
- end
- until Position.z == z
- repeat
- if Position.y<y then
- Move("up")
- elseif Position.y>y then
- Move("down")
- end
- until Position.y == y
- end
- function DepositAll()
- for i = 1,16 do
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i))
- end
- end
- function DepositExtras()
- local f = true
- for i = 1,16 do
- local name = turtle.getItemDetail(i).name:lower()
- if turtle.getItemCount(i)>0 and OnBlack(name) and not OnWhite(name) then
- f = false
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i))
- end
- end
- return f
- end
- function Display(...)
- local tab = {...}
- local n = 0
- term.clear()
- for i,v in pairs(tab) do
- n = n+1
- term.setCursorPos(1,n)
- print(v)
- end
- end
- function CheckFuel()
- if turtle.getFuelLevel()==0 then
- repeat
- sleep(1)
- Display("Place fuel in selected slot.")
- until
- turtle.getItemCount(turtle.getSelectedSlot())>0 and turtle.getItemDetail(turtle.getSelectedSlot()).name:find("coal")
- turtle.refuel(turtle.getItemCount(turtle.getSelectedSlot()))
- end
- end
- function Quarry(x,y,z)
- local StartPos = {x=Position.x,y=Position.y,z=Position.z}
- local TDirection = ""
- local TPos = {x=0,y=0,z=0}
- local ax,ay,az = x,y,z
- local Progress = 0
- for y = 1,y/3 do
- for i = 1,(y~=1 and 3 or 2) do
- Progress = Progress+1
- Move("down")
- end
- for x = 1,x/2 do
- for z = 1,z-1 do
- Progress = Progress+3
- Display("Creating Quarry","Progress: "..math.ceil((Progress/(ax*ay*az))*100).."%","Fuel: "..turtle.getFuelLevel().."/"..turtle.getFuelLimit())
- Dig("up")
- Dig("down")
- Move("right")
- if IsFull() and DepositExtras() then
- TPos = {x=Position.x,y=Position.y,z=Position.z}
- TDirection = GetDirection()
- GoTo(0,0,0)
- SetDirection("backwards")
- DepositAll()
- GoTo(TPos.x,TPos.y,TPos.z)
- SetDirection(TDirection)
- end
- end
- Dig("up")
- Dig("down")
- if Position.x~=ax-1 then
- Progress = Progress+1
- Move("forward")
- end
- for z = 1,z-1 do
- Progress = Progress+3
- Display("Creating Quarry","Progress: "..math.ceil((Progress/(ax*ay*az))*100).."%","Fuel: "..turtle.getFuelLevel().."/"..turtle.getFuelLimit())
- Dig("up")
- Dig("down")
- Move("left")
- if IsFull() and DepositExtras() then
- TPos = {x=Position.x,y=Position.y,z=Position.z}
- TDirection = GetDirection()
- GoTo(0,0,0)
- SetDirection("backwards")
- DepositAll()
- GoTo(TPos.x,TPos.y,TPos.z)
- SetDirection(TDirection)
- end
- end
- Dig("up")
- Dig("down")
- if Position.x~=ax-1 then
- Progress = Progress+1
- Move("forward")
- end
- end
- GoTo(StartPos.x,Position.y,StartPos.z)
- end
- GoTo(0,0,0)
- SetDirection("backwards")
- DepositAll()
- SetDirection("forward")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement