Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- quarry program
- ztarget = 2 -- 2 for flat bedrock, 6 for normal
- invlimit = 8
- --default safe values
- x = 4
- y = 3
- z = 15
- maxheight = 15
- zhome = 15
- lr = "left"
- ---------------------
- fuellimit = 2000
- d = 0
- itemcount = 0
- function up()
- u = false
- while u == false do
- dig("up")
- u = turtle.up()
- z = z + 1
- end
- end
- function forward()
- u = false
- while u == false do
- dig("forward")
- u = turtle.forward()
- end
- end
- function down()
- u = false
- while u == false do
- dig("down")
- u = turtle.down()
- z = z - 1
- end
- end
- function home()
- for zc = z,zhome-1 do
- up()
- end
- turtle.turnRight()
- turtle.turnRight()
- for i = 1,12 do
- itemcount = itemcount + turtle.getItemCount(i)
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(14)
- turtle.placeDown()
- turtle.slect(1)
- print("Quarry complete")
- print("Mined a total of "..itemcount.." items")
- print("don't fall down the hole!")
- return
- end
- function inventorycheck()
- invfull = false
- for invslot = invlimit,12 do
- turtle.select(invslot)
- if turtle.getItemCount(invslot) > 0 then
- invfull = true
- else
- end
- end
- if invfull == true then
- print("Inventory getting full, returning to unload")
- deposit()
- else
- end
- end
- function deposit()
- zreturn = z
- for zd = z,zhome-1 do
- up()
- end
- turtle.turnRight()
- turtle.turnRight()
- for drop = 1,12 do
- itemcount = itemcount + turtle.getItemCount(drop)
- turtle.select(drop)
- turtle.drop()
- end
- print("Current items gathered: "..itemcount)
- fuelcheck()
- hold()
- turtle.turnRight()
- turtle.turnRight()
- for zd = zreturn,zhome-1 do
- down()
- end
- end
- function fuelcheck()
- while turtle.getFuelLevel() < fuellimit do
- turtle.select(1)
- turtle.suckUp()
- turtle.refuel()
- end
- end
- function hold()
- redstonewait = true
- print("Checking Torch Signal")
- while redstonewait == true do
- sleep(2)
- if redstone.getInput("left") then
- redstonewait = true
- print("Waiting On Torch")
- sleep(15)
- elseif redstone.getInput("right") then
- redstonewait = true
- print("Waiting On Torch")
- sleep(15)
- else
- redstonewait = false
- end
- end
- end
- function layerTurn()
- throwTrash()
- if lastline == false then
- if lr == "left" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- forward()
- if lr == "left" then
- turtle.turnLeft()
- lr = "right"
- else
- turtle.turnRight()
- lr = "left"
- end
- else
- layerReturn()
- end
- end
- function layerReturn()
- if xstart == false then
- if lr == "left" then
- turtle.turnLeft()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.turnRight()
- end
- for i = 1,x-1 do
- forward()
- end
- else
- if lr == "left" then
- lr = "right"
- else
- lr = "left"
- end
- end
- if lr == "left" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- for i = 1,y-1 do
- forward()
- end
- if lr == "left" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function dig(dir)
- turtle.select(1)
- if dir == "forward" then
- turtle.dig()
- elseif dir == "up" then
- turtle.digUp()
- elseif dir == "down" then
- turtle.digDown()
- else
- end
- end
- function throwTrash()
- for stack = 1,12 do
- junk = false
- turtle.select(stack)
- for trash = 13,16 do
- if turtle.compareTo(trash) == true then
- junk = true
- else
- end
- end
- if junk == true then
- turtle.drop()
- else
- end
- end
- end
- function blockTestUp()
- mineup = true
- for i = 13,16 do
- turtle.select(i)
- if turtle.compareUp() == true then
- mineup = false
- else
- end
- end
- end
- function blockTestDown()
- minedown = true
- for i = 13,16 do
- turtle.select(i)
- if turtle.compareDown() == true then
- minedown = false
- else
- end
- end
- end
- function mine()
- blockTestUp()
- blockTestDown()
- if mineup == true then
- dig("up")
- else
- end
- if minedown == true then
- dig("down")
- else
- end
- end
- function clean()
- term.clear()
- term.setCursorPos(1,1)
- end
- function minelayer()
- xstart = true
- lastline = false
- mine()
- for yc = 1,y do
- for xc = 1,x-1 do
- forward()
- mine()
- end
- if xstart == true then
- xstart = false
- else
- xstart = true
- end
- if yc == y then
- lastline = true
- end
- layerTurn()
- mine()
- end
- end
- function maxcheck()
- if zcurrent >= maxheight then
- home()
- else
- end
- end
- function layermove()
- for zc = ztarget,zhome-3,3 do
- print("Mining layer: "..zc)
- zcurrent = zc
- minelayer()
- maxcheck()
- inventorycheck()
- for i = 1,3 do
- up()
- end
- end
- end
- function initiate()
- z = zhome
- for zi = ztarget,z-1 do
- down()
- end
- end
- -- Program
- clean()
- print("QUARRY PROGRAM")
- print("")
- print("Current Height: ")
- print("Lowest Height: ")
- print("Maximum Height: ")
- print("Length: ")
- print("Width: ")
- print("First turn: ")
- term.setCursorPos(17,3)
- zhome = tonumber(read())
- term.setCursorPos(17,4)
- ztarget = tonumber(read())
- term.setCursorPos(17,5)
- maxheight = tonumber(read())
- term.setCursorPos(17,6)
- x = tonumber(read())
- term.setCursorPos(17,7)
- y = tonumber(read())
- term.setCursorPos(17,8)
- lr = read()
- clean()
- print("Digging to bedrock")
- initiate()
- print("Mining first layer")
- layermove()
- print("Returning home")
- home()
- --read info
- --initiate
- --layermove
- --layermine
- --inventorycheck
- --deposit
- --fuelcheck
- --home
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement