Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- xH = -175
- yH = 15
- zH = 539
- homeFace = 1
- 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 goHome()
- while true do
- xL,yL,zL = gps.locate()
- print(yL)
- print(yH)
- x = xL - xH
- y = yL - yH
- z = zL - zH
- if y > 0 then
- turtle.down()
- elseif y < 0 then
- turtle.up()
- elseif z < 0 then
- currentDir = compass()
- if currentDir ~= 0 then
- turnTo(0)
- end
- while turtle.forward() == false do
- turtle.select(4)
- turtle.dig()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- end
- elseif z > 0 then
- currentDir = compass()
- if currentDir ~= 2 then
- turnTo(2)
- end
- while turtle.forward() == false do
- turtle.select(4)
- turtle.dig()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- end
- elseif x < 0 then
- currentDir = compass()
- if currentDir ~= 3 then
- turnTo(3)
- end
- while turtle.forward() == false do
- turtle.select(4)
- turtle.dig()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- end
- elseif x > 0 then
- currentDir = compass()
- if currentDir ~= 1 then
- turnTo(1)
- end
- while turtle.forward() == false do
- turtle.select(4)
- turtle.dig()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- 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
- goHome()
- compass()
- turnTo(homeFace)
- while true do
- event, p1, p2 = os.pullEvent("rednet_message")
- if p1 == 33 and p2 == true then
- goHome()
- print("got home")
- compass()
- turnTo(homeFace)
- sleep(.5)
- event = os.pullEvent("redstone")
- for i = 1,2 do
- turtle.forward()
- end
- turtle.select(4)
- turtle.dig()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.down()
- turtle.select(1)
- turtle.place()
- turtle.up()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.place()
- for i = 1, 2 do
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.place()
- end
- turtle.up()
- turtle.select(2)
- turtle.place()
- for i = 1,2 do
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.place()
- end
- turtle.down()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.select(4)
- turtle.dig()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- for i = 1,4 do
- turtle.forward()
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(3)
- turtle.refuel(1)
- sleep(11)
- else
- sleep(0.1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement