Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem")
- modem.open(2)
- modem.open(42069)
- local rotation = 1 --1 = north , 2 = east, 3 = south, 4 = west
- local rotationtable1 = {north = {0,-1}, east = {1,0}, south = {0,1}, west = {-1,0}}
- local rotationtable = {{0,-1},{1,0},{0,1},{-1,0}}
- local x,z,y = gps.locate()
- local function findrotation()
- print("executing findrotation")
- local tempx , tempz , tempy = gps.locate()
- if turtle.forward() then
- local tempxx , tempzz , tempyy = gps.locate()
- turtle.back()
- if tempzz < tempz then
- return 1
- elseif tempzz > tempz then
- return 3
- elseif tempxx < tempx then
- return 4
- elseif tempxx > tempx then
- return 2
- end
- else
- turtle.turnRight()
- return findrotation()
- end
- end
- local function f()
- if turtle.forward() then
- x = x + rotationtable[rotation][1]
- z = z + rotationtable[rotation][2]
- else
- if turtle.up() then
- f()
- y = y + 1
- else
- print(x,z,y,rotation)
- end
- end
- end
- local function b()
- if turtle.back() then
- x = x - rotationtable[rotation][1]
- z = z - rotationtable[rotation][2]
- end
- end
- local function CheckNeededRotation(xcords , zcords, ycords)
- print("executing CheckNeededRotation")
- local tempx , tempz , tempy = gps.locate()
- f()
- if tempz > zcords then
- b()
- return 1
- elseif tempz < zcords then
- b()
- return 3
- elseif tempx < xcords then
- b()
- return 2
- elseif tempx > xcords then
- b()
- return 4
- end
- end
- local function rotate(cardinaldirectionNum)
- print("executing rotation")
- if rotation == 1 then
- rotation = cardinaldirectionNum
- if cardinaldirectionNum == 2 then
- turtle.turnRight()
- elseif cardinaldirectionNum == 3 then
- turtle.turnRight()
- turtle.turnRight()
- elseif cardinaldirectionNum == 4 then
- turtle.turnLeft()
- end
- elseif rotation == 2 then
- rotation = cardinaldirectionNum
- if cardinaldirectionNum == 1 then
- turtle.turnLeft()
- elseif cardinaldirectionNum == 3 then
- turtle.turnRight()
- elseif cardinaldirectionNum == 4 then
- turtle.turnRight()
- turtle.turnRight()
- end
- elseif rotation == 3 then
- rotation = cardinaldirectionNum
- if cardinaldirectionNum == 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif cardinaldirectionNum == 2 then
- turtle.turnLeft()
- elseif cardinaldirectionNum == 4 then
- turtle.turnRight()
- end
- elseif rotation == 4 then
- rotation = cardinaldirectionNum
- if cardinaldirectionNum == 1 then
- turtle.turnRight()
- elseif cardinaldirectionNum == 2 then
- turtle.turnRight()
- turtle.turnRight()
- elseif cardinaldirectionNum == 3 then
- turtle.turnLeft()
- end
- end
- end
- local function IsThere(xcords,zcords,ycords)
- print("executing IsThere\n"
- , x,z,y ,"\n"
- , xcords,zcords,ycords)
- if x == xcords and zcords == z then
- if ycords > y then
- while turtle.down() do
- end
- print("IsThere is true")
- return true
- end
- end
- print("IsThere is false")
- return false
- end
- local function GoUntilNeeded(xcords,zcords,ycords)
- print("executing GoUntilNeeded")
- local temp = CheckNeededRotation(xcords,zcords,ycords)
- rotate(temp)
- if zcords ~= z then
- print("executing moving in z direction")
- while zcords ~= z do
- f()
- end
- print("done executing moving in z direction")
- elseif xcords ~= x then
- print("executing moving in x direction")
- while xcords ~= x do
- f()
- end
- print("done executing moving in x direction")
- end
- end
- while true do
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- if message == "b" then
- break
- end
- print("")
- local xcord = message[1]
- local zcord = message[2]
- local ycord = message[3]
- rotation = findrotation()
- print(rotation)
- while IsThere(xcord,zcord,zcord)~=true do
- GoUntilNeeded(xcord,zcord,ycord)
- end
- print("---------------")
- print(x,z,y)
- print(message[1],message[2],message[3])
- print("got there")
- end
- modem.closeAll()
Add Comment
Please, Sign In to add comment