Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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]
- repeat
- moved = turtle.forward()
- if moved == false then
- turtle.dig()
- end
- until moved == true
- 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()
- turtle.up()
- z = z + 1
- end
- function down()
- turtle.down()
- z = z - 1
- end
- function getCorner() -- 1, 2, 3, 4 = topL, topR, bottomL, bottomR
- if y ~= 0 and z ~= 0 then return 1 end
- if y == 0 and z ~= 0 then return 2 end
- if y ~= 0 and z == 0 then return 3 end
- if y == 0 and z == 0 then return 4 end
- end
- function digRow()
- if width > 1 then
- repeat
- turtle.dig()
- print(z ~= depth)
- print(getcorner ~= 4)
- if z ~= depth then forward() end
- until y == width - 1 or y == 0
- end
- end
- function digLayer()
- if height > 1 then
- corner = getCorner()
- if corner == 1 or corner == 3 then
- right()
- else
- left()
- end
- repeat
- digRow()
- left()
- left()
- if corner > 2 then
- if z ~= height then
- turtle.digUp()
- up()
- end
- end
- if corner < 3 then
- if z ~= 0 then
- turtle.digDown()
- down()
- end
- end
- until z == 0 or z == height -1
- digRow()
- while orient ~= 1 do
- if orient == 2 then left()
- else right()
- end
- end
- end
- end
- function digTunnel()
- for n = 1, depth do
- digLayer()
- end
- end
- digTunnel()
Advertisement
Add Comment
Please, Sign In to add comment