Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------
- -- Efficient Quarry --
- -- Made By Vilsol --
- -- 1/20/2012 --
- ----------------------
- term.clear()
- term.setCursorPos(1, 1)
- tArgs = { ... }
- depth = 0
- left = false
- bonux = 0
- bonuz = 0
- DCZ = 0
- DCX = 0
- if(tArgs[1] == "update")then
- shell.run("rm", "ebQuarry")
- shell.run("pastebin", "get", "LpBaQVER", "ebQuarry")
- print "Update successfull!"
- error()
- end
- function savePos()
- file = fs.open("ebpos", "w")
- file.writeLine(heightx)
- file.writeLine(widthz)
- file.writeLine(depth)
- file.writeLine(x)
- file.writeLine(y)
- file.writeLine(z)
- file.writeLine(adddown)
- file.close()
- end
- function safeUp()
- checkFuel()
- if(not turtle.up())then
- sleep(1)
- if(turtle.attackUp())then
- for attack = 1, 50 do
- turtle.attackUp()
- if(turtle.up())then
- up = 1
- break
- end
- sleep(1)
- end
- if up then
- up = 0
- return true
- else
- savePos()
- error("Unknown problem!")
- end
- else
- if(turtle.digUp())then
- sleep(1)
- for graveler = 1, 8 do
- if(not turtle.digUp())then
- break
- end
- sleep(1)
- end
- if(turtle.up())then
- return true
- else
- savePos()
- error("Unknown problem!")
- end
- else
- savePos()
- error("Unknown problem!")
- end
- end
- else
- return true
- end
- end
- function safeDown()
- checkFuel()
- if(not turtle.down())then
- sleep(1)
- if(turtle.attackDown())then
- for attack = 1, 50 do
- turtle.attackDown()
- if(turtle.down())then
- down = 1
- break
- end
- sleep(1)
- end
- if down then
- down = 0
- return true
- else
- savePos()
- error("Unknown problem!")
- end
- else
- if(turtle.digDown())then
- sleep(1)
- for graveler = 1, 8 do
- if(not turtle.digDown())then
- break
- end
- sleep(1)
- end
- if(turtle.down())then
- return true
- else
- savePos()
- error("Unknown problem!")
- end
- else
- savePos()
- error("Unknown problem!")
- end
- end
- else
- return true
- end
- end
- function bringHome(widthz, heightx)
- if(widthz == nil)then widthz = 0 end
- if(heightx == nil)then heightx = 0 end
- if left then
- turtle.turnRight()
- if(widthz > 1)then
- for back = 1, widthz-1 do
- safeForward(12345, 12345)
- end
- end
- turtle.turnLeft()
- if(x-heightx > -3)then
- for back = 1, x-heightx+1 do
- safeForward(12345, 12345)
- end
- end
- else
- turtle.turnLeft()
- if(widthz > 1)then
- for back = 1, widthz-1 do
- safeForward(12345, 12345)
- end
- end
- turtle.turnLeft()
- if(heightx > 1)then
- for back = 1, heightx-1 do
- safeForward(12345, 12345)
- end
- end
- end
- if(adddown)then
- for backup = 1, depth+adddown do
- safeUp()
- end
- else
- for backup = 1, depth do
- safeUp()
- end
- end
- for slots = 1, 12 do
- turtle.select(slots)
- turtle.drop()
- end
- turtle.select(1)
- if(adddown)then
- for backdown = 1, depth+adddown do
- safeDown()
- end
- else
- for backdown = 1, depth do
- safeDown()
- end
- end
- if left then
- turtle.turnLeft()
- turtle.turnLeft()
- if(x-heightx+1 > -3)then
- for back = 1, x-heightx+1 do
- turtle.forward()
- end
- end
- turtle.turnRight()
- if(widthz > 1)then
- for back = 1, widthz-1 do
- turtle.forward()
- end
- end
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.turnLeft()
- if(heightx > 1)then
- for back = 1, heightx-1 do
- turtle.forward()
- end
- end
- turtle.turnRight()
- if(widthz > 1)then
- for back = 1, widthz-1 do
- turtle.forward()
- end
- end
- turtle.turnLeft()
- end
- end
- function isFull(widthz, heightx)
- slot = turtle.getItemCount(12)
- if(slot >= 1)then
- bringHome(widthz, heightx)
- end
- end
- function checkSlots()
- dirt = turtle.getItemCount(14)
- stone = turtle.getItemCount(15)
- fuel = turtle.getItemCount(16)
- if(dirt == 1 and stone == 1 and fuel >= 1)then
- return true
- else
- return false
- end
- end
- function checkFuel()
- if(turtle.getFuelLevel() < 100)then
- turtle.select(16)
- if (turtle.refuel())then
- print "Refueled successfully"
- return true
- else
- savePos()
- error("Out of fuel!")
- end
- turtle.select(1)
- else
- return true
- end
- end
- function safeDig(widthz, heightx)
- isFull(widthz, heightx)
- if(not turtle.dig())then
- if(not turtle.detect())then
- return true
- else
- if(turtle.attack())then
- for attack = 1, 50 do
- turtle.attack()
- if(turtle.dig())then
- dig = 1
- break
- end
- sleep(0.1)
- end
- if dig then
- dig = 0
- return true
- else
- savePos()
- error("Unknown problem!")
- end
- else
- savePos()
- error("Unknown problem!")
- end
- end
- else
- return true
- end
- end
- function safeForward(widthz, heightx)
- checkFuel()
- if(widthz ~= 12345 and heightx ~= 12345)then
- isFull(widthz, heightx)
- end
- if(not turtle.forward())then
- sleep(1)
- if(turtle.attack())then
- for attack = 1, 50 do
- turtle.attack()
- if(turtle.forward())then
- forward = 1
- break
- end
- sleep(1)
- end
- if forward then
- forward = 0
- return true
- else
- savePos()
- error("Unknown problem!")
- end
- else
- if(turtle.dig())then
- sleep(1)
- for graveler = 1, 8 do
- if(not turtle.dig())then
- break
- end
- sleep(1)
- end
- if(turtle.forward())then
- return true
- else
- savePos()
- error("Unknown problem!")
- end
- else
- if(not turtle.forward())then
- savePos()
- error("Unknown problem!")
- end
- end
- end
- else
- return true
- end
- end
- function compareOre()
- digup = 0
- digdown = 0
- turtle.select(14)
- if not turtle.compareUp() then
- digup = 1
- end
- if not turtle.compareDown() then
- digdown = 1
- end
- turtle.select(15)
- if not turtle.compareUp() then
- digup = digup + 1
- end
- if not turtle.compareDown() then
- digdown = digdown + 1
- end
- turtle.select(1)
- if(digup == 2)then turtle.digUp() end
- if(digdown == 2)then turtle.digDown() end
- end
- function turn()
- if left then
- left = false
- turtle.turnLeft()
- safeDig(widthz, heightx)
- safeForward(12345, 12345)
- turtle.turnLeft()
- else
- left = true
- turtle.turnRight()
- safeDig(widthz, heightx)
- safeForward(12345, 12345)
- turtle.turnRight()
- end
- end
- function calcuturn()
- if left then
- left = false
- else
- left = true
- end
- end
- function checkLayer(x, z)
- undone = 0
- for widthz = 1, z do
- if(DCZ == 0)then
- if(bonuz > widthz and bonuz > 0)then
- bonuz = bonuz+1
- undone = 1
- break
- end
- for heightx = 1, x do
- if(DCX == 0)then
- if(bonux > heightx and bonux > 0)then
- bonux = bonux+1
- break
- end
- compareOre()
- safeDig(widthz, heightx)
- safeForward(widthz, heightx)
- else
- if(heightx == extrax)then DCX = 0 end
- end
- end
- compareOre()
- if tonumber(widthz) < tonumber(z) then
- turn()
- end
- else
- if(widthz == extraz)then DCZ = 0 end
- end
- end
- if undone then
- if left then
- turtle.turnRight()
- for back = 1, z-1 do
- safeForward(widthz, heightx)
- end
- turtle.turnRight()
- else
- turtle.turnLeft()
- for back = 1, z-1 do
- safeForward(widthz, heightx)
- end
- turtle.turnLeft()
- for back = 1, x do
- safeForward(widthz, heightx)
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- left = false
- end
- end
- function backUp()
- if(adddown)then
- for up = 1, y+2+adddown do
- safeUp()
- end
- else
- for up = 1, y+2 do
- safeUp()
- end
- end
- end
- function digQuarry(x, z, y)
- while true do
- checkLayer(x, z)
- bonux = 0
- bonuz = 0
- for down = 1, 3 do
- depth = depth + 1
- turtle.digDown()
- turtle.down()
- end
- if(depth >= y)then
- backUp()
- print "Done!"
- break
- end
- end
- end
- if(tArgs[1] == "resume")then
- if fs.exists("spawners") then
- file = fs.open("ebpos", "r")
- skipx = tonumber(file.readLine())
- skipz = tonumber(file.readLine())
- depth = tonumber(file.readLine())
- x = tonumber(file.readLine())
- y = tonumber(file.readLine())
- z = tonumber(file.readLine())
- adddown = tonumber(file.readLine())
- file.close()
- DCZ = 1
- DCX = 1
- digQuarry(x, z, y)
- else
- print "No save file!"
- end
- error()
- end
- if(#tArgs < 3)then
- print "Usage: ebQuarry x z y add +x +z"
- error()
- else
- x = tonumber(tArgs[1]) - 1
- z = tonumber(tArgs[2])
- y = tonumber(tArgs[3])
- if(tonumber(x) and tonumber(z) and tonumber(y))then
- if(checkSlots())then
- if(checkFuel())then
- if(#tArgs >= 4)then
- if(tonumber(tArgs[4]) > 0)then
- adddown = tonumber(tArgs[4])
- for addingdown = 1, adddown do
- turtle.digDown()
- turtle.down()
- end
- end
- end
- if(#tArgs >= 5)then
- if(tonumber(tArgs[5])-1 > 0)then
- bonux = tonumber(tArgs[5])
- for bx = 1, bonux do
- turtle.forward()
- end
- end
- end
- if(#tArgs >= 6)then
- if(tonumber(tArgs[6]) > 0)then
- turtle.turnRight()
- bonuz = tonumber(tArgs[6])
- for bz = 1, bonuz do
- turtle.forward()
- calcuturn()
- end
- if left == false then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- end
- print ("Digging a " .. x+1 .. "x" .. z .. "x" .. y .. " quarry!")
- digQuarry(x, z, y)
- else
- error("Something went very wrong!")
- end
- else
- print "Please fill in the slot as follows:"
- print "Slot 14: Dirt"
- print "Slot 15: Stone"
- print "Slot 16: Fuel"
- error()
- end
- else
- print "Please use only numbers!"
- error()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement