Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local params = {...}
- -- Validade Params
- if(tonumber(params[1]) < 1) then
- term.write("Param [".. params[1] .."] is invalid")
- return
- elseif(tonumber(params[2]) < 1) then
- term.write("Param [".. params[2] .."] is invalid")
- return
- elseif(tonumber(params[3]) < 1) then
- term.write("Param [".. params[3] .."] is invalid")
- return
- end
- params[1] = tonumber(params[1])
- params[2] = tonumber(params[2])
- params[3] = tonumber(params[3])
- -- Variables
- local posX = 0
- local posY = 0
- local posZ = 0
- local rot = 0
- -- 0 = forward
- -- 1 = right
- -- 2 = back
- -- 3 = left
- local turn = 0;
- -- Moviment
- function DirectionOperator()
- if(rot < 2) then
- return 1;
- else
- return -1;
- end
- end
- function Forward()
- if(turtle.forward()) then
- if(rot == 0) then
- posZ = posZ + 1;
- elseif(rot == 1) then
- posX = posX - 1;
- elseif(rot == 2) then
- posZ = posZ - 1;
- elseif(rot == 3) then
- posX = posX + 1;
- end
- end
- end
- function Right()
- turtle.turnRight()
- rot = rot + 1
- if(rot > 3) then
- rot = 0
- end
- end
- function Left()
- turtle.turnLeft()
- rot = rot - 1
- if(rot < 0) then
- rot = 3
- end
- end
- function Up()
- if(turtle.up()) then
- posY = posY + 1
- end
- end
- function Down()
- if(turtle.down()) then
- posY = posY - 1
- end
- end
- -- Functions
- function Dig()
- if(posY + 1 < params[2]) then
- turtle.digUp()
- end
- if(posY - 1 >= 0) then
- turtle.digDown()
- end
- if(rot == 0) then
- if(posZ + 1 <= params[3]) then
- turtle.dig()
- end
- elseif(rot == 2) then
- if(posZ - 1 > 0) then
- turtle.dig()
- end
- end
- end
- function EndRowRight()
- Right()
- turtle.dig()
- Forward()
- Right()
- end
- function EndRowLeft()
- Left()
- turtle.dig()
- Forward()
- Left()
- end
- function EndLevel()
- -- +1 already digged, +2 wont dig up, +3 will dig up
- if(posY + 3 < params[2]) then
- Up()
- turtle.digUp()
- Up()
- turtle.digUp()
- Up()
- elseif(posY + 2 < params[2]) then
- Up()
- turtle.digUp()
- Up()
- else
- return
- end
- Right()
- Right()
- end
- function NextTurn()
- if(turn == 0) then
- if(posZ == params[3] or posZ == 1) then
- EndRowLeft()
- turn = 1
- --print("Turn set to 1")
- end
- else
- if(posZ == params[3] or posZ == 1) then
- EndRowRight()
- turn = 0
- --print("Turn set to 0")
- end
- end
- end
- -- Dig Loop
- --::dig::
- local levels = math.ceil(params[2] / 3)
- if(params[2] > 1) then
- turtle.digUp()
- Up()
- end
- turtle.dig()
- Forward()
- for loopY = 1, levels do
- for loopX = 1, params[1] do
- for loopZ = 1, (params[3] - 1) do
- Dig()
- Forward()
- --print(loopZ .." ".. params[3] .." | ".. posX .." ".. posZ)
- end
- if(posY + 1 < params[2]) then
- turtle.digUp()
- end
- if(posY - 1 >= 0) then
- turtle.digDown()
- end
- if(loopX ~= params[1]) then
- --print("NextTurn")
- NextTurn()
- end
- end
- if(loopY ~= levels) then
- EndLevel()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement