Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s = peripheral.wrap("left")
- dir=0
- x,y,z=nil
- function turnRight()
- turtle.turnRight()
- dir=dir+1
- define()
- end
- function turnLeft()
- turtle.turnLeft()
- dir=dir-1
- define()
- end
- function turnAround()
- turnRight()
- turnRight()
- end
- function define()
- if (dir > 3) then
- dir=dir-4
- elseif (dir < 0) then
- dir=dir+4
- end
- end
- function move()
- if (dir == 0) then
- if (z > 1.5) then
- turtle.forward()
- elseif (z < -1.5) then
- turnAround()
- elseif (x < -1.5) then
- turnRight()
- elseif (x > 1.5) then
- turnLeft()
- end
- elseif (dir == 1) then
- if (x < -1.5) then
- turtle,forward()
- elseif (x > 1.5) then
- turnAround()
- elseif (z > 1.5) then
- turnLeft()
- elseif (z < -1.5) then
- turnRight()
- end
- elseif (dir == 2) then
- if (z > 1.5) then
- turnAround()
- elseif (z < -1.5) then
- turtle.forward()
- elseif (x < -1.5) then
- turnLeft()
- elseif (x > 1.5) then
- turnRight()
- end
- elseif (dir == 3) then
- if (x < -1.5) then
- turnAround()
- elseif (x > 1.5) then
- turtle.forward()
- elseif (z > 1.5) then
- turnRight()
- elseif (z < -1.5) then
- turnLeft()
- end
- end
- end
- function turnToAttack()
- if (dir == 0) then
- if (z > 0 and z < 1.5 and x < 1.5 and x > -1.5) then
- turtle.attack()
- elseif (x < 0 and x > -1.5 and z < 1.5 and z > -1.5) then
- turnLeft()
- turtle.attack()
- elseif (x > 0 and x < 1.5 and z < 1.5 and z > -1.5) then
- turnRight()
- turtle.attack()
- end
- elseif (dir == 1) then
- if (x < 0 and x > -1.5 and z < 1.5 and z > -1.5) then
- turtle.attack()
- elseif (z > 0 and z < 1.5 and x < 1.5 and x > -1.5) then
- turnLeft()
- turtle.attack()
- elseif (z < 0 and z > -1.5 and x < 1.5 and x > -1.5) then
- turnRight()
- turtle.attack()
- end
- elseif (dir == 2) then
- if (z < 0 and z > -1.5 and x < 1.5 and x > -1.5) then
- turtle.attack()
- elseif (x < 0 and x > -1.5 and z < 1.5 and z > -1.5) then
- turnRight()
- turtle.attack()
- elseif (x > 0 and x < 1.5 and z < 1.5 and z > -1.5) then
- turnLeft()
- turtle.attack()
- end
- elseif (dir == 3) then
- if (x > 0 and x < 1.5 and z < 1.5 and z > -1.5) then
- turtle.attack()
- elseif (z < 0 and z > -1.5 and x < 1.5 and x > -1.5) then
- turnLeft()
- turtle.attack()
- elseif (z > 0 and z < 1.5 and x < 1.5 and x > -1.5) then
- turnRight()
- turtle.attack()
- end
- end
- end
- while true do
- id = s.getMobIds()[1]
- if not (id == nil) then
- pos = s.getMobData(id).position
- x = pos.x
- y = pos.y
- z = pos.z
- move()
- turnToAttack()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement