Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function digforward(n)
- for i = 1, n do
- repeat
- if turtle.detect() then turtle.dig() end
- until turtle.forward()
- if direction == 1 then gx = gx + 1 end
- if direction == 2 then gy = gy + 1 end
- if direction == 3 then gx = gx - 1 end
- if direction == 4 then gy = gy - 1 end
- end
- end
- function movedown(n)
- for i = 1, n do
- repeat
- if turtle.detectDown() then turtle.digDown() end
- until turtle.down()
- gz = gz + 1
- end
- end
- function moveup(n)
- for i = 1, n do
- repeat
- if turtle.detectUp() then turtle.digUp() end
- until turtle.up()
- gz = gz - 1
- end
- end
- function turnright(n)
- for i = 1, n do
- turtle.turnRight()
- direction = direction + 1
- if direction > 4 then direction = 1 end
- end
- end
- function dumpinventory()
- for i = 2, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- end
- function dumpores()
- local rx, ry, rz, rdirection = gx, gy, gz, direction
- gohome()
- face(3)
- dumpinventory()
- gotoz(rz)
- gotoy(ry)
- gotox(rx)
- face(rdirection)
- end
- function waitforfuel()
- local rx, ry, rz, rdirection = gx, gy, gz, direction
- gohome()
- face(3)
- dumpinventory()
- print("Turtle needs more fuel. Refill and press ENTER to continue.")
- io.read()
- refuel()
- gotoz(rz)
- gotoy(ry)
- gotox(rx)
- face(rdirection)
- end
- function digoutblock(isup, isdown)
- if isup and turtle.detectUp() and (not turtle.compareUp())
- then turtle.digUp() end
- if isdown and turtle.detectDown() and (not turtle.compareDown())
- then turtle.digDown() end
- if turtle.getItemCount(16) > 0 then dumpores() end
- if turtle.getFuelLevel() < 100 then waitforfuel() end
- end
- function turn(isright)
- if isright then
- turtle.turnRight()
- direction = direction + 1
- if direction > 4 then direction = 1 end
- else
- turtle.turnLeft()
- direction = direction - 1
- if direction < 1 then direction = 4 end
- end
- end
- function digoutrow(x, isup, isdown)
- digoutblock(isup, isdown)
- if x > 1 then digforward(1) digoutrow((x - 1), isup, isdown) end
- end
- function digoutlayer(x, y, isup, isdown, isright)
- digoutrow(x, isup, isdown)
- if y > 1 then
- turn(isright)
- digforward(1)
- turn(isright)
- digoutlayer(x, (y - 1), isup, isdown, (not isright))
- else turnright(2) end
- end
- function iseven(n)
- if math.fmod(n, 2) == 0 then return true
- else return false end
- end
- function getright(y, isright)
- if iseven(y) then return not isright
- else return isright end
- end
- function face(n)
- if direction == n then return end
- turnright(1)
- face(n)
- end
- function gotox(x)
- if gx > x then face(3)
- elseif gx < x then face(1)
- elseif gx == x then return end
- digforward(1)
- gotox(x)
- end
- function gotoy(y)
- if gy > y then face(4)
- elseif gy < y then face(2)
- elseif gy == y then return end
- digforward(1)
- gotoy(y)
- end
- function gotoz(z)
- if gz > z then moveup(1) gotoz(z) end
- if gz < z then movedown(1) gotoz(z) end
- end
- function gohome()
- gotox(0)
- gotoy(0)
- gotoz(0)
- face(1)
- end
- function excavate(x, y, z, isright)
- print("Excacating "..x.." "..y.." "..z)
- if z >= 3 then
- movedown(1)
- digoutlayer(x, y, true, true, isright)
- end
- if z > 3 then
- movedown(2)
- excavate(x, y, (z - 3), getright(y, isright))
- end
- if z == 2 then digoutlayer(x, y, false, true, isright) end
- if z == 1 then digoutlayer(x, y, false, false, isright) end
- if z < 4 then gohome() end
- end
- function refuel()
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- turtle.select(1)
- end
- refuel()
- turtle.select(1)
- gx = 0
- gy = 0
- gz = 0
- direction = 1
- excavate(30, 3, 50, true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement