Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- by morganamilo ([email protected]) based on http://pastebin.com/TgDE8CSY
- local args = {...}
- local radius = tonumber(args[1]) --the size of the radius includes the center block
- local depth = tonumber(args[2])
- local usage = 'Usage:' .. shell.getRunningProgram() .. ' <radius> <depth>'
- if table.getn(args) ~= 2 then
- print(usage)
- error()
- end
- if radius == nil or depth == nil then
- print('Radius and depth must both be numbers')
- error()
- end
- if radius ~= math.floor(args[1]) or depth ~= math.floor(args[2]) then
- print('Radius and depth must be whole numbers')
- error()
- end
- if radius < 3 or depth < 1 then
- print('Radius must be at least 3, depth must be at least 1')
- error()
- end
- local x = 0
- local y = 0 --in minecraft y is really z but the turtles coords are relative to itself so it doesnt matter
- local xDiff = {0, 1, 0, -1}
- local yDiff = {1, 0, -1, 0}
- local orient = 1
- local moves = {}
- function forward()
- x = x + xDiff[orient + 1]
- y = y + yDiff[orient + 1]
- table.insert(moves, 'forward')
- end
- function left()
- orient = orient - 1
- orient = (orient % 4)
- if moves[table.getn(moves)] ~= 'right' then
- table.insert(moves, 'left')
- else
- table.remove(moves)
- end
- end
- function right()
- orient = orient + 1
- orient = (orient % 4)
- table.insert(moves, 'right')
- end
- function doMoves()
- for n = 1, table.getn(moves) do
- if moves[n] == 'forward' then
- turtle.dig()
- while turtle.forward() == false do
- if turtle.getFuelLevel() == 0 then
- print('Out of fuel\nWaiting for fuel in slot 1...')
- while turtle.getFuelLevel() == 0 do
- turtle.refuel()
- end
- print('Fuel level is: ' .. turtle.getFuelLevel())
- end
- end
- end
- if moves[n] == 'left' then
- turtle.turnLeft() end
- if moves[n] == 'right' then
- turtle.turnRight() end
- end
- moves = {}
- end
- function round(n)
- if n - math.floor(n) >= 0.5 then
- return math.ceil(n)
- else
- return math.floor(n)
- end
- end
- function inRad(x, y, rad)
- return round(math.sqrt(x*x+y*y)) < rad
- end
- function nextInRad(rad)
- nextX = x + xDiff[orient + 1]
- nextY = y + yDiff[orient + 1]
- return inRad(nextX, nextY, rad)
- end
- function digRing(rad)
- while nextInRad(rad) do forward() end
- left()
- originalX = x
- originalY = y
- repeat
- while nextInRad(rad) do forward() end
- while not nextInRad(rad) do left() end
- forward()
- right()
- until x == originalX and y == originalY
- doMoves()
- end
- function digLayer()
- for n=1,4 do
- turtle.dig()
- turtle.turnLeft()
- end
- for n = 2, radius do
- digRing(n)
- end
- left()
- left()
- for n = 2, radius do
- forward()
- end
- left()
- left()
- doMoves()
- end
- function digCyl()
- for n = 1, depth do
- digLayer(radius)
- if n ~= depth then
- turtle.digDown()
- while turtle.down() == false do
- if turtle.getFuelLevel() == 0 then
- print('Out of fuel\nWaiting for fuel in slot 1...')
- while turtle.getFuelLevel() == 0 do
- turtle.refuel()
- end
- print('Fuel level is: ' .. turtle.getFuelLevel())
- end
- end
- end
- end
- end
- digCyl()
- print('Done!')
Advertisement
Add Comment
Please, Sign In to add comment