Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Surface Quarry v1.0
- --By: Fizzgig
- --Tested with: FTB Mod pack - Direwolf20 v3
- --Purpose: A turtle program designed to dig and collect blocks from the surface to a specified depth.
- -- Useful for collecting sand from the desert and keeping the terrain generally "untouched".
- -- No ugly quarry holes!
- --Usage: surface <Depth> <Length> <Width> [Optional <'left'(Default='right')> <Offset>]
- -- Recommended depths 1 or 2. Greater than 3 is not recommended.
- -- Fuel slots 1 and 2. Split stack or 2 stacks (Put fuel in each slot)
- -- Placement - Turtle ontop of a chest.
- --Arguments
- local args = {...} --depth length width [Optional <'left'> <Offset>]
- if #args < 3 then
- print("Usage: surface <Depth> <Length> <Width> [Optional <'left'(Default='right')> <Offset>]")
- return
- end
- if tonumber(args[1]) < 1 then args[1] = "1" end
- if tonumber(args[2]) < 2 then args[2] = "2" end
- if tonumber(args[3]) < 2 then args[3] = "2" end
- local depth = tonumber(args[1])
- local length = tonumber(args[2])
- local width = tonumber(args[3])
- local quarry = "right"
- if #args >= 4 then
- if args[4] == "left" or args[4] == "Left" or args[4] == "LEFT" then quarry = "left" end
- end
- local offset = 0
- if #args == 5 then
- if tonumber(args[5]) < 0 then args[5] = "0" end
- offset = tonumber(args[5])
- end
- --Declarations
- local xpos = -2
- local ypos = 0
- local zpos = 1
- local dir = 1
- local safe = false
- --Functions
- function organize(num)
- --Sort the inv
- for i=num,16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then --same as below. that is intended
- for j=1,4 do
- if turtle.getItemCount(i) > 0 then --double condition is intended
- if turtle.getItemSpace(j)>turtle.getItemCount(i) then
- turtle.transferTo(j,turtle.getItemCount(i))
- else
- turtle.transferTo(j,turtle.getItemSpace(j))
- end
- end
- end
- end
- end
- local athome = (xpos == -2 and ypos == 0 and zpos == 1)
- --Drop to chest
- if athome then
- for i=num,16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- turtle.dropDown(turtle.getItemCount(i))
- end
- end
- end
- end
- function setdir(ndir)
- if ndir == 4 and dir == 1 then
- turtle.turnLeft()
- dir = 4
- end
- if ndir == 1 and dir == 4 then
- turtle.turnRight()
- dir = 1
- end
- if ndir == 4 and dir == 2 then
- turtle.turnLeft()
- turtle.turnLeft()
- dir = 4
- end
- if ndir == 2 and dir == 4 then
- turtle.turnRight()
- turtle.turnRight()
- dir= 2
- end
- if ndir > dir then
- while dir ~= ndir do
- turtle.turnRight()
- dir = dir+1
- end
- end
- if ndir < dir then
- while dir ~= ndir do
- turtle.turnLeft()
- dir = dir-1
- end
- end
- end
- function forward(num)
- if num == nil then num=1 end
- local modifyer
- if dir <= 2 then modifyer = 1 else modifyer = -1 end
- if dir == 1 or dir == 3 then
- while num > 0 do
- if turtle.forward() then
- xpos=xpos+modifyer
- num = num-1
- elseif safe then
- if turtle.getFuelLevel() == 0 then fuel(1,2)
- elseif turtle.up() then zpos=zpos+1
- elseif turtle.down() then zpos=zpos-1 end
- else
- turtle.dig()
- fuel(1,2)
- end
- end
- end
- if dir == 2 or dir == 4 then
- while num > 0 do
- if turtle.forward() then
- ypos=ypos+modifyer
- num = num-1
- elseif safe then
- if turtle.getFuelLevel() == 0 then fuel(1,2)
- elseif turtle.up() then zpos=zpos+1
- elseif turtle.down() then zpos=zpos-1 end
- else
- turtle.dig()
- fuel(1,2)
- end
- end
- end
- end
- function up(num)
- if num == nil then num = 1 end
- while num > 0 do
- if turtle.up() then
- zpos=zpos+1
- num = num-1
- else
- turtle.digUp()
- fuel(1,2)
- end
- end
- end
- function down(num)
- if num == nil then num = 1 end
- while num > 0 do
- if turtle.down() then
- zpos=zpos-1
- num = num-1
- else
- turtle.digDown()
- fuel(1,2)
- end
- end
- end
- function home()
- safe = true
- go(0,ypos)
- go(xpos,0)
- if zpos > 1 then down(zpos-1) end
- if zpos < 1 then up(1-zpos) end
- go(-2,0)
- setdir(1)
- safe = false
- end
- function start()
- go(0,ypos)
- end
- function go(x,y)
- if y ~= ypos then
- if y < ypos then
- setdir(4)
- forward(ypos-y)
- end
- if y > ypos then
- setdir(2)
- forward(y-ypos)
- end
- end
- if x ~= xpos then
- if x < xpos then
- setdir(3)
- forward(xpos-x)
- end
- if x > xpos then
- setdir(1)
- forward(x-xpos)
- end
- end
- end
- function fuel(num1,num2)
- if num1 == nil then num1 = 1 end
- if num2 == nil then num2 = num1 end
- if turtle.getFuelLevel() == 0 then
- while turtle.getFuelLevel() == 0 do
- if turtle.getItemCount(num1)-1 > 0 then
- turtle.select(num1)
- turtle.refuel(1)
- elseif turtle.getItemCount(num2)-1 > 0 then
- turtle.select(num2)
- turtle.refuel(1)
- end
- if turtle.getFuelLevel() == 0 then
- term.clear()
- term.setCursorPos(1,1)
- if num1 ~= num2 then print("Waiting for fuel - Slot "..num1.." or "..num2.."...")
- else print("Waiting for fuel - Slot "..num1.."...") end
- end
- sleep(0.05)
- end
- term.clear()
- term.setCursorPos(1,1)
- end
- end
- --Main
- start()
- if quarry == "left" then go(xpos,ypos-(offset+1)) else go(xpos,ypos+offset) end
- setdir(1)
- for i=1,width-offset do
- for j=1,length do
- while turtle.detectDown() == false do down() end
- if depth > 1 then down(depth-1) end
- turtle.digDown()
- while turtle.detect() do up() end
- if j ~= length then forward() end
- end
- if i ~= width-offset then
- while turtle.detect() do up() end
- if xpos==0 then
- xstore=xpos
- ystore= ypos
- zstore=zpos
- home()
- organize(3)
- start()
- safe = true
- go(xstore,ypos)
- go(xpos,ystore)
- if zstore > zpos then up(zstore-zpos) end
- if zstore < zpos then down(zpos-zstore) end
- safe = false
- end
- if quarry == "left" then setdir(4) else setdir(2) end
- forward()
- if xpos==0 then setdir(1) else setdir(3) end
- end
- end
- home()
- organize(3)
Advertisement
Add Comment
Please, Sign In to add comment