Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for a,b in pairs(rs.getSides()) do --find modem and open rednet
- if peripheral.getType(b) == 'modem' then
- rednet.open(b)
- break
- end
- end
- 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()
- print("compass")
- return facing
- end
- function goTo(mobx, moby, mobz)
- xL,yL,zL = gps.locate()
- --while true do
- xL,yL,zL = gps.locate()
- xD = xL - math.floor(mobx)
- yD = yL - math.floor(moby)
- zD = zL - math.floor(mobz) -1
- if yD > 0 then
- while turtle.down() == false do
- turtle.forward()
- end
- elseif yD < 0 then
- while turtle.up() == false do
- turtle.forward()
- end
- elseif zD < 0 then
- currentDir = compass()
- if currentDir ~= 0 then
- turnTo(0)
- end
- for i = 1,zD*-1 do
- while turtle.forward() == false do
- turtle.turnRight()
- turtle.forward()
- end
- end
- elseif zD > 0 then
- currentDir = compass()
- if currentDir ~= 2 then
- turnTo(2)
- end
- for i = 1,zD do
- while turtle.forward() == false do
- turtle.turnRight()
- turtle.forward()
- end
- end
- elseif xD < 0 then
- currentDir = compass()
- if currentDir ~= 3 then
- turnTo(3)
- end
- for i = 1,(xD*-1) - 1 do
- while turtle.forward() == false do
- turtle.turnRight()
- turtle.forward()
- end
- end
- print("stuck")
- elseif xD > 0 then
- currentDir = compass()
- if currentDir ~= 1 then
- turnTo(1)
- end
- for i = 1,xD - 1 do
- while turtle.forward() == false do
- turtle.turnRight()
- turtle.forward()
- end
- end
- print("stuck2")
- --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
- function mobCompass()
- x,y,z = gps.locate()
- if x < position.x then
- return 3
- elseif x > position.x then
- return 1
- end
- end
- while true do
- turtle.attack()
- id, position = rednet.receive()
- myx,myy,myz = gps.locate()
- if myx - position.x <= 2 and myx - position.x >= -2 and myz - position.z <= 2 and myz - position.z >= -2 and myy == position.y then
- print("arrived at target")
- compass()
- turnTo(mobCompass())
- turtle.forward()
- turtle.attack()
- else
- goTo(position.x, position.y, position.z)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement