/// <summary> /// Returns whether the EntityAIBase should begin execution. /// </summary> public override bool ShouldExecute() { if (!TheEntity.IsCollidedHorizontally) { return(false); } PathNavigate pathnavigate = TheEntity.GetNavigator(); PathEntity pathentity = pathnavigate.GetPath(); if (pathentity == null || pathentity.IsFinished() || !pathnavigate.Func_48665_b()) { return(false); } for (int i = 0; i < Math.Min(pathentity.GetCurrentPathIndex() + 2, pathentity.GetCurrentPathLength()); i++) { PathPoint pathpoint = pathentity.GetPathPointFromIndex(i); EntityPosX = pathpoint.XCoord; EntityPosY = pathpoint.YCoord + 1; EntityPosZ = pathpoint.ZCoord; if (TheEntity.GetDistanceSq(EntityPosX, TheEntity.PosY, EntityPosZ) > 2.25D) { continue; } TargetDoor = Func_48318_a(EntityPosX, EntityPosY, EntityPosZ); if (TargetDoor != null) { return(true); } } EntityPosX = MathHelper2.Floor_double(TheEntity.PosX); EntityPosY = MathHelper2.Floor_double(TheEntity.PosY + 1.0D); EntityPosZ = MathHelper2.Floor_double(TheEntity.PosZ); TargetDoor = Func_48318_a(EntityPosX, EntityPosY, EntityPosZ); return(TargetDoor != null); }
/// <summary> /// If null path or reached the end /// </summary> public virtual bool NoPath() { return(CurrentPath == null || CurrentPath.IsFinished()); }
public override void UpdateEntityActionState() { Profiler.StartSection("ai"); if (FleeingTick > 0) { FleeingTick--; } HasAttacked = IsMovementCeased(); float f = 16F; if (EntityToAttack == null) { EntityToAttack = FindPlayerToAttack(); if (EntityToAttack != null) { PathToEntity = WorldObj.GetPathEntityToEntity(this, EntityToAttack, f, true, false, false, true); } } else if (!EntityToAttack.IsEntityAlive()) { EntityToAttack = null; } else { float f1 = EntityToAttack.GetDistanceToEntity(this); if (CanEntityBeSeen(EntityToAttack)) { AttackEntity(EntityToAttack, f1); } else { AttackBlockedEntity(EntityToAttack, f1); } } Profiler.EndSection(); if (!HasAttacked && EntityToAttack != null && (PathToEntity == null || Rand.Next(20) == 0)) { PathToEntity = WorldObj.GetPathEntityToEntity(this, EntityToAttack, f, true, false, false, true); } else if (!HasAttacked && (PathToEntity == null && Rand.Next(180) == 0 || Rand.Next(120) == 0 || FleeingTick > 0) && EntityAge < 100) { UpdateWanderPath(); } int i = MathHelper2.Floor_double(BoundingBox.MinY + 0.5D); bool flag = IsInWater(); bool flag1 = HandleLavaMovement(); RotationPitch = 0.0F; if (PathToEntity == null || Rand.Next(100) == 0) { base.UpdateEntityActionState(); PathToEntity = null; return; } Profiler.StartSection("followpath"); Vec3D vec3d = PathToEntity.GetCurrentNodeVec3d(this); for (double d = Width * 2.0F; vec3d != null && vec3d.SquareDistanceTo(PosX, vec3d.YCoord, PosZ) < d * d;) { PathToEntity.IncrementPathIndex(); if (PathToEntity.IsFinished()) { vec3d = null; PathToEntity = null; } else { vec3d = PathToEntity.GetCurrentNodeVec3d(this); } } IsJumping = false; if (vec3d != null) { double d1 = vec3d.XCoord - PosX; double d2 = vec3d.ZCoord - PosZ; double d3 = vec3d.YCoord - (double)i; float f2 = (float)((Math.Atan2(d2, d1) * 180D) / Math.PI) - 90F; float f3 = f2 - RotationYaw; MoveForward = MoveSpeed; for (; f3 < -180F; f3 += 360F) { } for (; f3 >= 180F; f3 -= 360F) { } if (f3 > 30F) { f3 = 30F; } if (f3 < -30F) { f3 = -30F; } RotationYaw += f3; if (HasAttacked && EntityToAttack != null) { double d4 = EntityToAttack.PosX - PosX; double d5 = EntityToAttack.PosZ - PosZ; float f5 = RotationYaw; RotationYaw = (float)((Math.Atan2(d5, d4) * 180D) / Math.PI) - 90F; float f4 = (((f5 - RotationYaw) + 90F) * (float)Math.PI) / 180F; MoveStrafing = -MathHelper2.Sin(f4) * MoveForward * 1.0F; MoveForward = MathHelper2.Cos(f4) * MoveForward * 1.0F; } if (d3 > 0.0F) { IsJumping = true; } } if (EntityToAttack != null) { FaceEntity(EntityToAttack, 30F, 30F); } if (IsCollidedHorizontally && !HasPath()) { IsJumping = true; } if (Rand.NextFloat() < 0.8F && (flag || flag1)) { IsJumping = true; } Profiler.EndSection(); }