Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local width, length
- local blocksMined = 0
- local xDir, zDir = 0, 1
- local xx, yy, zz = 0, 0, 0
- local enderChest = false
- local quarryLeft = false
- local quarryUpwd = false
- local fuelLimit = turtle.getFuelLimit()
- local args = {...}
- local nArgs = #args
- local optns = 0
- if string.sub(args[1], 1, 1) == "-" then
- optns = 1
- local ops = string.lower(string.sub(args[1], 2))
- if string.match(ops, "e") then enderChest = true end
- if string.match(ops, "l") then quarryLeft = true end
- if string.match(ops, "u") then quarryUpwd = true end
- end
- width = tonumber(args[optns+1])
- if (nArgs - optns == 1) then
- length = width
- elseif (nArgs - optns == 2) then
- length = tonumber(args[optns+2])
- end
- function spaceLeft()
- if enderChest then return turtle.getItemCount(15)==0
- else return turtle.getItemCount(16)==0 end
- end
- function isFueled(over)
- local over = over or 0
- return ( turtle.getFuelLevel() > ( xx + yy + zz + over ) )
- end
- function left()
- local swap = xDir
- turtle.turnLeft()
- xDir = zDir
- zDir = -swap
- end
- function right()
- local swap = xDir
- turtle.turnRight()
- xDir = -zDir
- zDir = swap
- end
- function iLeft() if quarryLeft then right() else left() end end
- function iRight() if quarryLeft then left() else right() end end
- function forward(dist)
- local dist = dist or 1
- dist = math.abs(dist)
- for iter = 1, dist do
- while not turtle.forward() do
- refuel()
- if turtle.detect() and (not turtle.dig()) then
- return false end
- turtle.attack()
- turtle.suck()
- end
- xx = xx + xDir
- zz = zz + zDir
- end
- end
- function up(dist)
- local dist = dist or 1
- dist = math.abs(dist)
- for iter = 1, dist do
- while not turtle.up() do
- refuel()
- if turtle.detectUp() and (not turtle.digUp()) then
- return false end
- turtle.attackUp()
- turtle.suckUp()
- end
- yy = yy - 1
- end
- end
- function down(dist)
- local dist = dist or 1
- dist = math.abs(dist)
- for iter = 1, dist do
- while not turtle.down() do
- refuel()
- if turtle.detectDown() and (not turtle.digDown()) then
- return false end
- turtle.attackDown()
- turtle.suckDown()
- end
- yy = yy + 1
- end
- end
- function goTo(pos)
- local xX, yY, zZ, xXDir, zZDir = pos[1], pos[2], pos[3], pos[4], pos[5]
- if (yY < yy) then up(2)
- elseif (yY > yy) then down(2) end
- if (xX > xx) then
- while (xDir ~= 1) do
- right()
- end
- elseif (xX < xx) then
- while (xDir ~= -1) do
- left()
- end
- end
- forward(xX - xx)
- if (zZ > zz) then
- while (zDir ~= 1) do
- left()
- end
- elseif (zZ < zz) then
- while (zDir ~= -1) do
- right()
- end
- end
- forward(zZ - zz)
- if (yY < yy) then up(yY - yy)
- elseif (yY > yy) then down(yY - yy) end
- while not ((xXDir == xDir) and (zZDir == zDir)) do
- right()
- end
- end
- function mineFwd()
- if not spaceLeft() then dropLoot() end
- while turtle.dig() do
- blocksMined = blocksMined + 1
- sleep(0.05)
- end
- refuel()
- if not spaceLeft() then dropLoot() end
- forward()
- while turtle.digUp() do
- blocksMined = blocksMined + 1
- sleep(0.1)
- end
- if not spaceLeft() then dropLoot() end
- if turtle.digDown() then blocksMined = blocksMined + 1 end
- turtle.suckUp()
- turtle.suckDown()
- end
- function refuel(over)
- local over = over or 5
- if not ((fuelLimit==0) or isFueled(over)) then
- if enderChest then
- turtle.select(1)
- turtle.placeUp()
- turtle.suckUp(1)
- turtle.refuel(1)
- turtle.digUp()
- elseif (turtle.getItemCount(1) > 0) then
- turtle.select(1)
- turtle.refuel(1)
- else
- local pos = {xx, yy, zz, xDir, zDir}
- goTo({0, 0, 0, 0, -1})
- print("Waiting for Fuel...")
- while (turtle.getItemCount(1) == 0) do
- os.pullEvent("turtle_inventory")
- end
- turtle.select(1)
- turtle.refuel()
- goTo(pos)
- end
- end
- end
- function dropLoot(done)
- local done = done or false
- local pos = {xx, yy, zz, xDir, zDir}
- if enderChest then
- turtle.select(16)
- turtle.placeUp()
- for slot = 2, 15 do
- turtle.select(slot)
- while not turtle.dropUp() do
- sleep(10)
- end
- end
- turtle.select(16)
- turtle.digUp()
- else
- refuel(2)
- goTo({0, 0, 0, 0, -1})
- for slot = 2, 16 do
- turtle.select(slot)
- while not turtle.drop() do
- sleep(10)
- end
- end
- if not done then
- turtle.refuel(pos[1] + pos[2] + pos[3])
- goTo(pos)
- else goTo({0, 0, 0, 0, 1}) end
- end
- turtle.select(1)
- end
- local alternate = 0
- local square = width == length
- local swapSides = false
- local done = turtle.detectDown() and (not turtle.digDown())
- turtle.digUp()
- while not done do
- local iWidth, iLength
- if (not square) and swapSides then
- iWidth, iLength = length, width
- else
- iWidth, iLength = width, length
- end
- for ii = 1, iWidth do
- for jj = 1, iLength-1 do
- mineFwd()
- end
- if ii < iWidth then
- if math.fmod(ii + alternate, 2) == 0 then
- iLeft()
- mineFwd()
- iLeft()
- else
- iRight()
- mineFwd()
- iRight()
- end
- end
- end
- if (width > 1) and (length > 1) then
- if math.fmod(iWidth, 2) == 0 then
- if (alternate == 0) or math.fmod(iLength, 2) == 0 then
- iRight()
- else iLeft() end
- else
- if alternate == 0 then
- iLeft()
- else
- iRight()
- end
- alternate = 1 - alternate
- end
- end
- for n = 1, 3 do
- if quarryUpwd then
- up()
- turtle.digUp()
- else
- turtle.digDown()
- down()
- end
- end
- swapSides = not swapSides
- done = (turtle.detectDown() and (not turtle.digDown())) and (not turtle.detect())
- end
- dropLoot(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement