Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Args = {...}
- x,y,z = 0,0,0
- dir = { [1]="+X", [2]="+Y", [3]="-X", [4]="-Y" }
- nDir = 1
- atBedrock = false
- dirDown = true
- dirFor = true
- function printUsage()
- print("Usage:")
- print("quarry <LENGTH> <WIDE> <left/right>")
- print("Quarries a <LENGTH> long and <WIDE> wide hole to bedrock.")
- end
- function dropOff()
- print("Dropping off items.")
- oldx = x
- oldy = y
- oldz = z
- oldDir = nDir
- goZ(0)
- goX(0)
- goY(0)
- turnTo("-X")
- turtle.select(1)
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- print("Items dropped off. Going back to "..oldx..","..oldy..","..oldz..".")
- goY(oldy)
- goX(oldx)
- goZ(oldz)
- turnTo(dir[oldDir])
- print("Back in position. Continues.")
- 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()
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- hasSpace()
- return true
- end
- function mineUp()
- while turtle.detectUp() do
- turtle.digUp()
- os.sleep(0.5)
- end
- hasSpace()
- return true
- end
- function mineDown()
- turtle.digDown()
- hasSpace()
- return true
- end
- function goFor()
- if turtle.forward() then
- goDirFor(true)
- return true
- else
- return false
- end
- end
- function goBack()
- if turtle.back() then
- goDirFor(false)
- return true
- else
- return false
- end
- end
- function goUp()
- if turtle.up() then
- z = z + 1
- return true
- else
- return false
- end
- end
- function goDown()
- if turtle.down() then
- z = z - 1
- return true
- else
- return false
- end
- end
- function turnRight()
- turtle.turnRight()
- if nDir < 4 then
- nDir = nDir + 1
- else
- nDir = 1
- end
- end
- function turnLeft()
- turtle.turnLeft()
- if nDir > 1 then
- nDir = nDir - 1
- else
- nDir = 4
- end
- end
- function stripFor()
- mineUp()
- if turtle.detectUp() then
- while turtle.detectUp() do
- goBack()
- mineUp()
- end
- goUp()
- end
- mineFor()
- while turtle.detect() do
- goUp()
- mineFor()
- end
- mineDown()
- if turtle.detectDown() and not atBedrock then
- atBedrock = true
- print("Hit bedrock.")
- end
- return goFor()
- end
- function turn()
- print("Turning around.")
- if tRight then
- turnRight()
- while not stripFor() do
- os.sleep(0.5)
- end
- turnRight()
- else
- turnLeft()
- while not stripFor() do
- os.sleep(0.5)
- end
- turnLeft()
- end
- tRight = not tRight
- dirFor = not dirFor
- end
- function stripDown()
- for i=1,3 do
- mineDown()
- mineUp()
- if turtle.detectDown() and not atBedrock then
- atBedrock = true
- print("Hit bedrock.")
- break
- end
- goDown()
- end
- turnRight()
- turnRight()
- dirFor = not dirFor
- end
- function turnTo(str)
- while dir[nDir] ~= str do
- turnRight()
- end
- end
- function goX(dx)
- if dx > x then
- turnTo("+X")
- else
- turnTo("-X")
- end
- while x ~= dx do
- turtle.dig()
- goFor()
- end
- end
- function goY(dy)
- if dy > y then
- turnTo("+Y")
- else
- turnTo("-Y")
- end
- while y ~= dy do
- turtle.dig()
- goFor()
- end
- end
- function goZ(dz)
- while dz > z do
- turtle.digUp()
- goUp()
- end
- while dz < z do
- turtle.digDown()
- goDown()
- end
- end
- function resetPos()
- goZ(0)
- goX(0)
- goY(0)
- end
- function quarry(dx,dy)
- while not atBedrock do
- for i=1,dy do
- if dirFor then
- while x < dx do
- stripFor()
- end
- if i < dy then
- turn()
- end
- else
- while x > 0 do
- stripFor()
- end
- if i < dy then
- turn()
- end
- end
- end
- if not atBedrock then
- stripDown()
- end
- end
- print("Going back to start.")
- mineDown()
- mineUp()
- resetPos()
- dropOff()
- print("Job done.")
- end
- if #Args == 0 then
- printUsage()
- else
- if tonumber(Args[1]) == 0 or tonumber(Args[2]) == 0 then
- printUsage()
- else
- if Args[3] == "right" or Args[3] == "left" then
- if Args[3] == "right" then
- tRight = true
- else
- tRight = false
- end
- if #Args == 4 then
- if tonumber(Args[4]) ~= 0 then
- for i=1,tonumber(Args[4]) do
- mineDown()
- goDown()
- end
- end
- end
- quarry(tonumber(Args[1])-1,tonumber(Args[2]))
- else
- printUsage()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment