Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- local tArgs = { ... }
- local gox = tonumber(tArgs[1])
- local goy = tonumber(tArgs[2])
- local goz = tonumber(tArgs[3])
- if #tArgs ~= 3 then
- print("Uzycie: goto <x> <y> <z>")
- end
- local digBlocks = false
- local goneUp = 0
- local dir = 0
- function forward()
- while not turtle.forward() do
- if turtle.getFuelLevel() == 0 then
- turtle.select(1)
- turtle.refuel(1)
- end
- if digBlocks then
- turtle.dig()
- else
- turtle.up()
- goneUp = goneUp + 1
- end
- end
- while goneUp > 0 and not turtle.detectDown() do
- turtle.down()
- goneUp = goneUp - 1
- end
- end
- function up()
- while not turtle.up() do
- if turtle.getFuelLevel() == 0 then
- turtle.select(1)
- turtle.refuel(1)
- end
- if digBlocks then
- turtle.digUp()
- end
- end
- end
- function down()
- while not turtle.down() do
- if turtle.getFuelLevel() == 0 then
- turtle.select(1)
- turtle.refuel(1)
- end
- if digBlocks then
- turtle.digDown()
- end
- end
- end
- function getPos()
- cx, cy, cz = gps.locate(10)
- end
- function getDir()
- getPos()
- ox, oy, oz = cx, cy, cz
- forward()
- getPos()
- if oz > cz then dir = 0
- elseif oz < cz then dir = 2
- elseif ox < cx then dir = 1
- elseif ox > cx then dir = 3 end
- turtle.back()
- getPos()
- end
- function turn(d)
- getDir()
- while dir ~= d do
- turtle.turnRight()
- dir = dir + 1
- if dir == 4 then dir = 0 end
- end
- end
- function moveX()
- getPos()
- if gox > cx then
- turn(1)
- for x = 1, gox - cx do
- forward()
- cx = cx + 1
- end
- elseif gox < cx then
- turn(3)
- for x = 1, cx - gox do
- forward()
- cx = cx - 1
- end
- end
- end
- function moveZ()
- getPos()
- if goz > cz then
- turn(2)
- for z = 1, goz - cz do
- forward()
- cz = cz + 1
- end
- elseif goz < cz then
- turn(0)
- for z = 1, cz - goz do
- forward()
- cz = cz - 1
- end
- end
- end
- function moveY()
- getPos()
- if goy > cy then
- for z = 1, goy - cy do
- up()
- cy = cy + 1
- end
- elseif goy < cy then
- for z = 1, cy - goy do
- down()
- cy = cy - 1
- end
- end
- end
- getPos()
- if goy > cy then
- moveY()
- moveX()
- moveZ()
- else
- moveX()
- moveZ()
- moveY()
- end
- rednet.close()
Add Comment
Please, Sign In to add comment