Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arg = {...}
- if arg[1] ~= nil and arg[2] ~= nil then
- width = arg[1]
- length = arg[2]
- else
- term.setTextColor(colors.red)
- print("usage: quarry <width> <length>")
- end
- x = 0
- z = 0
- y = 0
- facing = 0
- function refuel()
- if turtle.getFuelLevel() < 5 then
- turtle.refuel(1)
- return true
- end
- end
- function step()
- while not turtle.forward() do
- if not refuel() then
- if turtle.detect() then
- turtle.dig()
- else
- turtle.attack()
- end
- end
- end
- if facing == 0 then z = z + 1 end
- if facing == 2 then z = z - 1 end
- if facing == 1 then x = x + 1 end
- if facing == 3 then x = x - 1 end
- end
- function up()
- while not turtle.up() do
- if not refuel() then
- if turtle.detectUp() then
- turtle.digUp()
- else
- turtle.attackUp()
- end
- end
- end
- y = y + 1
- end
- function down()
- while not turtle.down() do
- if not refuel() then
- if turtle.detectDown() then
- turtle.digDown()
- else
- turtle.attackDown()
- end
- end
- end
- y = y - 1
- end
- function turnLeft()
- turtle.turnLeft()
- facing = facing - 1
- if facing < 0 then facing = 0 end
- end
- function turnRight()
- turtle.turnRight()
- facing = facing + 1
- if facing > 3 then facing = 3 end
- end
- function turnAround()
- if z == length-1 then
- function turn = turnRight
- elseif z == 0 then
- function turn = turnLeft
- end
- turn()
- step()
- turn()
- end
- function layer()
- for i = 1,width do
- for j = 1,length do
- step()
- end
- turnAround()
- end
- end
- function start()
- down()
- layer()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement