Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Efficient Digging Program by Galygious
- --Variables
- tArgs = { ... }
- m3 = 0
- m2 = 0
- m1 = 0
- h = 0
- r = 0
- f = o
- forward = true
- --Functions
- local printUsage = function(ecode)
- if ecode == 0 then
- print('Error Code 0\nThis Program Requires these variables:\narg1 - Depth (positive number)\narg2 - Width (positive number)\narg3 - Height (positive number)')
- error()
- elseif ecode == 1 then
- print('Error Code 0\nThis Program Requires these variables:\narg1 - Depth (positive number)\narg2 - Width (positive number)\narg3 - Height (positive number)')
- error()
- elseif ecode == 2 then
- print('Error Code 2\nFirst argument must represent a distance (positive number)')
- error()
- elseif ecode == 3 then
- print('Error Code 3\nFirst argument must represent a distance (positive number)')
- error()
- elseif ecode == 4 then
- print('Error Code 4\nSecond argument must represent a distance (positive number)')
- error()
- elseif ecode == 5 then
- print('Error Code 5\nSecond argument must represent a distance (positive number)')
- error()
- elseif ecode == 6 then
- print('Error Code 6\nThird argument must represent a distance (positive number)')
- error()
- elseif ecode == 7 then
- print('Error Code 7\nThird argument must represent a distance (positive number)')
- error()
- end
- end
- local mineup = function()
- while turtle.detectUp() do
- if not turtle.digUp() then
- sleep(0.8)
- end
- end
- end
- local minedown = function()
- while turtle.detectDown() do
- if not turtle.digDown() then
- sleep(0.8)
- end
- end
- end
- local move = function(Dir,Dis)
- shell.run('/progs/move',Dir,Dis)
- end
- local tturn = function(Dir)
- shell.run('/progs/tturn',Dir)
- end
- local mine1 = function()
- move('f',1)
- end
- local mine2 = function()
- move('f',1)
- mineup()
- end
- local mine3 = function()
- move('f',1)
- mineup()
- minedown()
- end
- local row1 = function()
- for i=1,depth-1 do
- mine1()
- end
- end
- local row2 = function()
- mineup()
- for i=1,depth-1 do
- mine2()
- end
- end
- local row3 = function()
- mineup()
- minedown()
- for i=1,depth-1 do
- mine3()
- end
- end
- local quarry1 = function()
- if height > 1 then
- move('u',2)
- h=h+2
- tturn('u')
- forward = not forward
- end
- for i=1,width do
- row1()
- if forward==true and i ~= width then
- if not (runs % 2 == 0) then
- move('r',1)
- tturn('r')
- else
- move('l',1)
- tturn('l')
- end
- forward=not forward
- elseif forward==false and i ~= width then
- if not (runs % 2 == 0) then
- move('l',1)
- tturn('l')
- else
- move('r',1)
- tturn('r')
- end
- forward=not forward
- end
- end
- end
- local quarry2 = function()
- if height > 2 then
- move('u',2)
- h=h+2
- tturn('u')
- forward = not forward
- end
- for i=1,width do
- row2()
- if forward==true and i ~= width then
- if not (runs % 2 == 0) then
- move('r',1)
- tturn('r')
- else
- move('l',1)
- tturn('l')
- end
- forward=not forward
- elseif forward==false and i ~= width then
- if not (runs % 2 == 0) then
- move('l',1)
- tturn('l')
- else
- move('r',1)
- tturn('r')
- end
- forward=not forward
- end
- end
- end
- local quarry3 = function()
- if height > 3 and start == false then
- move('u',3)
- h=h+3
- tturn('u')
- forward = not forward
- elseif start == true then
- move('u',1)
- h=h+1
- start = not start
- end
- for i=1,width do
- row3()
- if forward==true and i ~= width then
- if not ((m3c + 1)% 2 == 0) then
- move('r',1)
- tturn('r')
- else
- move('l',1)
- tturn('l')
- end
- forward=not forward
- elseif forward==false and i ~= width then
- if not ((m3c + 1)% 2 == 0) then
- move('l',1)
- tturn('l')
- else
- move('r',1)
- tturn('r')
- end
- forward=not forward
- end
- end
- end
- --Argument Handling
- if tArgs[1] ~= nil then
- if #tArgs ~= 3 then
- printUsage(1)
- elseif not tonumber(tArgs[1]) then
- printUsage(2)
- elseif tonumber(tArgs[1]) < 0 then
- printUsage(3)
- elseif not tonumber(tArgs[2]) then
- printUsage(4)
- elseif tonumber(tArgs[2]) < 0 then
- printUsage(5)
- elseif not tonumber(tArgs[3]) then
- printUsage(6)
- elseif tonumber(tArgs[3]) < 0 then
- printUsage(7)
- else
- depth = tonumber(tArgs[1])
- print('depth = ' .. tArgs[1])
- width = tonumber(tArgs[2])
- print('width = ' .. tArgs[2])
- height = tonumber(tArgs[3])
- print('height = ' .. tArgs[3])
- end
- else
- printUsage(0)
- end
- --calculate how to mine
- h = tonumber(height)
- while h > 2 do
- h=h-3
- m3=m3+1
- end
- if h>1 then
- h=0
- m2=1
- elseif h>0 then
- h=0
- m1=1
- end
- -- Begin Mining
- runs = m3 + m2 +m1
- start=true
- m3c=0
- while m3c < m3 do
- quarry3()
- m3c=m3c+1
- end
- if m2 > 0 then
- quarry2()
- end
- if m1 > 0 then
- quarry1()
- end
- if (runs % 2 == 0) then
- --already at start
- move('d',h)
- tturn('u')
- else
- --move back to left
- if forward == true then
- move('l',width-1)
- move('l',depth-1)
- tturn('u')
- move('d',h)
- else
- move('r',width-1)
- tturn('r')
- move('d',h)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment