Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = { ... }
- torchSlot = 1
- torchSpacing = 5
- hitBedrock = false
- -- define some relative coordinates
- home = {0,0,0} -- define home position
- face = 1 -- define home direction
- pos = {0,0,0}
- backPos = {0,0,0}
- if #args == 6 then -- if specified, set quarry position
- quarryPos ={tonumber(args[4]), tonumber(args[5]), tonumber(args[6])}
- end
- movement = {{1,0,0},{0,0,1},{-1,0,0},{0,0,-1}}
- -- movement functions
- function quarryRight()
- turtle.turnRight()
- face = face + 1
- if face > 4 then
- face = 1
- end
- end
- function quarryLeft()
- turtle.turnLeft()
- face = face - 1
- if face < 1 then
- face = 4
- end
- end
- function digMove()
- if type(turtle.getFuelLevel()) == "number" then
- if turtle.getFuelLevel() < 10 then
- turtle.select(16)
- turtle.refuel(1)
- end
- end
- if digging then
- if turtle.getItemCount(16) > 0 then
- digging = false
- oldX = pos[1]
- oldY = pos[2]
- oldZ = pos[3]
- oldFace = face
- dropInv()
- goBack(oldX, oldY, oldZ, oldFace)
- print("we should be back now")
- digging = true
- end
- end
- moved = turtle.forward()
- while not moved do
- if not turtle.dig() then
- if not turtle.attack() then
- hitBedrock = true
- print("hit Bedrock, bailing out")
- dropInv()
- end
- end
- moved = turtle.forward()
- end
- if moved then
- pos[1] = pos[1] + movement[face][1]
- pos[2] = pos[2] + movement[face][2]
- pos[3] = pos[3] + movement[face][3]
- end
- print(pos[1].." "..pos[2].." "..pos[3].." "..face)
- end
- function digMoveDown()
- if type(turtle.getFuelLevel()) == "number" then
- if turtle.getFuelLevel() < 10 then
- turtle.select(16)
- turtle.refuel(1)
- end
- end
- moved = turtle.down()
- while not moved do
- if not turtle.digDown() then
- if not turtle.attackDown() then
- hitBedrock = true
- print("hit Bedrock, bailing out")
- dropInv()
- end
- end
- moved = turtle.down()
- end
- if moved then
- pos[2] = pos[2] - 1
- end
- print(pos[1].." "..pos[2].." "..pos[3].." "..face)
- end
- function digMoveUp()
- if type(turtle.getFuelLevel()) == "number" then
- if turtle.getFuelLevel() < 10 then
- turtle.select(16)
- turtle.refuel(1)
- end
- end
- moved = turtle.up()
- while not moved do
- if not turtle.digUp() then
- if not turtle.attackUp() then
- hitBedrock = true
- end
- end
- moved = turtle.up()
- end
- if moved then
- pos[2] = pos[2] + 1
- end
- print(pos[1].." "..pos[2].." "..pos[3].." "..face)
- end
- -- meta movement functions (gohome, goback)
- function dropInv()
- print("iventory is getting full, gotta drop some stuff off")
- while pos[2] < 0 do
- digMoveUp()
- end
- if pos[1] ~= home[1] then
- if pos[1] > home[1] then
- while not (face == 3) do
- quarryLeft()
- end
- elseif pos[1] < home[1] then
- while not (face == 1) do
- quarryLeft()
- end
- end
- end
- while pos[1] ~= home[1] do
- digMove()
- end
- if pos[3] ~= home[3] then
- if pos[3] > home[3] then
- while not (face == 4) do
- quarryLeft()
- end
- elseif pos[3] < home[3] then
- while not (face == 2) do
- quarryLeft()
- end
- end
- end
- while pos[3] ~= home[3] do
- digMove()
- end
- while face ~= 3 do
- quarryLeft()
- end
- for i = 1,16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- if hitBedrock then
- os.reboot()
- end
- end
- function goBack(oldX, oldY, oldZ, oldFace)
- print("alright, back to "..oldX.." "..oldY.." "..oldZ)
- if pos[1] ~= oldX then
- if pos[1] > oldX then
- while not (face == 3) do
- quarryLeft()
- end
- elseif pos[1] < oldX then
- while not (face == 1) do
- quarryLeft()
- end
- end
- end
- while pos[1] ~= oldX do
- digMove()
- end
- if pos[3] ~= oldZ then
- if pos[3] > oldZ then
- while not (face == 4) do
- quarryLeft()
- end
- elseif pos[3] < oldZ then
- while not (face == 2) do
- quarryLeft()
- end
- end
- end
- while pos[3] ~= oldZ do
- digMove()
- end
- while pos[2] > oldY do
- digMoveDown()
- end
- while face ~= oldFace do
- quarryLeft()
- end
- end
- function gotoQuarry(qPos)
- print("going to quarry position")
- if pos[1] ~= qPos[1] then
- if pos[1] > qPos[1] then
- while not (face == 3) do
- quarryLeft()
- end
- elseif pos[1] < qPos[1] then
- while not (face == 1) do
- quarryLeft()
- end
- end
- end
- while pos[1] ~= qPos[1] do
- digMove()
- end
- if pos[3] ~= qPos[3] then
- if pos[3] > qPos[3] then
- while not (face == 4) do
- quarryLeft()
- end
- elseif pos[3] < qPos[3] then
- while not (face == 2) do
- quarryLeft()
- end
- end
- end
- while pos[3] ~= qPos[3] do
- digMove()
- end
- print("going to quarry position")
- if pos[2] ~= qPos[2] then
- if pos[2] > qPos[2] then
- while not (pos[2] == qPos[2]) do
- digMoveDown()
- end
- elseif pos[2] < qPos[2] then
- while not (pos[2] == qPos[2]) do
- digMoveUp()
- end
- end
- end
- while not (face == 1) do
- quarryLeft()
- end
- end
- function digLine(length, lNumber)
- -- print("digging a "..length.." long line")
- for i = 2,length do
- turtle.digDown()
- turtle.digUp()
- if ((i - 1) % torchSpacing == 1) and (lNumber % torchSpacing == 1) then
- turtle.select(torchSlot)
- --turtle.placeDown()
- end
- digMove()
- end
- turtle.digDown()
- turtle.digUp()
- end
- function nextLine(oldLine, lDir)
- -- print("turning for next line")
- if oldLine % 2 == 1 then -- odd linenumber -> turn in layer direction
- if lDir == "r" then -- layer direction is right
- quarryRight()
- digMove()
- quarryRight()
- else -- layer direction is left
- quarryLeft()
- digMove()
- quarryLeft()
- end
- else -- even linenumber -> turn against layer direction
- if lDir == "l" then -- layerdirection is left
- quarryRight()
- digMove()
- quarryRight()
- else -- layer direction is right
- quarryLeft()
- digMove()
- quarryLeft()
- end
- end
- end
- function digLayer(lWidth, lLength, lDir)
- -- print("digging a "..lLength.." long and "..lWidth.." wide layer")
- for n = 1,lWidth do
- digLine(lLength,n)
- if n < lWidth then
- nextLine(n, lDir)
- end
- end
- end
- function nextLayer(lWidth, lDir)
- -- print("going down for next layer")
- for n = 1,3 do
- digMoveDown()
- end
- turtle.digDown()
- if lWidth % 2 == 1 then -- odd width -> turn aginst layerDirection
- -- print("old layer had an odd width, turning against it")
- if lDir == "l" then
- quarryRight()
- else
- quarryLeft()
- end
- else -- even width -> turn into layerDirection
- -- print("old layer had an even width, turning with it")
- if lDir == "r" then
- quarryRight()
- else
- quarryLeft()
- end
- end
- end
- function digQuarry(qWidth, qLength, qDir)
- digging = true
- depth = 50
- if #args == 6 then -- goto quarry position
- gotoQuarry(quarryPos)
- end
- lWidth = qWidth
- lLength = qLength
- lDir = qDir
- for layer = 1,depth do
- digLayer(lWidth, lLength, lDir)
- if layer < depth then
- nextLayer(lWidth, lDir)
- end
- if lWidth % 2 == 1 then -- odd layer width -> change direction
- -- print("last layer had an odd width, changing layer direction")
- if lDir == "l" then
- lDir = "r"
- else
- lDir = "l"
- end
- end
- lWidth, lLength = lLength, lWidth --switch dimensions
- end
- end
- digQuarry(tonumber(args[1]),tonumber(args[2]),args[3])
- --gotoQuarry({3,-2,-2})
Advertisement
Add Comment
Please, Sign In to add comment