Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DIR = 1
- function getOrientation()
- loc1 = vector.new(gps.locate(2, false))
- if not turtle.forward() then
- for j=1,6 do
- if not turtle.forward() then
- turtle.dig()
- else break end
- end
- end
- loc2 = vector.new(gps.locate(2, false))
- heading = loc2 - loc1
- return ((heading.x + math.abs(heading.x) * 2) + (heading.z + math.abs(heading.z) * 3))
- end
- function left()
- if turtle then turtle.turnLeft() end
- DIR = DIR - 1
- if DIR < 1 then DIR = DIR + 4 end
- end
- function right()
- if turtle then turtle.turnRight() end
- DIR = DIR + 1
- if DIR > 4 then DIR = DIR - 4 end
- end
- function face(target)
- if(DIR== target) then return end
- diff = DIR - target
- if(diff == 1 or diff == -3) then left()
- else
- if(math.abs(diff) == 2) then right() right()
- else right() end
- end
- end
- local modem = peripheral.find("modem")
- rednet.open("left")
- local pos = vector.new(gps.locate())
- local target = vector.new(452, 69, -438)
- local start = vector.new(gps.locate())
- DIR = getOrientation()
- print("Now facing " .. DIR)
- sleep(5)
- local diff = target - pos
- if(target.x > pos.x) then
- face(3)
- else
- face(1)
- end
- print("Now facing " .. DIR)
- while(math.abs(diff.x) > 0) do
- turtle.forward()
- pos = vector.new(gps.locate())
- diff = target - pos
- print(diff.x)
- rednet.send(6, os.getComputerLabel() .. " | " .. turtle.getFuelLevel() .. " | (" .. pos.x .. ", " .. pos.y ..", " .. pos.z .. ") | " .. "Inactive", "miners")
- end
- if(target.z > pos.z) then
- face(4)
- else
- face(2)
- end
- print("Now facing " .. DIR)
- while(math.abs(diff.z)> 0) do
- turtle.forward()
- pos = vector.new(gps.locate())
- diff = target - pos
- print(diff.z)
- rednet.send(6, os.getComputerLabel() .. " | " .. turtle.getFuelLevel() .. " | (" .. pos.x .. ", " .. pos.y ..", " .. pos.z .. ") | " .. "Inactive", "miners")
- end
- if(target.y > pos.y) then
- while(math.abs(diff.y)> 0) do
- turtle.up()
- pos = vector.new(gps.locate())
- diff = target - pos
- print(diff.y)
- rednet.send(6, os.getComputerLabel() .. " | " .. turtle.getFuelLevel() .. " | (" .. pos.x .. ", " .. pos.y ..", " .. pos.z .. ") | " .. "Inactive", "miners")
- end
- end
- if(target.y < pos.y) then
- while(math.abs(diff.y)> 0) do
- turtle.down()
- pos = vector.new(gps.locate())
- diff = target - pos
- print(diff.y)
- rednet.send(6, os.getComputerLabel() .. " | " .. turtle.getFuelLevel() .. " | (" .. pos.x .. ", " .. pos.y ..", " .. pos.z .. ") | " .. "Inactive", "miners")
- end
- end
Add Comment
Please, Sign In to add comment