Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --place in bottom left corner
- local args = {...}
- local width = tonumber(args[1])
- local height = tonumber(args[2])
- local depth = tonumber(args [3])
- if table.getn(args) < 3 then
- print('Usage: ' .. shell.getRunningProgram() .. ' <width> <height> <depth>')
- error()
- end
- if width == nil or height == nil or depth == nil then
- print('Dimensions must be numbers')
- error()
- end
- if width ~= math.floor(width) or height ~= math.floor(height) or depth ~= math.floor(depth) then
- print('Dimensions must be whole numbers')
- error()
- end
- if width < 1 or height < 1 or depth < 1 then
- print('All dimensions 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 z = 0
- local orient = 1
- local xDiff = {0, 1, 0, -1}
- local yDiff = {1, 0, -1, 0}
- function forward()
- x = x + xDiff[orient + 1]
- y = y + yDiff[orient + 1]
- moved = turtle.forward()
- while not moved 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
- if turtle.detect() then turtle.dig() end
- moved = turtle.forward()
- end
- if z > -depth + 1 and turtle.detectDown() and z > 0 then turtle.digDown() end
- if turtle.detectUp() then turtle.digUp() end
- end
- function left()
- orient = orient - 1
- orient = (orient % 4)
- turtle.turnLeft()
- end
- function right()
- orient = orient + 1
- orient = (orient % 4)
- turtle.turnRight()
- end
- function up()
- if turtle.detectUp() then turtle.digUp() end
- moved = turtle.up()
- if not moved then
- repeat
- if turtle.detectUp() then turtle.digUp() end
- moved = turtle.up()
- until moved
- end
- z = z + 1
- if turtle.detectUp() and z < height -1 then turtle.digUp() end
- end
- function down()
- if turtle.detectDown() then turtle.digDown() end
- moved = turtle.down()
- if not moved then
- repeat
- if turtle.detectDown() then turtle.digDown() end
- moved = turtle.down()
- until moved
- end
- z = z - 1
- if turtle.detectDown() and z > 0 then turtle.digDown() end
- end
- function digRow()
- if width > 1 then
- repeat
- forward()
- until y == width - 1 or y == 0
- end
- end
- function digLayer(direction)
- if z == 0 and height ~= 1 then up()
- elseif z == height then down() end
- if width > 1 then
- if y ~= 0 then right()
- else left() end
- end
- repeat
- digRow()
- if (width > 3 or height > 3) and height ~= 1 and width ~= 1 then
- left()
- left()
- end
- if height > 1 then
- if direction and z < height - 2 then
- up()
- if z < height - 2 then up() end
- if z < height - 2 then up() end
- elseif z > 1 then
- down()
- if z > 1 then down() end
- if z > 1 then down() end
- end
- end
- until z <= 1 or z >= height -2
- if (width > 3 or height > 3) and height ~= 1 then digRow() end
- while orient ~= 1 do
- if orient == 2 then left()
- else right()
- end
- end
- end
- function digTunnel()
- for n = 1, depth do
- forward()
- digLayer((n % 2) ~= 0)
- end
- end
- if width == 1 and height <= 2 then
- for n = 1, depth do
- forward()
- if height == 2 then turtle.digUp() end
- end
- else
- digTunnel()
- end
- while z > 0 do down() end
Advertisement
Add Comment
Please, Sign In to add comment