Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Blacklist = {}
- function Black(...)
- local stuff = {...}
- for i,v in pairs(stuff) do Blacklist[tostring(v):lower()]=true end
- end
- Black("Copper","Dirt","Stone","Limestone","Gravel")
- 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 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()
- if direction =="up" then
- repeat if turtle.detectUp() then turtle.digUp() end until not turtle.detectUp()
- turtle.up()
- Position.y=Position.y+1
- elseif direction == "down" then
- repeat if turtle.detectDown() then turtle.digDown() end until not turtle.detectDown()
- turtle.down()
- Position.y=Position.y-1
- else
- SetDirection(direction)
- if GetDirection()==direction then
- repeat if turtle.detect() then turtle.dig() end until not turtle.detect()
- turtle.forward()
- 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
- if turtle.getItemCount(i)>0 and OnBlack(turtle.getItemDetail(i).name:lower()) then
- f = false
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i))
- end
- end
- return f
- end
- function Display(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()) 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
- if y ~= ay/3 then
- for i = 1,(y~=1 and 3 or 2) do
- Progress = Progress+1
- Move("down")
- end
- 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)).."%","Fuel: "..turtle.getFuelLevel().."/"..turtle.getFuelLimit()})
- turtle.digUp()
- turtle.digDown()
- 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
- turtle.digUp()
- turtle.digDown()
- 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)).."%","Fuel: "..turtle.getFuelLevel().."/"..turtle.getFuelLimit()})
- turtle.digUp()
- turtle.digDown()
- 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
- turtle.digUp()
- turtle.digDown()
- 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