public MovingObjectPosition CalculateIntercept(Vec3D par1Vec3D, Vec3D par2Vec3D) { Vec3D vec3d = par1Vec3D.GetIntermediateWithXValue(par2Vec3D, MinX); Vec3D vec3d1 = par1Vec3D.GetIntermediateWithXValue(par2Vec3D, MaxX); Vec3D vec3d2 = par1Vec3D.GetIntermediateWithYValue(par2Vec3D, MinY); Vec3D vec3d3 = par1Vec3D.GetIntermediateWithYValue(par2Vec3D, MaxY); Vec3D vec3d4 = par1Vec3D.GetIntermediateWithZValue(par2Vec3D, MinZ); Vec3D vec3d5 = par1Vec3D.GetIntermediateWithZValue(par2Vec3D, MaxZ); if (!IsVecInYZ(vec3d)) { vec3d = null; } if (!IsVecInYZ(vec3d1)) { vec3d1 = null; } if (!IsVecInXZ(vec3d2)) { vec3d2 = null; } if (!IsVecInXZ(vec3d3)) { vec3d3 = null; } if (!IsVecInXY(vec3d4)) { vec3d4 = null; } if (!IsVecInXY(vec3d5)) { vec3d5 = null; } Vec3D vec3d6 = null; if (vec3d != null && (vec3d6 == null || par1Vec3D.SquareDistanceTo(vec3d) < par1Vec3D.SquareDistanceTo(vec3d6))) { vec3d6 = vec3d; } if (vec3d1 != null && (vec3d6 == null || par1Vec3D.SquareDistanceTo(vec3d1) < par1Vec3D.SquareDistanceTo(vec3d6))) { vec3d6 = vec3d1; } if (vec3d2 != null && (vec3d6 == null || par1Vec3D.SquareDistanceTo(vec3d2) < par1Vec3D.SquareDistanceTo(vec3d6))) { vec3d6 = vec3d2; } if (vec3d3 != null && (vec3d6 == null || par1Vec3D.SquareDistanceTo(vec3d3) < par1Vec3D.SquareDistanceTo(vec3d6))) { vec3d6 = vec3d3; } if (vec3d4 != null && (vec3d6 == null || par1Vec3D.SquareDistanceTo(vec3d4) < par1Vec3D.SquareDistanceTo(vec3d6))) { vec3d6 = vec3d4; } if (vec3d5 != null && (vec3d6 == null || par1Vec3D.SquareDistanceTo(vec3d5) < par1Vec3D.SquareDistanceTo(vec3d6))) { vec3d6 = vec3d5; } if (vec3d6 == null) { return(null); } sbyte byte0 = -1; if (vec3d6 == vec3d) { byte0 = 4; } if (vec3d6 == vec3d1) { byte0 = 5; } if (vec3d6 == vec3d2) { byte0 = 0; } if (vec3d6 == vec3d3) { byte0 = 1; } if (vec3d6 == vec3d4) { byte0 = 2; } if (vec3d6 == vec3d5) { byte0 = 3; } return(new MovingObjectPosition(0, 0, 0, byte0, vec3d6)); }
private void PathFollow() { Vec3D vec3d = GetEntityPosition(); int i = CurrentPath.GetCurrentPathLength(); int i2 = CurrentPath.GetCurrentPathIndex(); do { if (i2 >= CurrentPath.GetCurrentPathLength()) { break; } if (CurrentPath.GetPathPointFromIndex(i2).YCoord != (int)vec3d.YCoord) { i = i2; break; } i2++; }while (true); float f = TheEntity.Width * TheEntity.Width; for (int j = CurrentPath.GetCurrentPathIndex(); j < i; j++) { if (vec3d.SquareDistanceTo(CurrentPath.GetVectorFromIndex(TheEntity, j)) < (double)f) { CurrentPath.SetCurrentPathIndex(j + 1); } } int k = (int)Math.Ceiling(TheEntity.Width); int l = (int)TheEntity.Height + 1; int i1 = k; int j1 = i - 1; do { if (j1 < CurrentPath.GetCurrentPathIndex()) { break; } if (IsDirectPathBetweenPoints(vec3d, CurrentPath.GetVectorFromIndex(TheEntity, j1), k, l, i1)) { CurrentPath.SetCurrentPathIndex(j1); break; } j1--; }while (true); if (TotalTicks - TicksAtLastPos > 100) { if (vec3d.SquareDistanceTo(LastPosCheck) < 2.25D) { ClearPathEntity(); } TicksAtLastPos = TotalTicks; LastPosCheck.XCoord = vec3d.XCoord; LastPosCheck.YCoord = vec3d.YCoord; LastPosCheck.ZCoord = vec3d.ZCoord; } }
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(); }