Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Args = {...}
- fileName = "quarrydata"
- function printData()
- local path = shell.resolve("quarrydata")
- data = { ["dir"] = textutils.serialize(dir), ["nDir"] = nDir, ["checkDir"] = checkDir, ["x"] = x, ["y"] = y, ["z"] = z, ["checkX"] = checkX, ["checkY"] = checkY, ["dirFor"] = dirFor, ["checkDirFor"] = checkDirFor, ["dirDown"] = dirDown, ["checkDirDown"] = checkDirDown, ["dimX"] = dimX, ["dimY"] = dimY, ["rowsClear"] = rowsClear, ["bedrockLevel"] = bedrockLevel }
- if fs.exists("quarrydata") then
- fs.delete("quarrydata")
- end
- local file = fs.open(path,"w")
- file.write(textutils.serialize(data))
- file.close()
- end
- function getData()
- local path = shell.resolve("quarrydata")
- if fs.exists("quarrydata") then
- local file = fs.open(path,"r")
- data = textutils.unserialize(file.readAll())
- x,y,z = data["x"],data["y"],data["z"]
- dir = textutils.unserialize(data["dir"])
- nDir = data["nDir"]
- checkDir = data["checkDir"]
- checkX,checkY = data["checkX"],data["checkY"]
- checkDirDown = data["checkDirDown"]
- checkDirFor = data["checkDirFor"]
- dimX,dimY = data["dimX"],data["dimY"]
- dirFor = data["dirFor"]
- dirDown = data["dirDown"]
- rowsClear = data["rowsClear"]
- bedrockLevel = data["bedrockLevel"]
- file.close()
- return true
- else
- print("Cannot continue, no data found.")
- return false
- end
- end
- function printUsage()
- print("Usage:")
- print("quarry <LENGTH> <WIDE> <left/right>")
- print("Quarries a <LENGTH> long and <WIDE> wide hole to bedrock.")
- print("quarry continue")
- print("Continues from where it left off.")
- print("Place enderchest in slot 1.")
- end
- function dropOff()
- print("Dropping off items.")
- turtle.digUp()
- turtle.select(1)
- if turtle.placeUp() then
- for i=2,16 do
- turtle.select(i)
- turtle.dropUp()
- end
- turtle.select(1)
- turtle.digUp()
- else
- print("Failed to drop off.")
- end
- end
- function hasSpace()
- local space = false
- for i=1,16 do
- if turtle.getItemCount(i) == 0 then
- space = true
- end
- end
- if not space then dropOff() end
- end
- function goDirFor(bool)
- if bool then
- if dir[nDir] == "+X" then x = x + 1 elseif
- dir[nDir] == "-X" then x = x - 1 elseif
- dir[nDir] == "+Y" then y = y + 1 elseif
- dir[nDir] == "-Y" then y = y - 1 end
- else
- if dir[nDir] == "+X" then x = x - 1 elseif
- dir[nDir] == "-X" then x = x + 1 elseif
- dir[nDir] == "+Y" then y = y - 1 elseif
- dir[nDir] == "-Y" then y = y + 1 end
- end
- end
- function mineFor()
- n = 0
- while turtle.detect() and n < 5 do
- turtle.dig()
- os.sleep(0.5)
- n = n + 1
- end
- hasSpace()
- return true
- end
- function mineUp()
- n = 0
- while turtle.detectUp() and n < 5 do
- turtle.digUp()
- os.sleep(0.5)
- n = n + 1
- end
- hasSpace()
- return true
- end
- function mineDown()
- turtle.digDown()
- hasSpace()
- return true
- end
- function goFor()
- if turtle.forward() then
- goDirFor(true)
- printData()
- return true
- else
- return false
- end
- end
- function goBack()
- if turtle.back() then
- goDirFor(false)
- printData()
- return true
- else
- return false
- end
- end
- function goUp()
- if turtle.up() then
- z = z + 1
- printData()
- return true
- else
- return false
- end
- end
- function goDown()
- if turtle.down() then
- z = z - 1
- printData()
- return true
- else
- return false
- end
- end
- function turnRight()
- turtle.turnRight()
- if nDir < 4 then
- nDir = nDir + 1
- else
- nDir = 1
- end
- printData()
- end
- function turnLeft()
- turtle.turnLeft()
- if nDir > 1 then
- nDir = nDir - 1
- else
- nDir = 4
- end
- printData()
- end
- function turnTo(desDir)
- while dir[nDir] ~= desDir do
- if dir[nDir+1] == desDir then
- turnRight()
- elseif dir[nDir-1] == desDir then
- turnLeft()
- else
- turnRight()
- end
- end
- end
- function goToX(des)
- if x > des then
- turnTo("-X")
- elseif x < des then
- turnTo("+X")
- end
- while x ~= des do
- goFor()
- end
- end
- function goToY(des)
- if y > des then
- turnTo("-Y")
- elseif y < des then
- turnTo("+Y")
- end
- while y ~= des do
- goFor()
- end
- end
- function goToZ(des)
- while z ~= des do
- if z > des then
- mineDown()
- goDown()
- else
- mineUp()
- goUp()
- end
- end
- end
- function turnAround()
- turnTo("+Y")
- mineFor()
- while not goFor() do
- mineUp()
- goUp()
- mineFor()
- end
- if dirFor then
- turnTo("-X")
- else
- turnTo("+X")
- end
- if dirDown then
- mineDown()
- mineFor()
- goDown()
- else
- mineUp()
- mineFor()
- goUp()
- end
- if dir[nDir] == "+X" then
- dirFor = true
- elseif dir[nDir] == "-X" then
- dirFor = false
- end
- rowsClear = rowsClear + 1
- end
- function quarryVertical()
- checkX,checkY = x,y
- checkDir = nDir
- checkDirFor = dirFor
- checkDirDown = dirDown
- active = true
- if dirDown then
- while active do
- mineDown()
- if dir[nDir] == "+X" then
- if x < dimX then
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- end
- elseif dir[nDir] == "-X" then
- if x > 0 then
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- end
- end
- if turtle.detectDown() then
- bedrockLevel = z
- active = false
- end
- goDown()
- if z <= bedrockLevel then
- active = false
- end
- end
- else
- while z < 0 do
- mineUp()
- if dir[nDir] == "+X" then
- if x < dimX then
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- end
- elseif dir[nDir] == "-X" then
- if x > 0 then
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- end
- end
- if not goUp() then
- goBack()
- goUp()
- end
- end
- end
- dirDown = not dirDown
- if x == dimX and dir[nDir] == "+X" then
- if y <= rowsClear then
- turnAround()
- end
- elseif x == 0 and dir[nDir] == "-X" then
- if y <= rowsClear then
- turnAround()
- end
- else
- for i = 1, 6 do
- turtle.dig()
- os.sleep(0.5)
- if not turtle.detect() then
- break
- end
- end
- if dir[nDir] == "+X" then
- if x < (dimX-1) then
- goFor()
- mineFor()
- end
- elseif dir[nDir] == "-X" then
- if x > 1 then
- goFor()
- mineFor()
- end
- end
- while not goFor() do
- mineUp()
- if not goUp() then
- goBack()
- goUp()
- end
- turtle.dig()
- bedrockLevel = z
- end
- end
- if y == (dimY+1) then
- return false
- end
- return true
- end
- function quarry()
- while quarryVertical() do
- printData()
- end
- goToY(0)
- goToX(0)
- goToZ(0)
- dropOff()
- if fs.exists("quarrydata") then
- fs.delete("quarrydata")
- end
- print("Job done.")
- end
- if #Args == 0 then
- printUsage()
- else
- if Args[1] == "continue" then
- if not getData() then
- error()
- end
- print("Quarry continueing with "..(dimX+1)..", "..(dimY+1).." quarry hole.")
- goToZ(0)
- goToX(checkX)
- goToY(checkY)
- dirDown = checkDirDown
- dirFor = checkDirFor
- turnTo(dir[checkDir])
- quarry()
- elseif tonumber(Args[1]) == 0 or tonumber(Args[2]) == 0 then
- printUsage()
- else
- if Args[3] == "right" or Args[3] == "left" then
- nDir = 1
- checkX,checkY = 0,0
- rowsClear = 0
- x,y,z = 0,0,0
- dirDown = true
- dirFor = true
- bedrockLevel = -1000
- if Args[3] == "right" then
- dir = { [0]="-Y", [1]="+X", [2]="+Y", [3]="-X", [4]="-Y", [5]="+X" }
- else
- dir = { [0]="+Y", [1]="+X", [2]="-Y", [3]="-X", [4]="+Y", [5]="+X" }
- end
- dimX = tonumber(Args[1]) - 1
- dimY = tonumber(Args[2]) - 1
- quarry()
- else
- printUsage()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment