Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for a,b in pairs(rs.getSides()) do
- if peripheral.getType(b) == 'modem' then
- rednet.open(b)
- break
- end
- end
- tArgs = {...}
- function compass()
- x,y,z = gps.locate()
- while turtle.forward() == false do
- turtle.turnRight()
- end
- x1,y1,z1 = gps.locate()
- direction = {x = x - x1, y = y - y1, z = z - z1}
- for k,v in pairs( direction ) do
- if k == "x" and v == 1 then
- facing = 1 -- west
- elseif k == "x" and v == -1 then
- facing = 3 -- east
- elseif k == "z" and v == 1 then
- facing = 2 -- north
- elseif k == "z" and v == -1 then
- facing = 0 -- south
- end
- end
- turtle.back()
- return facing
- end
- function goTo()
- xL,yL,zL = gps.locate()
- print("Starting from: "..xL.." "..yL.." "..zL)
- print("Going to: "..tArgs[1].." "..tArgs[2].." "..tArgs[3])
- while true do
- xL,yL,zL = gps.locate()
- x = xL - tArgs[1]
- y = yL - tArgs[2]
- z = zL - tArgs[3]
- if y > 0 then
- while tArgs[4] == "dig" and turtle.down() == false do
- turtle.digDown()
- end
- elseif y < 0 then
- while tArgs[4] == "dig" and turtle.up() == false do
- turtle.digUp()
- turtle.up()
- end
- elseif z < 0 then
- currentDir = compass()
- if currentDir ~= 0 then
- turnTo(0)
- end
- while tArgs[4] == "dig" and turtle.forward() == false do
- turtle.dig()
- turtle.forward()
- end
- elseif z > 0 then
- currentDir = compass()
- if currentDir ~= 2 then
- turnTo(2)
- end
- while tArgs[4] == "dig" and turtle.forward() == false do
- turtle.dig()
- turtle.forward()
- end
- elseif x < 0 then
- currentDir = compass()
- if currentDir ~= 3 then
- turnTo(3)
- end
- while tArgs[4] == "dig" and turtle.forward() == false do
- turtle.dig()
- turtle.forward()
- end
- elseif x > 0 then
- currentDir = compass()
- if currentDir ~= 1 then
- turnTo(1)
- end
- while tArgs[4] == "dig" and turtle.forward() == false do
- turtle.dig()
- turtle.forward()
- end
- else
- break
- end
- end
- end
- function turnTo(Int)
- if facing ~= Int then
- local current = facing - Int
- if current < 0 then
- for i = 1, math.abs(current) do
- turtle.turnRight()
- end
- else
- for i = 1,current do
- turtle.turnLeft()
- end
- end
- end
- end
- if #tArgs < 3 or #tArgs > 4 then
- print ("Usage: "..shell.getRunningProgram().." <x> <y> <z> <'dig' or leave blank>")
- else
- goTo()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement