/// <summary> /// Checks if the entity's current position is a valid location to spawn this entity. /// </summary> public override bool GetCanSpawnHere() { if (WorldObj.Rand.Next(3) == 0) { return(false); } if (WorldObj.CheckIfAABBIsClear(BoundingBox) && WorldObj.GetCollidingBoundingBoxes(this, BoundingBox).Count == 0 && !WorldObj.IsAnyLiquid(BoundingBox)) { int i = MathHelper2.Floor_double(PosX); int j = MathHelper2.Floor_double(BoundingBox.MinY); int k = MathHelper2.Floor_double(PosZ); if (j < 63) { return(false); } int l = WorldObj.GetBlockId(i, j - 1, k); if (l == Block.Grass.BlockID || l == Block.Leaves.BlockID) { return(true); } } return(false); }
/// <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() { base.OnLivingUpdate(); if (IsWet()) { AttackEntityFrom(DamageSource.Drown, 1); } int i = MathHelper2.Floor_double(PosX); int k = MathHelper2.Floor_double(PosZ); if (WorldObj.GetBiomeGenForCoords(i, k).GetFloatTemperature() > 1.0F) { AttackEntityFrom(DamageSource.OnFire, 1); } for (int j = 0; j < 4; j++) { int l = MathHelper2.Floor_double(PosX + (double)((float)((j % 2) * 2 - 1) * 0.25F)); int i1 = MathHelper2.Floor_double(PosY); int j1 = MathHelper2.Floor_double(PosZ + (double)((float)(((j / 2) % 2) * 2 - 1) * 0.25F)); if (WorldObj.GetBlockId(l, i1, j1) == 0 && WorldObj.GetBiomeGenForCoords(l, j1).GetFloatTemperature() < 0.8F && Block.Snow.CanPlaceBlockAt(WorldObj, l, i1, j1)) { WorldObj.SetBlockWithNotify(l, i1, j1, Block.Snow.BlockID); } } }
/// <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() { base.OnLivingUpdate(); if (Field_48120_c > 0) { Field_48120_c--; } if (Field_48118_d > 0) { Field_48118_d--; } //JAVA TO C# CONVERTER TODO TASK: Octal literals cannot be represented in C#: if (MotionX * MotionX + MotionZ * MotionZ > 2.5000002779052011E-007D && Rand.Next(5) == 0) { int i = MathHelper2.Floor_double(PosX); int j = MathHelper2.Floor_double(PosY - 0.20000000298023224D - (double)YOffset); int k = MathHelper2.Floor_double(PosZ); int l = WorldObj.GetBlockId(i, j, k); if (l > 0) { WorldObj.SpawnParticle((new StringBuilder()).Append("tilecrack_").Append(l).ToString(), PosX + ((double)Rand.NextFloat() - 0.5D) * (double)Width, BoundingBox.MinY + 0.10000000000000001D, PosZ + ((double)Rand.NextFloat() - 0.5D) * (double)Width, 4D * ((double)Rand.NextFloat() - 0.5D), 0.5D, ((double)Rand.NextFloat() - 0.5D) * 4D); } } }
/// <summary> /// Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count /// ticks and creates a new spawn inside its implementation. /// </summary> public override void UpdateEntity() { LastProgress = Progress; if (LastProgress >= 1.0F) { UpdatePushedObjects(1.0F, 0.25F); WorldObj.RemoveBlockTileEntity(XCoord, YCoord, ZCoord); Invalidate(); if (WorldObj.GetBlockId(XCoord, YCoord, ZCoord) == Block.PistonMoving.BlockID) { WorldObj.SetBlockAndMetadataWithNotify(XCoord, YCoord, ZCoord, StoredBlockID, StoredMetadata); } return; } Progress += 0.5F; if (Progress >= 1.0F) { Progress = 1.0F; } if (Extending) { UpdatePushedObjects(Progress, (Progress - LastProgress) + 0.0625F); } }
/// <summary> /// Checks if the entity's current position is a valid location to spawn this entity. /// </summary> public override bool GetCanSpawnHere() { int i = MathHelper2.Floor_double(PosX); int j = MathHelper2.Floor_double(BoundingBox.MinY); int k = MathHelper2.Floor_double(PosZ); return(WorldObj.GetBlockId(i, j - 1, k) == Block.Grass.BlockID && WorldObj.GetFullBlockLightValue(i, j, k) > 8 && base.GetCanSpawnHere()); }
/// <summary> /// Takes a coordinate in and returns a weight to determine how likely this creature will try to path to the block. /// Args: x, y, z /// </summary> public override float GetBlockPathWeight(int par1, int par2, int par3) { if (WorldObj.GetBlockId(par1, par2 - 1, par3) == Block.Grass.BlockID) { return(10F); } else { return(WorldObj.GetLightBrightness(par1, par2, par3) - 0.5F); } }
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> /// Takes a coordinate in and returns a weight to determine how likely this creature will try to path to the block. /// Args: x, y, z /// </summary> public override float GetBlockPathWeight(int par1, int par2, int par3) { if (WorldObj.GetBlockId(par1, par2 - 1, par3) == Block.Stone.BlockID) { return(10F); } else { return(base.GetBlockPathWeight(par1, par2, par3)); } }
/// <summary> /// performs the check for adjacent chests to determine if this chest is double or not. /// </summary> public virtual void CheckForAdjacentChests() { if (AdjacentChestChecked) { return; } AdjacentChestChecked = true; AdjacentChestZNeg = null; AdjacentChestXPos = null; AdjacentChestXNeg = null; AdjacentChestZPos = null; if (WorldObj.GetBlockId(XCoord - 1, YCoord, ZCoord) == Block.Chest.BlockID) { AdjacentChestXNeg = (TileEntityChest)WorldObj.GetBlockTileEntity(XCoord - 1, YCoord, ZCoord); } if (WorldObj.GetBlockId(XCoord + 1, YCoord, ZCoord) == Block.Chest.BlockID) { AdjacentChestXPos = (TileEntityChest)WorldObj.GetBlockTileEntity(XCoord + 1, YCoord, ZCoord); } if (WorldObj.GetBlockId(XCoord, YCoord, ZCoord - 1) == Block.Chest.BlockID) { AdjacentChestZNeg = (TileEntityChest)WorldObj.GetBlockTileEntity(XCoord, YCoord, ZCoord - 1); } if (WorldObj.GetBlockId(XCoord, YCoord, ZCoord + 1) == Block.Chest.BlockID) { AdjacentChestZPos = (TileEntityChest)WorldObj.GetBlockTileEntity(XCoord, YCoord, ZCoord + 1); } if (AdjacentChestZNeg != null) { AdjacentChestZNeg.UpdateContainingBlockInfo(); } if (AdjacentChestZPos != null) { AdjacentChestZPos.UpdateContainingBlockInfo(); } if (AdjacentChestXPos != null) { AdjacentChestXPos.UpdateContainingBlockInfo(); } if (AdjacentChestXNeg != null) { AdjacentChestXNeg.UpdateContainingBlockInfo(); } }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { base.OnUpdate(); if (DelayBeforeCanPickup > 0) { DelayBeforeCanPickup--; } PrevPosX = PosX; PrevPosY = PosY; PrevPosZ = PosZ; MotionY -= 0.039999999105930328F; if (WorldObj.GetBlockMaterial(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ)) == Material.Lava) { MotionY = 0.20000000298023224F; MotionX = (Rand.NextFloat() - Rand.NextFloat()) * 0.2F; MotionZ = (Rand.NextFloat() - Rand.NextFloat()) * 0.2F; WorldObj.PlaySoundAtEntity(this, "random.fizz", 0.4F, 2.0F + Rand.NextFloat() * 0.4F); } PushOutOfBlocks(PosX, (BoundingBox.MinY + BoundingBox.MaxY) / 2F, PosZ); MoveEntity(MotionX, MotionY, MotionZ); float f = 0.98F; if (OnGround) { f = 0.5880001F; int i = WorldObj.GetBlockId(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(BoundingBox.MinY) - 1, MathHelper2.Floor_double(PosZ)); if (i > 0) { f = Block.BlocksList[i].Slipperiness * 0.98F; } } MotionX *= f; MotionY *= 0.98000001907348633F; MotionZ *= f; if (OnGround) { MotionY *= -0.5F; } Age++; if (Age >= 6000) { SetDead(); } }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { base.OnUpdate(); if (LightningState == 2) { WorldObj.PlaySoundEffect(PosX, PosY, PosZ, "ambient.weather.thunder", 10000F, 0.8F + Rand.NextFloat() * 0.2F); WorldObj.PlaySoundEffect(PosX, PosY, PosZ, "random.explode", 2.0F, 0.5F + Rand.NextFloat() * 0.2F); } LightningState--; if (LightningState < 0) { if (BoltLivingTime == 0) { SetDead(); } else if (LightningState < -Rand.Next(10)) { BoltLivingTime--; LightningState = 1; BoltVertex = Rand.Next(); if (WorldObj.DoChunksNearChunkExist(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ), 10)) { int i = MathHelper2.Floor_double(PosX); int j = MathHelper2.Floor_double(PosY); int k = MathHelper2.Floor_double(PosZ); if (WorldObj.GetBlockId(i, j, k) == 0 && Block.Fire.CanPlaceBlockAt(WorldObj, i, j, k)) { WorldObj.SetBlockWithNotify(i, j, k, Block.Fire.BlockID); } } } } if (LightningState >= 0) { float d = 3; List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.GetBoundingBoxFromPool(PosX - d, PosY - d, PosZ - d, PosX + d, PosY + 6 + d, PosZ + d)); for (int l = 0; l < list.Count; l++) { Entity entity = list[l]; entity.OnStruckByLightning(this); } WorldObj.LightningFlash = 2; } }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { if (BlockID == 0) { SetDead(); return; } PrevPosX = PosX; PrevPosY = PosY; PrevPosZ = PosZ; FallTime++; MotionY -= 0.039999999105930328F; MoveEntity(MotionX, MotionY, MotionZ); MotionX *= 0.98000001907348633F; MotionY *= 0.98000001907348633F; MotionZ *= 0.98000001907348633F; int i = MathHelper2.Floor_double(PosX); int j = MathHelper2.Floor_double(PosY); int k = MathHelper2.Floor_double(PosZ); if (FallTime == 1 && WorldObj.GetBlockId(i, j, k) == BlockID) { WorldObj.SetBlockWithNotify(i, j, k, 0); } else if (!WorldObj.IsRemote && FallTime == 1) { SetDead(); } if (OnGround) { MotionX *= 0.69999998807907104F; MotionZ *= 0.69999998807907104F; MotionY *= -0.5F; if (WorldObj.GetBlockId(i, j, k) != Block.PistonMoving.BlockID) { SetDead(); if ((!WorldObj.CanBlockBePlacedAt(BlockID, i, j, k, true, 1) || BlockSand.CanFallBelow(WorldObj, i, j - 1, k) || !WorldObj.SetBlockWithNotify(i, j, k, BlockID)) && !WorldObj.IsRemote) { DropItem(BlockID, 1); } } } else if (FallTime > 100 && !WorldObj.IsRemote && (j < 1 || j > 256) || FallTime > 600) { DropItem(BlockID, 1); SetDead(); } }
/// <summary> /// removes a pistons tile entity (and if the piston is moving, stops it) /// </summary> public virtual void ClearPistonTileEntity() { if (LastProgress < 1.0F && WorldObj != null) { LastProgress = Progress = 1.0F; WorldObj.RemoveBlockTileEntity(XCoord, YCoord, ZCoord); Invalidate(); if (WorldObj.GetBlockId(XCoord, YCoord, ZCoord) == Block.PistonMoving.BlockID) { WorldObj.SetBlockAndMetadataWithNotify(XCoord, YCoord, ZCoord, StoredBlockID, StoredMetadata); } } }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { PrevPosX = PosX; PrevPosY = PosY; PrevPosZ = PosZ; InnerRotation++; DataWatcher.UpdateObject(8, Convert.ToInt32(Health)); int i = MathHelper2.Floor_double(PosX); int j = MathHelper2.Floor_double(PosY); int k = MathHelper2.Floor_double(PosZ); if (WorldObj.GetBlockId(i, j, k) != Block.Fire.BlockID) { WorldObj.SetBlockWithNotify(i, j, k, Block.Fire.BlockID); } }
/// <summary> /// Destroys all blocks that aren't associated with 'The End' inside the given bounding box. /// </summary> private bool DestroyBlocksInAABB(AxisAlignedBB par1AxisAlignedBB) { int i = MathHelper2.Floor_double(par1AxisAlignedBB.MinX); int j = MathHelper2.Floor_double(par1AxisAlignedBB.MinY); int k = MathHelper2.Floor_double(par1AxisAlignedBB.MinZ); int l = MathHelper2.Floor_double(par1AxisAlignedBB.MaxX); int i1 = MathHelper2.Floor_double(par1AxisAlignedBB.MaxY); int j1 = MathHelper2.Floor_double(par1AxisAlignedBB.MaxZ); bool flag = false; bool flag1 = false; for (int k1 = i; k1 <= l; k1++) { for (int l1 = j; l1 <= i1; l1++) { for (int i2 = k; i2 <= j1; i2++) { int j2 = WorldObj.GetBlockId(k1, l1, i2); if (j2 == 0) { continue; } if (j2 == Block.Obsidian.BlockID || j2 == Block.WhiteStone.BlockID || j2 == Block.Bedrock.BlockID) { flag = true; } else { flag1 = true; WorldObj.SetBlockWithNotify(k1, l1, i2, 0); } } } } if (flag1) { double d = par1AxisAlignedBB.MinX + (par1AxisAlignedBB.MaxX - par1AxisAlignedBB.MinX) * (double)Rand.NextFloat(); double d1 = par1AxisAlignedBB.MinY + (par1AxisAlignedBB.MaxY - par1AxisAlignedBB.MinY) * (double)Rand.NextFloat(); double d2 = par1AxisAlignedBB.MinZ + (par1AxisAlignedBB.MaxZ - par1AxisAlignedBB.MinZ) * (double)Rand.NextFloat(); WorldObj.SpawnParticle("largeexplode", d, d1, d2, 0.0F, 0.0F, 0.0F); } return(flag); }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { base.OnUpdate(); if (FishPosRotationIncrements > 0) { float d = PosX + (FishX - PosX) / FishPosRotationIncrements; float d1 = PosY + (FishY - PosY) / FishPosRotationIncrements; float d2 = PosZ + (FishZ - PosZ) / FishPosRotationIncrements; double d4; for (d4 = FishYaw - RotationYaw; d4 < -180D; d4 += 360D) { } for (; d4 >= 180D; d4 -= 360D) { } RotationYaw += (float)d4 / FishPosRotationIncrements; RotationPitch += (float)(FishPitch - RotationPitch) / FishPosRotationIncrements; FishPosRotationIncrements--; SetPosition(d, d1, d2); SetRotation(RotationYaw, RotationPitch); return; } if (!WorldObj.IsRemote) { ItemStack itemstack = Angler.GetCurrentEquippedItem(); if (Angler.IsDead || !Angler.IsEntityAlive() || itemstack == null || itemstack.GetItem() != Item.FishingRod || GetDistanceSqToEntity(Angler) > 1024D) { SetDead(); Angler.FishEntity = null; return; } if (Bobber != null) { if (Bobber.IsDead) { Bobber = null; } else { PosX = Bobber.PosX; PosY = Bobber.BoundingBox.MinY + Bobber.Height * 0.80000000000000004F; PosZ = Bobber.PosZ; return; } } } if (Shake > 0) { Shake--; } if (InGround) { int i = WorldObj.GetBlockId(XTile, YTile, ZTile); if (i != InTile) { InGround = false; MotionX *= Rand.NextFloat() * 0.2F; MotionY *= Rand.NextFloat() * 0.2F; MotionZ *= Rand.NextFloat() * 0.2F; TicksInGround = 0; TicksInAir = 0; } else { TicksInGround++; if (TicksInGround == 1200) { SetDead(); } return; } } else { TicksInAir++; } Vec3D vec3d = Vec3D.CreateVector(PosX, PosY, PosZ); Vec3D vec3d1 = Vec3D.CreateVector(PosX + MotionX, PosY + MotionY, PosZ + MotionZ); MovingObjectPosition movingobjectposition = WorldObj.RayTraceBlocks(vec3d, vec3d1); 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 d3 = 0.0F; for (int j = 0; j < list.Count; j++) { Entity entity1 = list[j]; if (!entity1.CanBeCollidedWith() || entity1 == Angler && TicksInAir < 5) { continue; } float f2 = 0.3F; AxisAlignedBB axisalignedbb = entity1.BoundingBox.Expand(f2, f2, f2); MovingObjectPosition movingobjectposition1 = axisalignedbb.CalculateIntercept(vec3d, vec3d1); if (movingobjectposition1 == null) { continue; } double d6 = vec3d.DistanceTo(movingobjectposition1.HitVec); if (d6 < d3 || d3 == 0.0F) { entity = entity1; d3 = d6; } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null) { if (movingobjectposition.EntityHit != null) { if (movingobjectposition.EntityHit.AttackEntityFrom(DamageSource.CauseThrownDamage(this, Angler), 0)) { Bobber = movingobjectposition.EntityHit; } } else { InGround = true; } } if (InGround) { return; } MoveEntity(MotionX, MotionY, MotionZ); float f = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ); RotationYaw = (float)((Math.Atan2(MotionX, MotionZ) * 180D) / Math.PI); for (RotationPitch = (float)((Math.Atan2(MotionY, f) * 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 f1 = 0.92F; if (OnGround || IsCollidedHorizontally) { f1 = 0.5F; } int k = 5; float d5 = 0.0F; for (int l = 0; l < k; l++) { float d8 = ((BoundingBox.MinY + ((BoundingBox.MaxY - BoundingBox.MinY) * (l + 0)) / k) - 0.125F) + 0.125F; float d9 = ((BoundingBox.MinY + ((BoundingBox.MaxY - BoundingBox.MinY) * (l + 1)) / k) - 0.125F) + 0.125F; AxisAlignedBB axisalignedbb1 = AxisAlignedBB.GetBoundingBoxFromPool(BoundingBox.MinX, d8, BoundingBox.MinZ, BoundingBox.MaxX, d9, BoundingBox.MaxZ); if (WorldObj.IsAABBInMaterial(axisalignedbb1, Material.Water)) { d5 += 1.0F / k; } } if (d5 > 0.0F) { if (TicksCatchable > 0) { TicksCatchable--; } else { int c = 500; if (WorldObj.CanLightningStrikeAt(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY) + 1, MathHelper2.Floor_double(PosZ))) { c = 300; } if (Rand.Next(c) == 0) { TicksCatchable = Rand.Next(30) + 10; MotionY -= 0.20000000298023224F; WorldObj.PlaySoundAtEntity(this, "random.splash", 0.25F, 1.0F + (Rand.NextFloat() - Rand.NextFloat()) * 0.4F); float f3 = MathHelper2.Floor_double(BoundingBox.MinY); for (int i1 = 0; (float)i1 < 1.0F + Width * 20F; i1++) { float f4 = (Rand.NextFloat() * 2.0F - 1.0F) * Width; float f6 = (Rand.NextFloat() * 2.0F - 1.0F) * Width; WorldObj.SpawnParticle("bubble", PosX + f4, f3 + 1.0F, PosZ + f6, MotionX, MotionY - (Rand.NextFloat() * 0.2F), MotionZ); } for (int j1 = 0; (float)j1 < 1.0F + Width * 20F; j1++) { float f5 = (Rand.NextFloat() * 2.0F - 1.0F) * Width; float f7 = (Rand.NextFloat() * 2.0F - 1.0F) * Width; WorldObj.SpawnParticle("splash", PosX + f5, f3 + 1.0F, PosZ + f7, MotionX, MotionY, MotionZ); } } } } if (TicksCatchable > 0) { MotionY -= (Rand.NextFloat() * Rand.NextFloat() * Rand.NextFloat()) * 0.20000000000000001F; } float d7 = d5 * 2F - 1.0F; MotionY += 0.039999999105930328F * d7; if (d5 > 0.0F) { f1 = (float)((double)f1 * 0.90000000000000002D); MotionY *= 0.80000000000000004F; } MotionX *= f1; MotionY *= f1; MotionZ *= f1; SetPosition(PosX, PosY, PosZ); }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { base.OnUpdate(); if (Field_35126_c > 0) { Field_35126_c--; } PrevPosX = PosX; PrevPosY = PosY; PrevPosZ = PosZ; MotionY -= 0.029999999329447746F; if (WorldObj.GetBlockMaterial(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ)) == Material.Lava) { MotionY = 0.20000000298023224F; MotionX = (Rand.NextFloat() - Rand.NextFloat()) * 0.2F; MotionZ = (Rand.NextFloat() - Rand.NextFloat()) * 0.2F; WorldObj.PlaySoundAtEntity(this, "random.fizz", 0.4F, 2.0F + Rand.NextFloat() * 0.4F); } PushOutOfBlocks(PosX, (BoundingBox.MinY + BoundingBox.MaxY) / 2F, PosZ); float d = 8F; EntityPlayer entityplayer = WorldObj.GetClosestPlayerToEntity(this, d); if (entityplayer != null) { float d1 = (entityplayer.PosX - PosX) / d; float d2 = ((entityplayer.PosY + entityplayer.GetEyeHeight()) - PosY) / d; float d3 = (entityplayer.PosZ - PosZ) / d; float d4 = (float)Math.Sqrt(d1 * d1 + d2 * d2 + d3 * d3); float d5 = 1.0F - d4; if (d5 > 0.0F) { d5 *= d5; MotionX += (d1 / d4) * d5 * 0.10000000000000001F; MotionY += (d2 / d4) * d5 * 0.10000000000000001F; MotionZ += (d3 / d4) * d5 * 0.10000000000000001F; } } MoveEntity(MotionX, MotionY, MotionZ); float f = 0.98F; if (OnGround) { f = 0.5880001F; int i = WorldObj.GetBlockId(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(BoundingBox.MinY) - 1, MathHelper2.Floor_double(PosZ)); if (i > 0) { f = Block.BlocksList[i].Slipperiness * 0.98F; } } MotionX *= f; MotionY *= 0.98000001907348633F; MotionZ *= f; if (OnGround) { MotionY *= -0.89999997615814209F; } XpColor++; XpOrbAge++; if (XpOrbAge >= 6000) { SetDead(); } }
/// <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(); }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { LastTickPosX = PosX; LastTickPosY = PosY; LastTickPosZ = PosZ; base.OnUpdate(); if (ThrowableShake > 0) { ThrowableShake--; } if (InGround) { int i = WorldObj.GetBlockId(XTile, YTile, ZTile); if (i != InTile) { InGround = false; MotionX *= Rand.NextFloat() * 0.2F; MotionY *= Rand.NextFloat() * 0.2F; MotionZ *= Rand.NextFloat() * 0.2F; TicksInGround = 0; TicksInAir = 0; } else { TicksInGround++; if (TicksInGround == 1200) { SetDead(); } return; } } else { TicksInAir++; } Vec3D vec3d = Vec3D.CreateVector(PosX, PosY, PosZ); Vec3D vec3d1 = Vec3D.CreateVector(PosX + MotionX, PosY + MotionY, PosZ + MotionZ); MovingObjectPosition movingobjectposition = WorldObj.RayTraceBlocks(vec3d, vec3d1); 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); } if (!WorldObj.IsRemote) { Entity entity = null; List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox.AddCoord(MotionX, MotionY, MotionZ).Expand(1.0F, 1.0F, 1.0F)); float d = 0.0F; for (int k = 0; k < list.Count; k++) { Entity entity1 = list[k]; if (!entity1.CanBeCollidedWith() || entity1 == Thrower && TicksInAir < 5) { continue; } float f4 = 0.3F; AxisAlignedBB axisalignedbb = entity1.BoundingBox.Expand(f4, f4, f4); MovingObjectPosition movingobjectposition1 = axisalignedbb.CalculateIntercept(vec3d, vec3d1); if (movingobjectposition1 == null) { continue; } float d1 = (float)vec3d.DistanceTo(movingobjectposition1.HitVec); if (d1 < d || d == 0.0F) { entity = entity1; d = d1; } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } } if (movingobjectposition != null) { OnImpact(movingobjectposition); } PosX += MotionX; PosY += MotionY; PosZ += MotionZ; float f = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ); RotationYaw = (float)((Math.Atan2(MotionX, MotionZ) * 180D) / Math.PI); for (RotationPitch = (float)((Math.Atan2(MotionY, f) * 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 f1 = 0.99F; float f2 = Func_40075_e(); if (IsInWater()) { for (int j = 0; j < 4; j++) { float f3 = 0.25F; WorldObj.SpawnParticle("bubble", PosX - MotionX * f3, PosY - MotionY * f3, PosZ - MotionZ * f3, MotionX, MotionY, MotionZ); } f1 = 0.8F; } MotionX *= f1; MotionY *= f1; MotionZ *= f1; MotionY -= f2; SetPosition(PosX, PosY, PosZ); }
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> /// Teleport the enderman /// </summary> protected virtual bool TeleportTo(float par1, float par3, float par5) { float d = PosX; float d1 = PosY; float d2 = PosZ; PosX = par1; PosY = par3; PosZ = par5; bool flag = false; int i = MathHelper2.Floor_double(PosX); int j = MathHelper2.Floor_double(PosY); int k = MathHelper2.Floor_double(PosZ); if (WorldObj.BlockExists(i, j, k)) { bool flag1; for (flag1 = false; !flag1 && j > 0;) { int i1 = WorldObj.GetBlockId(i, j - 1, k); if (i1 == 0 || !Block.BlocksList[i1].BlockMaterial.BlocksMovement()) { PosY--; j--; } else { flag1 = true; } } if (flag1) { SetPosition(PosX, PosY, PosZ); if (WorldObj.GetCollidingBoundingBoxes(this, BoundingBox).Count == 0 && !WorldObj.IsAnyLiquid(BoundingBox)) { flag = true; } } } if (!flag) { SetPosition(d, d1, d2); return(false); } int l = 128; for (int j1 = 0; j1 < l; j1++) { double d3 = (double)j1 / ((double)l - 1.0D); float f = (Rand.NextFloat() - 0.5F) * 0.2F; float f1 = (Rand.NextFloat() - 0.5F) * 0.2F; float f2 = (Rand.NextFloat() - 0.5F) * 0.2F; double d4 = d + (PosX - d) * d3 + (Rand.NextDouble() - 0.5D) * (double)Width * 2D; double d5 = d1 + (PosY - d1) * d3 + Rand.NextDouble() * (double)Height; double d6 = d2 + (PosZ - d2) * d3 + (Rand.NextDouble() - 0.5D) * (double)Width * 2D; WorldObj.SpawnParticle("portal", d4, d5, d6, f, f1, f2); } WorldObj.PlaySoundEffect(d, d1, d2, "mob.endermen.portal", 1.0F, 1.0F); WorldObj.PlaySoundAtEntity(this, "mob.endermen.portal", 1.0F, 1.0F); return(true); }
/// <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() { if (!WorldObj.IsRemote && (ShootingEntity != null && ShootingEntity.IsDead || !WorldObj.BlockExists((int)PosX, (int)PosY, (int)PosZ))) { SetDead(); return; } base.OnUpdate(); SetFire(1); if (InGround) { int i = WorldObj.GetBlockId(XTile, YTile, ZTile); if (i != InTile) { InGround = false; MotionX *= Rand.NextFloat() * 0.2F; MotionY *= Rand.NextFloat() * 0.2F; MotionZ *= Rand.NextFloat() * 0.2F; TicksAlive = 0; TicksInAir = 0; } else { TicksAlive++; if (TicksAlive == 600) { SetDead(); } return; } } else { TicksInAir++; } Vec3D vec3d = Vec3D.CreateVector(PosX, PosY, PosZ); Vec3D vec3d1 = Vec3D.CreateVector(PosX + MotionX, PosY + MotionY, PosZ + MotionZ); MovingObjectPosition movingobjectposition = WorldObj.RayTraceBlocks(vec3d, vec3d1); 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 j = 0; j < list.Count; j++) { Entity entity1 = list[j]; if (!entity1.CanBeCollidedWith() || entity1.IsEntityEqual(ShootingEntity) && TicksInAir < 25) { continue; } float f2 = 0.3F; AxisAlignedBB axisalignedbb = entity1.BoundingBox.Expand(f2, f2, f2); MovingObjectPosition movingobjectposition1 = axisalignedbb.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) { Func_40071_a(movingobjectposition); } PosX += MotionX; PosY += MotionY; PosZ += MotionZ; float f = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ); RotationYaw = (float)((Math.Atan2(MotionX, MotionZ) * 180D) / Math.PI); for (RotationPitch = (float)((Math.Atan2(MotionY, f) * 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 f1 = 0.95F; if (IsInWater()) { for (int k = 0; k < 4; k++) { float f3 = 0.25F; WorldObj.SpawnParticle("bubble", PosX - MotionX * (double)f3, PosY - MotionY * (double)f3, PosZ - MotionZ * (double)f3, MotionX, MotionY, MotionZ); } f1 = 0.8F; } MotionX += AccelerationX; MotionY += AccelerationY; MotionZ += AccelerationZ; MotionX *= f1; MotionY *= f1; MotionZ *= f1; WorldObj.SpawnParticle("smoke", PosX, PosY + 0.5D, PosZ, 0.0F, 0.0F, 0.0F); SetPosition(PosX, PosY, PosZ); }
/// <summary> /// Called to update the entity's position/logic. /// </summary> public override void OnUpdate() { base.OnUpdate(); if (GetTimeSinceHit() > 0) { SetTimeSinceHit(GetTimeSinceHit() - 1); } if (GetDamageTaken() > 0) { SetDamageTaken(GetDamageTaken() - 1); } PrevPosX = PosX; PrevPosY = PosY; PrevPosZ = PosZ; int i = 5; float d = 0.0F; for (int j = 0; j < i; j++) { float d2 = (BoundingBox.MinY + ((BoundingBox.MaxY - BoundingBox.MinY) * (j + 0)) / i) - 0.125F; float d8 = (BoundingBox.MinY + ((BoundingBox.MaxY - BoundingBox.MinY) * (j + 1)) / i) - 0.125F; AxisAlignedBB axisalignedbb = AxisAlignedBB.GetBoundingBoxFromPool(BoundingBox.MinX, d2, BoundingBox.MinZ, BoundingBox.MaxX, d8, BoundingBox.MaxZ); if (WorldObj.IsAABBInMaterial(axisalignedbb, Material.Water)) { d += 1.0F / i; } } double d1 = Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ); if (d1 > 0.14999999999999999D) { double d3 = Math.Cos(((double)RotationYaw * Math.PI) / 180D); double d9 = Math.Sin(((double)RotationYaw * Math.PI) / 180D); for (int i1 = 0; (double)i1 < 1.0D + d1 * 60D; i1++) { double d16 = Rand.NextFloat() * 2.0F - 1.0F; double d19 = (double)(Rand.Next(2) * 2 - 1) * 0.69999999999999996D; if (Rand.NextBool()) { double d21 = (PosX - d3 * d16 * 0.80000000000000004D) + d9 * d19; double d23 = PosZ - d9 * d16 * 0.80000000000000004D - d3 * d19; WorldObj.SpawnParticle("splash", d21, PosY - 0.125D, d23, MotionX, MotionY, MotionZ); } else { double d22 = PosX + d3 + d9 * d16 * 0.69999999999999996D; double d24 = (PosZ + d9) - d3 * d16 * 0.69999999999999996D; WorldObj.SpawnParticle("splash", d22, PosY - 0.125D, d24, MotionX, MotionY, MotionZ); } } } if (WorldObj.IsRemote) { if (BoatPosRotationIncrements > 0) { float d4 = PosX + (BoatX - PosX) / BoatPosRotationIncrements; float d10 = PosY + (BoatY - PosY) / BoatPosRotationIncrements; float d13 = PosZ + (BoatZ - PosZ) / BoatPosRotationIncrements; double d17; for (d17 = BoatYaw - (double)RotationYaw; d17 < -180D; d17 += 360D) { } for (; d17 >= 180D; d17 -= 360D) { } RotationYaw += (float)d17 / BoatPosRotationIncrements; RotationPitch += ((float)BoatPitch - RotationPitch) / BoatPosRotationIncrements; BoatPosRotationIncrements--; SetPosition(d4, d10, d13); SetRotation(RotationYaw, RotationPitch); } else { float d5 = PosX + MotionX; float d11 = PosY + MotionY; float d14 = PosZ + MotionZ; SetPosition(d5, d11, d14); if (OnGround) { MotionX *= 0.5F; MotionY *= 0.5F; MotionZ *= 0.5F; } MotionX *= 0.99000000953674316F; MotionY *= 0.94999998807907104F; MotionZ *= 0.99000000953674316F; } return; } if (d < 1.0F) { float d6 = d * 2F - 1.0F; MotionY += 0.039999999105930328F * d6; } else { if (MotionY < 0.0F) { MotionY /= 2F; } MotionY += 0.0070000002160668373F; } if (RiddenByEntity != null) { MotionX += RiddenByEntity.MotionX * 0.20000000000000001F; MotionZ += RiddenByEntity.MotionZ * 0.20000000000000001F; } float d7 = 0.40000000000000002F; if (MotionX < -d7) { MotionX = -d7; } if (MotionX > d7) { MotionX = d7; } if (MotionZ < -d7) { MotionZ = -d7; } if (MotionZ > d7) { MotionZ = d7; } if (OnGround) { MotionX *= 0.5F; MotionY *= 0.5F; MotionZ *= 0.5F; } MoveEntity(MotionX, MotionY, MotionZ); if (IsCollidedHorizontally && d1 > 0.20000000000000001F) { if (!WorldObj.IsRemote) { SetDead(); for (int k = 0; k < 3; k++) { DropItemWithOffset(Block.Planks.BlockID, 1, 0.0F); } for (int l = 0; l < 2; l++) { DropItemWithOffset(Item.Stick.ShiftedIndex, 1, 0.0F); } } } else { MotionX *= 0.99000000953674316F; MotionY *= 0.94999998807907104F; MotionZ *= 0.99000000953674316F; } RotationPitch = 0.0F; double d12 = RotationYaw; double d15 = PrevPosX - PosX; double d18 = PrevPosZ - PosZ; if (d15 * d15 + d18 * d18 > 0.001D) { d12 = (float)((Math.Atan2(d18, d15) * 180D) / Math.PI); } double d20; for (d20 = d12 - (double)RotationYaw; d20 >= 180D; d20 -= 360D) { } for (; d20 < -180D; d20 += 360D) { } if (d20 > 20D) { d20 = 20D; } if (d20 < -20D) { d20 = -20D; } RotationYaw += (float)d20; 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 = (Entity)list[j1]; if (entity != RiddenByEntity && entity.CanBePushed() && (entity is EntityBoat)) { entity.ApplyEntityCollision(this); } } } for (int k1 = 0; k1 < 4; k1++) { int l1 = MathHelper2.Floor_double(PosX + ((double)(k1 % 2) - 0.5D) * 0.80000000000000004D); int i2 = MathHelper2.Floor_double(PosY); int j2 = MathHelper2.Floor_double(PosZ + ((double)(k1 / 2) - 0.5D) * 0.80000000000000004D); if (WorldObj.GetBlockId(l1, i2, j2) == Block.Snow.BlockID) { WorldObj.SetBlockWithNotify(l1, i2, j2, 0); } } if (RiddenByEntity != null && RiddenByEntity.IsDead) { RiddenByEntity = null; } }
/// <summary> /// Moves the entity based on the specified heading. Args: strafe, forward /// </summary> public override void MoveEntityWithHeading(float par1, float par2) { if (IsInWater()) { MoveFlying(par1, par2, 0.02F); MoveEntity(MotionX, MotionY, MotionZ); MotionX *= 0.80000001192092896F; MotionY *= 0.80000001192092896F; MotionZ *= 0.80000001192092896F; } else if (HandleLavaMovement()) { MoveFlying(par1, par2, 0.02F); MoveEntity(MotionX, MotionY, MotionZ); MotionX *= 0.5F; MotionY *= 0.5F; MotionZ *= 0.5F; } else { float f = 0.91F; if (OnGround) { f = 0.5460001F; int i = WorldObj.GetBlockId(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(BoundingBox.MinY) - 1, MathHelper2.Floor_double(PosZ)); if (i > 0) { f = Block.BlocksList[i].Slipperiness * 0.91F; } } float f1 = 0.1627714F / (f * f * f); MoveFlying(par1, par2, OnGround ? 0.1F * f1 : 0.02F); f = 0.91F; if (OnGround) { f = 0.5460001F; int j = WorldObj.GetBlockId(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(BoundingBox.MinY) - 1, MathHelper2.Floor_double(PosZ)); if (j > 0) { f = Block.BlocksList[j].Slipperiness * 0.91F; } } MoveEntity(MotionX, MotionY, MotionZ); MotionX *= f; MotionY *= f; MotionZ *= f; } Field_705_Q = Field_704_R; double d = PosX - PrevPosX; double d1 = PosZ - PrevPosZ; float f2 = MathHelper2.Sqrt_double(d * d + d1 * d1) * 4F; if (f2 > 1.0F) { f2 = 1.0F; } Field_704_R += (f2 - Field_704_R) * 0.4F; Field_703_S += Field_704_R; }
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); }