Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x, y, z = 0, 0, 0
- direction = 0
- function safeDig(side)
- if not (peripheral.getType(side) == "turtle") then
- if side == "front" then
- return turtle.dig()
- elseif side == "top" then
- return turtle.digUp()
- elseif side == "bottom" then
- return turtle.digDown()
- end
- end
- return false
- end
- function forward(steps)
- steps = steps or 1
- for i = 1, steps do
- while not turtle.forward() do
- safeDig("front")
- sleep(0.6)
- end
- if direction == 0 then
- z = z - 1
- elseif direction == 2 then
- z = z + 1
- elseif direction == 1 then
- x = x + 1
- elseif direction == 3 then
- x = x - 1
- end
- end
- end
- function up()
- while not turtle.up() do
- safeDig("top")
- end
- y = y + 1
- end
- function down()
- while not turtle.down() do
- safeDig("bottom")
- end
- y = y - 1
- end
- function turnTo(newDirection)
- local turns = newDirection - direction
- if turns <= -3 then
- turns = turns + 4
- elseif turns >= 3 then
- turns = turns - 4
- end
- while turns ~= 0 do
- if turns < 0 then
- turns = turns + 1
- turtle.turnLeft()
- else
- turns = turns - 1
- turtle.turnRight()
- end
- end
- direction = newDirection
- end
- function deploy(to)
- forward()
- if to < 0 then
- turnTo(3)
- elseif to > 0 then
- turnTo(1)
- end
- while x ~= to do
- forward()
- end
- turnTo(0)
- forward()
- end
- function dock()
- turnTo(2)
- while z < -1 do
- forward()
- end
- while y ~= -1 do
- if y < -1 then
- up()
- else
- down()
- end
- end
- if x < 0 then
- while x < -1 do
- turnTo(1)
- forward()
- end
- turnTo(2)
- forward()
- forward()
- turnTo(1)
- forward()
- else
- if x == 0 then
- turnTo(1)
- forward()
- end
- while x > 1 do
- turnTo(3)
- forward()
- end
- turnTo(2)
- forward()
- forward()
- turnTo(3)
- forward()
- end
- up()
- turnTo(0)
- forward()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement