public virtual Vec3D Func_515_a(double par1, double par3, double par5, double par7) { int i = MathHelper2.Floor_double(par1); int j = MathHelper2.Floor_double(par3); int k = MathHelper2.Floor_double(par5); if (BlockRail.IsRailBlockAt(WorldObj, i, j - 1, k)) { j--; } int l = WorldObj.GetBlockId(i, j, k); if (BlockRail.IsRailBlock(l)) { int i1 = WorldObj.GetBlockMetadata(i, j, k); if (((BlockRail)Block.BlocksList[l]).IsPowered()) { i1 &= 7; } par3 = j; if (i1 >= 2 && i1 <= 5) { par3 = j + 1; } int[][] ai = Field_855_j[i1]; float d = ai[1][0] - ai[0][0]; float d1 = ai[1][2] - ai[0][2]; float d2 = (float)Math.Sqrt(d * d + d1 * d1); d /= d2; d1 /= d2; par1 += d * par7; par5 += d1 * par7; if (ai[0][1] != 0 && MathHelper2.Floor_double(par1) - i == ai[0][0] && MathHelper2.Floor_double(par5) - k == ai[0][2]) { par3 += ai[0][1]; } else if (ai[1][1] != 0 && MathHelper2.Floor_double(par1) - i == ai[1][0] && MathHelper2.Floor_double(par5) - k == ai[1][2]) { par3 += ai[1][1]; } return(Func_514_g(par1, par3, par5)); } else { return(null); } }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { PrevPosX = PosX; PrevPosY = PosY; PrevPosZ = PosZ; if (MaterialType == Material.Water) { ParticleRed = 0.2F; ParticleGreen = 0.3F; ParticleBlue = 1.0F; } else { ParticleRed = 1.0F; ParticleGreen = 16F / (float)((40 - BobTimer) + 16); ParticleBlue = 4F / (float)((40 - BobTimer) + 8); } MotionY -= ParticleGravity; if (BobTimer-- > 0) { MotionX *= 0.02F; MotionY *= 0.02F; MotionZ *= 0.02F; SetParticleTextureIndex(113); } else { SetParticleTextureIndex(112); } MoveEntity(MotionX, MotionY, MotionZ); MotionX *= 0.98000001907348633F; MotionY *= 0.98000001907348633F; MotionZ *= 0.98000001907348633F; if (ParticleMaxAge-- <= 0) { SetDead(); } if (OnGround) { if (MaterialType == Material.Water) { SetDead(); WorldObj.SpawnParticle("splash", PosX, PosY, PosZ, 0.0F, 0.0F, 0.0F); } else { SetParticleTextureIndex(114); } MotionX *= 0.69999998807907104F; MotionZ *= 0.69999998807907104F; } Material material = WorldObj.GetBlockMaterial(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ)); if (material.IsLiquid() || material.IsSolid()) { double d = (float)(MathHelper2.Floor_double(PosY) + 1) - BlockFluid.GetFluidHeightPercent(WorldObj.GetBlockMetadata(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ))); if (PosY < d) { SetDead(); } } }
public virtual Vec3D Func_514_g(double par1, double par3, double par5) { int i = MathHelper2.Floor_double(par1); int j = MathHelper2.Floor_double(par3); int k = MathHelper2.Floor_double(par5); if (BlockRail.IsRailBlockAt(WorldObj, i, j - 1, k)) { j--; } int l = WorldObj.GetBlockId(i, j, k); if (BlockRail.IsRailBlock(l)) { int i1 = WorldObj.GetBlockMetadata(i, j, k); par3 = j; if (((BlockRail)Block.BlocksList[l]).IsPowered()) { i1 &= 7; } if (i1 >= 2 && i1 <= 5) { par3 = j + 1; } int[][] ai = Field_855_j[i1]; double d = 0.0F; double d1 = (double)i + 0.5D + (double)ai[0][0] * 0.5D; double d2 = (double)j + 0.5D + (double)ai[0][1] * 0.5D; double d3 = (double)k + 0.5D + (double)ai[0][2] * 0.5D; double d4 = (double)i + 0.5D + (double)ai[1][0] * 0.5D; double d5 = (double)j + 0.5D + (double)ai[1][1] * 0.5D; double d6 = (double)k + 0.5D + (double)ai[1][2] * 0.5D; double d7 = d4 - d1; double d8 = (d5 - d2) * 2D; double d9 = d6 - d3; if (d7 == 0.0F) { par1 = (double)i + 0.5D; d = par5 - (double)k; } else if (d9 == 0.0F) { par5 = (double)k + 0.5D; d = par1 - (double)i; } else { double d10 = par1 - d1; double d11 = par5 - d3; double d12 = (d10 * d7 + d11 * d9) * 2D; d = d12; } par1 = d1 + d7 * d; par3 = d2 + d8 * d; par5 = d3 + d9 * d; if (d8 < 0.0F) { par3++; } if (d8 > 0.0F) { par3 += 0.5D; } return(Vec3D.CreateVector(par1, par3, par5)); } else { return(null); } }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { if (Func_41023_l() > 0) { Func_41028_c(Func_41023_l() - 1); } if (Func_41025_i() > 0) { Func_41024_b(Func_41025_i() - 1); } if (PosY < -64D) { Kill(); } if (IsMinecartPowered() && Rand.Next(4) == 0) { WorldObj.SpawnParticle("largesmoke", PosX, PosY + 0.80000000000000004D, PosZ, 0.0F, 0.0F, 0.0F); } if (WorldObj.IsRemote) { if (TurnProgress > 0) { float d = PosX + (MinecartX - PosX) / TurnProgress; float d1 = PosY + (MinecartY - PosY) / TurnProgress; float d3 = PosZ + (MinecartZ - PosZ) / TurnProgress; double d5; for (d5 = MinecartYaw - RotationYaw; d5 < -180D; d5 += 360D) { } for (; d5 >= 180D; d5 -= 360D) { } RotationYaw += (float)d5 / TurnProgress; RotationPitch += ((float)MinecartPitch - RotationPitch) / TurnProgress; TurnProgress--; SetPosition(d, d1, d3); SetRotation(RotationYaw, RotationPitch); } else { SetPosition(PosX, PosY, PosZ); SetRotation(RotationYaw, RotationPitch); } return; } PrevPosX = PosX; PrevPosY = PosY; PrevPosZ = PosZ; MotionY -= 0.039999999105930328F; int i = MathHelper2.Floor_double(PosX); int j = MathHelper2.Floor_double(PosY); int k = MathHelper2.Floor_double(PosZ); if (BlockRail.IsRailBlockAt(WorldObj, i, j - 1, k)) { j--; } float d2 = 0.40000000000000002F; float d4 = 0.0078125F; int l = WorldObj.GetBlockId(i, j, k); if (BlockRail.IsRailBlock(l)) { Vec3D vec3d = Func_514_g(PosX, PosY, PosZ); int i1 = WorldObj.GetBlockMetadata(i, j, k); PosY = j; bool flag = false; bool flag1 = false; if (l == Block.RailPowered.BlockID) { flag = (i1 & 8) != 0; flag1 = !flag; } if (((BlockRail)Block.BlocksList[l]).IsPowered()) { i1 &= 7; } if (i1 >= 2 && i1 <= 5) { PosY = j + 1; } if (i1 == 2) { MotionX -= d4; } if (i1 == 3) { MotionX += d4; } if (i1 == 4) { MotionZ += d4; } if (i1 == 5) { MotionZ -= d4; } int[][] ai = Field_855_j[i1]; float d9 = ai[1][0] - ai[0][0]; float d10 = ai[1][2] - ai[0][2]; float d11 = (float)Math.Sqrt(d9 * d9 + d10 * d10); double d12 = MotionX * d9 + MotionZ * d10; if (d12 < 0.0F) { d9 = -d9; d10 = -d10; } float d13 = (float)Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ); MotionX = (d13 * d9) / d11; MotionZ = (d13 * d10) / d11; if (flag1) { double d16 = Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ); if (d16 < 0.029999999999999999D) { MotionX *= 0.0F; MotionY *= 0.0F; MotionZ *= 0.0F; } else { MotionX *= 0.5F; MotionY *= 0.0F; MotionZ *= 0.5F; } } float d17 = 0.0F; float d18 = i + 0.5F + ai[0][0] * 0.5F; float d19 = k + 0.5F + ai[0][2] * 0.5F; float d20 = i + 0.5F + ai[1][0] * 0.5F; float d21 = k + 0.5F + ai[1][2] * 0.5F; d9 = d20 - d18; d10 = d21 - d19; if (d9 == 0.0F) { PosX = i + 0.5F; d17 = PosZ - k; } else if (d10 == 0.0F) { PosZ = k + 0.5F; d17 = PosX - i; } else { float d22 = PosX - d18; float d24 = PosZ - d19; float d26 = (d22 * d9 + d24 * d10) * 2F; d17 = d26; } PosX = d18 + d9 * d17; PosZ = d19 + d10 * d17; SetPosition(PosX, PosY + YOffset, PosZ); float d23 = MotionX; float d25 = MotionZ; if (RiddenByEntity != null) { d23 *= 0.75F; d25 *= 0.75F; } if (d23 < -d2) { d23 = -d2; } if (d23 > d2) { d23 = d2; } if (d25 < -d2) { d25 = -d2; } if (d25 > d2) { d25 = d2; } MoveEntity(d23, 0.0F, d25); if (ai[0][1] != 0 && MathHelper2.Floor_double(PosX) - i == ai[0][0] && MathHelper2.Floor_double(PosZ) - k == ai[0][2]) { SetPosition(PosX, PosY + ai[0][1], PosZ); } else if (ai[1][1] != 0 && MathHelper2.Floor_double(PosX) - i == ai[1][0] && MathHelper2.Floor_double(PosZ) - k == ai[1][2]) { SetPosition(PosX, PosY + ai[1][1], PosZ); } if (RiddenByEntity != null) { MotionX *= 0.99699997901916504F; MotionY *= 0.0F; MotionZ *= 0.99699997901916504F; } else { if (MinecartType == 2) { float d27 = MathHelper2.Sqrt_double(PushX * PushX + PushZ * PushZ); if (d27 > 0.01D) { PushX /= d27; PushZ /= d27; float d29 = 0.040000000000000001F; MotionX *= 0.80000001192092896F; MotionY *= 0.0F; MotionZ *= 0.80000001192092896F; MotionX += PushX * d29; MotionZ += PushZ * d29; } else { MotionX *= 0.89999997615814209F; MotionY *= 0.0F; MotionZ *= 0.89999997615814209F; } } MotionX *= 0.95999997854232788F; MotionY *= 0.0F; MotionZ *= 0.95999997854232788F; } Vec3D vec3d1 = Func_514_g(PosX, PosY, PosZ); if (vec3d1 != null && vec3d != null) { float d28 = ((float)vec3d.YCoord - (float)vec3d1.YCoord) * 0.050000000000000003F; float d14 = (float)Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ); if (d14 > 0.0F) { MotionX = (MotionX / d14) * (d14 + d28); MotionZ = (MotionZ / d14) * (d14 + d28); } SetPosition(PosX, (float)vec3d1.YCoord, PosZ); } int k1 = MathHelper2.Floor_double(PosX); int l1 = MathHelper2.Floor_double(PosZ); if (k1 != i || l1 != k) { float d15 = (float)Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ); MotionX = d15 * (k1 - i); MotionZ = d15 * (l1 - k); } if (MinecartType == 2) { float d30 = MathHelper2.Sqrt_double(PushX * PushX + PushZ * PushZ); if (d30 > 0.01F && MotionX * MotionX + MotionZ * MotionZ > 0.001F) { PushX /= d30; PushZ /= d30; if (PushX * MotionX + PushZ * MotionZ < 0.0F) { PushX = 0.0F; PushZ = 0.0F; } else { PushX = MotionX; PushZ = MotionZ; } } } if (flag) { float d31 = (float)Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ); if (d31 > 0.01D) { float d32 = 0.059999999999999998F; MotionX += (MotionX / d31) * d32; MotionZ += (MotionZ / d31) * d32; } else if (i1 == 1) { if (WorldObj.IsBlockNormalCube(i - 1, j, k)) { MotionX = 0.02F; } else if (WorldObj.IsBlockNormalCube(i + 1, j, k)) { MotionX = -0.02F; } } else if (i1 == 0) { if (WorldObj.IsBlockNormalCube(i, j, k - 1)) { MotionZ = 0.02F; } else if (WorldObj.IsBlockNormalCube(i, j, k + 1)) { MotionZ = -0.02F; } } } } else { if (MotionX < -d2) { MotionX = -d2; } if (MotionX > d2) { MotionX = d2; } if (MotionZ < -d2) { MotionZ = -d2; } if (MotionZ > d2) { MotionZ = d2; } if (OnGround) { MotionX *= 0.5F; MotionY *= 0.5F; MotionZ *= 0.5F; } MoveEntity(MotionX, MotionY, MotionZ); if (!OnGround) { MotionX *= 0.94999998807907104F; MotionY *= 0.94999998807907104F; MotionZ *= 0.94999998807907104F; } } RotationPitch = 0.0F; float d6 = PrevPosX - PosX; float d7 = PrevPosZ - PosZ; if (d6 * d6 + d7 * d7 > 0.001F) { RotationYaw = (float)((Math.Atan2(d7, d6) * 180F) / Math.PI); if (Field_856_i) { RotationYaw += 180F; } } float d8; for (d8 = RotationYaw - PrevRotationYaw; d8 >= 180F; d8 -= 360F) { } for (; d8 < -180D; d8 += 360F) { } if (d8 < -170D || d8 >= 170D) { RotationYaw += 180F; Field_856_i = !Field_856_i; } SetRotation(RotationYaw, RotationPitch); List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox.Expand(0.20000000298023224F, 0.0F, 0.20000000298023224F)); if (list != null && list.Count > 0) { for (int j1 = 0; j1 < list.Count; j1++) { Entity entity = list[j1]; if (entity != RiddenByEntity && entity.CanBePushed() && (entity is EntityMinecart)) { entity.ApplyEntityCollision(this); } } } if (RiddenByEntity != null && RiddenByEntity.IsDead) { if (RiddenByEntity.RidingEntity == this) { RiddenByEntity.RidingEntity = null; } RiddenByEntity = null; } if (Fuel > 0) { Fuel--; } if (Fuel <= 0) { PushX = PushZ = 0.0F; } SetMinecartPowered(Fuel > 0); }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { PrevPosX = PosX; PrevPosY = PosY; PrevPosZ = PosZ; MotionY -= ParticleGravity; MoveEntity(MotionX, MotionY, MotionZ); MotionX *= 0.98000001907348633F; MotionY *= 0.98000001907348633F; MotionZ *= 0.98000001907348633F; if (ParticleMaxAge-- <= 0) { SetDead(); } if (OnGround) { if ((new Random(1)).NextDouble() < 0.5D) { SetDead(); } MotionX *= 0.69999998807907104F; MotionZ *= 0.69999998807907104F; } Material material = WorldObj.GetBlockMaterial(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ)); if (material.IsLiquid() || material.IsSolid()) { double d = (float)(MathHelper2.Floor_double(PosY) + 1) - BlockFluid.GetFluidHeightPercent(WorldObj.GetBlockMetadata(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ))); if (PosY < d) { SetDead(); } } }
public override void UpdateEntityActionState() { base.UpdateEntityActionState(); if (WorldObj.IsRemote) { return; } if (AllySummonCooldown > 0) { AllySummonCooldown--; if (AllySummonCooldown == 0) { int i = MathHelper2.Floor_double(PosX); int k = MathHelper2.Floor_double(PosY); int i1 = MathHelper2.Floor_double(PosZ); bool flag = false; for (int l1 = 0; !flag && l1 <= 5 && l1 >= -5; l1 = l1 > 0 ? 0 - l1 : 1 - l1) { for (int j2 = 0; !flag && j2 <= 10 && j2 >= -10; j2 = j2 > 0 ? 0 - j2 : 1 - j2) { for (int k2 = 0; !flag && k2 <= 10 && k2 >= -10; k2 = k2 > 0 ? 0 - k2 : 1 - k2) { int l2 = WorldObj.GetBlockId(i + j2, k + l1, i1 + k2); if (l2 != Block.Silverfish.BlockID) { continue; } WorldObj.PlayAuxSFX(2001, i + j2, k + l1, i1 + k2, Block.Silverfish.BlockID + (WorldObj.GetBlockMetadata(i + j2, k + l1, i1 + k2) << 12)); WorldObj.SetBlockWithNotify(i + j2, k + l1, i1 + k2, 0); Block.Silverfish.OnBlockDestroyedByPlayer(WorldObj, i + j2, k + l1, i1 + k2, 0); if (!Rand.NextBool()) { continue; } flag = true; break; } } } } } if (EntityToAttack == null && !HasPath()) { int j = MathHelper2.Floor_double(PosX); int l = MathHelper2.Floor_double(PosY + 0.5D); int j1 = MathHelper2.Floor_double(PosZ); int k1 = Rand.Next(6); int i2 = WorldObj.GetBlockId(j + Facing.OffsetsXForSide[k1], l + Facing.OffsetsYForSide[k1], j1 + Facing.OffsetsZForSide[k1]); if (BlockSilverfish.GetPosingIdByMetadata(i2)) { WorldObj.SetBlockAndMetadataWithNotify(j + Facing.OffsetsXForSide[k1], l + Facing.OffsetsYForSide[k1], j1 + Facing.OffsetsZForSide[k1], Block.Silverfish.BlockID, BlockSilverfish.GetMetadataForBlockType(i2)); SpawnExplosionParticle(); SetDead(); } else { UpdateWanderPath(); } } else if (EntityToAttack != null && !HasPath()) { EntityToAttack = null; } }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { base.OnUpdate(); if (PrevRotationPitch == 0.0F && PrevRotationYaw == 0.0F) { float f = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ); PrevRotationYaw = RotationYaw = (float)((Math.Atan2(MotionX, MotionZ) * 180D) / Math.PI); PrevRotationPitch = RotationPitch = (float)((Math.Atan2(MotionY, f) * 180D) / Math.PI); } int i = WorldObj.GetBlockId(XTile, YTile, ZTile); if (i > 0) { Block.BlocksList[i].SetBlockBoundsBasedOnState(WorldObj, XTile, YTile, ZTile); AxisAlignedBB axisalignedbb = Block.BlocksList[i].GetCollisionBoundingBoxFromPool(WorldObj, XTile, YTile, ZTile); if (axisalignedbb != null && axisalignedbb.IsVecInside(Vec3D.CreateVector(PosX, PosY, PosZ))) { InGround = true; } } if (ArrowShake > 0) { ArrowShake--; } if (InGround) { int j = WorldObj.GetBlockId(XTile, YTile, ZTile); int k = WorldObj.GetBlockMetadata(XTile, YTile, ZTile); if (j != InTile || k != InData) { InGround = false; MotionX *= Rand.NextFloat() * 0.2F; MotionY *= Rand.NextFloat() * 0.2F; MotionZ *= Rand.NextFloat() * 0.2F; TicksInGround = 0; TicksInAir = 0; return; } TicksInGround++; if (TicksInGround == 1200) { SetDead(); } return; } TicksInAir++; Vec3D vec3d = Vec3D.CreateVector(PosX, PosY, PosZ); Vec3D vec3d1 = Vec3D.CreateVector(PosX + MotionX, PosY + MotionY, PosZ + MotionZ); MovingObjectPosition movingobjectposition = WorldObj.RayTraceBlocks_do_do(vec3d, vec3d1, false, true); vec3d = Vec3D.CreateVector(PosX, PosY, PosZ); vec3d1 = Vec3D.CreateVector(PosX + MotionX, PosY + MotionY, PosZ + MotionZ); if (movingobjectposition != null) { vec3d1 = Vec3D.CreateVector(movingobjectposition.HitVec.XCoord, movingobjectposition.HitVec.YCoord, movingobjectposition.HitVec.ZCoord); } Entity entity = null; List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox.AddCoord(MotionX, MotionY, MotionZ).Expand(1.0F, 1.0F, 1.0F)); double d = 0.0F; for (int l = 0; l < list.Count; l++) { Entity entity1 = list[l]; if (!entity1.CanBeCollidedWith() || entity1 == ShootingEntity && TicksInAir < 5) { continue; } float f5 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.BoundingBox.Expand(f5, f5, f5); MovingObjectPosition movingobjectposition1 = axisalignedbb1.CalculateIntercept(vec3d, vec3d1); if (movingobjectposition1 == null) { continue; } double d1 = vec3d.DistanceTo(movingobjectposition1.HitVec); if (d1 < d || d == 0.0F) { entity = entity1; d = d1; } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null) { if (movingobjectposition.EntityHit != null) { float f1 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionY * MotionY + MotionZ * MotionZ); int j1 = (int)Math.Ceiling((double)f1 * Damage); if (ArrowCritical) { j1 += Rand.Next(j1 / 2 + 2); } DamageSource damagesource = null; if (ShootingEntity == null) { damagesource = DamageSource.CauseArrowDamage(this, this); } else { damagesource = DamageSource.CauseArrowDamage(this, ShootingEntity); } if (IsBurning()) { movingobjectposition.EntityHit.SetFire(5); } if (movingobjectposition.EntityHit.AttackEntityFrom(damagesource, j1)) { if (movingobjectposition.EntityHit is EntityLiving) { ((EntityLiving)movingobjectposition.EntityHit).ArrowHitTempCounter++; if (Field_46027_au > 0) { float f7 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ); if (f7 > 0.0F) { movingobjectposition.EntityHit.AddVelocity((MotionX * Field_46027_au * 0.60000002384185791F) / f7, 0.10000000000000001F, (MotionZ * Field_46027_au * 0.60000002384185791F) / f7); } } } WorldObj.PlaySoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (Rand.NextFloat() * 0.2F + 0.9F)); SetDead(); } else { MotionX *= -0.10000000149011612F; MotionY *= -0.10000000149011612F; MotionZ *= -0.10000000149011612F; RotationYaw += 180F; PrevRotationYaw += 180F; TicksInAir = 0; } } else { XTile = movingobjectposition.BlockX; YTile = movingobjectposition.BlockY; ZTile = movingobjectposition.BlockZ; InTile = WorldObj.GetBlockId(XTile, YTile, ZTile); InData = WorldObj.GetBlockMetadata(XTile, YTile, ZTile); MotionX = (float)(movingobjectposition.HitVec.XCoord - PosX); MotionY = (float)(movingobjectposition.HitVec.YCoord - PosY); MotionZ = (float)(movingobjectposition.HitVec.ZCoord - PosZ); float f2 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionY * MotionY + MotionZ * MotionZ); PosX -= (MotionX / f2) * 0.05000000074505806F; PosY -= (MotionY / f2) * 0.05000000074505806F; PosZ -= (MotionZ / f2) * 0.05000000074505806F; WorldObj.PlaySoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (Rand.NextFloat() * 0.2F + 0.9F)); InGround = true; ArrowShake = 7; ArrowCritical = false; } } if (ArrowCritical) { for (int i1 = 0; i1 < 4; i1++) { WorldObj.SpawnParticle("crit", PosX + (MotionX * (double)i1) / 4D, PosY + (MotionY * (double)i1) / 4D, PosZ + (MotionZ * (double)i1) / 4D, -MotionX, -MotionY + 0.20000000000000001D, -MotionZ); } } PosX += MotionX; PosY += MotionY; PosZ += MotionZ; float f3 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ); RotationYaw = (float)((Math.Atan2(MotionX, MotionZ) * 180D) / Math.PI); for (RotationPitch = (float)((Math.Atan2(MotionY, f3) * 180D) / Math.PI); RotationPitch - PrevRotationPitch < -180F; PrevRotationPitch -= 360F) { } for (; RotationPitch - PrevRotationPitch >= 180F; PrevRotationPitch += 360F) { } for (; RotationYaw - PrevRotationYaw < -180F; PrevRotationYaw -= 360F) { } for (; RotationYaw - PrevRotationYaw >= 180F; PrevRotationYaw += 360F) { } RotationPitch = PrevRotationPitch + (RotationPitch - PrevRotationPitch) * 0.2F; RotationYaw = PrevRotationYaw + (RotationYaw - PrevRotationYaw) * 0.2F; float f4 = 0.99F; float f6 = 0.05F; if (IsInWater()) { for (int k1 = 0; k1 < 4; k1++) { float f8 = 0.25F; WorldObj.SpawnParticle("bubble", PosX - MotionX * (double)f8, PosY - MotionY * (double)f8, PosZ - MotionZ * (double)f8, MotionX, MotionY, MotionZ); } f4 = 0.8F; } MotionX *= f4; MotionY *= f4; MotionZ *= f4; MotionY -= f6; SetPosition(PosX, PosY, PosZ); }
/// <summary> /// Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons /// use this to react to sunlight and start to burn. /// </summary> public override void OnLivingUpdate() { if (IsWet()) { AttackEntityFrom(DamageSource.Drown, 1); } IsAttacking = EntityToAttack != null; MoveSpeed = EntityToAttack == null ? 0.3F : 6.5F; if (!WorldObj.IsRemote) { if (GetCarried() == 0) { if (Rand.Next(20) == 0) { int i = MathHelper2.Floor_double((PosX - 2D) + Rand.NextDouble() * 4D); int l = MathHelper2.Floor_double(PosY + Rand.NextDouble() * 3D); int j1 = MathHelper2.Floor_double((PosZ - 2D) + Rand.NextDouble() * 4D); int l1 = WorldObj.GetBlockId(i, l, j1); if (CanCarryBlocks[l1]) { SetCarried(WorldObj.GetBlockId(i, l, j1)); SetCarryingData(WorldObj.GetBlockMetadata(i, l, j1)); WorldObj.SetBlockWithNotify(i, l, j1, 0); } } } else if (Rand.Next(2000) == 0) { int j = MathHelper2.Floor_double((PosX - 1.0D) + Rand.NextDouble() * 2D); int i1 = MathHelper2.Floor_double(PosY + Rand.NextDouble() * 2D); int k1 = MathHelper2.Floor_double((PosZ - 1.0D) + Rand.NextDouble() * 2D); int i2 = WorldObj.GetBlockId(j, i1, k1); int j2 = WorldObj.GetBlockId(j, i1 - 1, k1); if (i2 == 0 && j2 > 0 && Block.BlocksList[j2].RenderAsNormalBlock()) { WorldObj.SetBlockAndMetadataWithNotify(j, i1, k1, GetCarried(), GetCarryingData()); SetCarried(0); } } } for (int k = 0; k < 2; k++) { WorldObj.SpawnParticle("portal", PosX + (Rand.NextDouble() - 0.5D) * (double)Width, (PosY + Rand.NextDouble() * (double)Height) - 0.25D, PosZ + (Rand.NextDouble() - 0.5D) * (double)Width, (Rand.NextDouble() - 0.5D) * 2D, -Rand.NextDouble(), (Rand.NextDouble() - 0.5D) * 2D); } if (WorldObj.IsDaytime() && !WorldObj.IsRemote) { float f = GetBrightness(1.0F); if (f > 0.5F && WorldObj.CanBlockSeeTheSky(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ)) && Rand.NextFloat() * 30F < (f - 0.4F) * 2.0F) { EntityToAttack = null; TeleportRandomly(); } } if (IsWet()) { EntityToAttack = null; TeleportRandomly(); } IsJumping = false; if (EntityToAttack != null) { FaceEntity(EntityToAttack, 100F, 100F); } if (!WorldObj.IsRemote && IsEntityAlive()) { if (EntityToAttack != null) { if ((EntityToAttack is EntityPlayer) && ShouldAttackPlayer((EntityPlayer)EntityToAttack)) { MoveStrafing = MoveForward = 0.0F; MoveSpeed = 0.0F; if (EntityToAttack.GetDistanceSqToEntity(this) < 16D) { TeleportRandomly(); } TeleportDelay = 0; } else if (EntityToAttack.GetDistanceSqToEntity(this) > 256D && TeleportDelay++ >= 30 && TeleportToEntity(EntityToAttack)) { TeleportDelay = 0; } } else { TeleportDelay = 0; } } base.OnLivingUpdate(); }