/** Called to update the entity's position/logic. */ public void onUpdate() { if (this.field_82344_g != null) { this.field_82344_g.update(); } if (this.func_70496_j() > 0) { this.func_70497_h(this.func_70496_j() - 1); } if (this.getDamage() > 0) { this.setDamage(this.getDamage() - 1); } if (this.posY < -64.0D) { this.kill(); } if (this.isMinecartPowered() && this.rand.nextInt(4) == 0) { this.worldObj.spawnParticle( "largesmoke", this.posX, this.posY + 0.8D, this.posZ, 0.0D, 0.0D, 0.0D); } int var2; if (!this.worldObj.isRemote && this.worldObj instanceof WorldServer) { this.worldObj.theProfiler.startSection("portal"); MinecraftServer var1 = ((WorldServer) this.worldObj).getMinecraftServer(); var2 = this.getMaxInPortalTime(); if (this.inPortal) { if (var1.getAllowNether()) { if (this.ridingEntity == null && this.field_82153_h++ >= var2) { this.field_82153_h = var2; this.timeUntilPortal = this.getPortalCooldown(); byte var3; if (this.worldObj.provider.dimensionId == -1) { var3 = 0; } else { var3 = -1; } this.travelToDimension(var3); } this.inPortal = false; } } else { if (this.field_82153_h > 0) { this.field_82153_h -= 4; } if (this.field_82153_h < 0) { this.field_82153_h = 0; } } if (this.timeUntilPortal > 0) { --this.timeUntilPortal; } this.worldObj.theProfiler.endSection(); } if (this.worldObj.isRemote) { if (this.turnProgress > 0) { double var46 = this.posX + (this.minecartX - this.posX) / (double) this.turnProgress; double var48 = this.posY + (this.minecartY - this.posY) / (double) this.turnProgress; double var5 = this.posZ + (this.minecartZ - this.posZ) / (double) this.turnProgress; double var7 = MathHelper.wrapAngleTo180_double(this.minecartYaw - (double) this.rotationYaw); this.rotationYaw = (float) ((double) this.rotationYaw + var7 / (double) this.turnProgress); this.rotationPitch = (float) ((double) this.rotationPitch + (this.minecartPitch - (double) this.rotationPitch) / (double) this.turnProgress); --this.turnProgress; this.setPosition(var46, var48, var5); this.setRotation(this.rotationYaw, this.rotationPitch); } else { this.setPosition(this.posX, this.posY, this.posZ); this.setRotation(this.rotationYaw, this.rotationPitch); } } else { this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; this.motionY -= 0.03999999910593033D; int var45 = MathHelper.floor_double(this.posX); var2 = MathHelper.floor_double(this.posY); int var47 = MathHelper.floor_double(this.posZ); if (BlockRail.isRailBlockAt(this.worldObj, var45, var2 - 1, var47)) { --var2; } double var4 = 0.4D; double var6 = 0.0078125D; int var8 = this.worldObj.getBlockId(var45, var2, var47); if (BlockRail.isRailBlock(var8)) { this.fallDistance = 0.0F; Vec3 var9 = this.func_70489_a(this.posX, this.posY, this.posZ); int var10 = this.worldObj.getBlockMetadata(var45, var2, var47); this.posY = (double) var2; boolean var11 = false; boolean var12 = false; if (var8 == Block.railPowered.blockID) { var11 = (var10 & 8) != 0; var12 = !var11; } if (((BlockRail) Block.blocksList[var8]).isPowered()) { var10 &= 7; } if (var10 >= 2 && var10 <= 5) { this.posY = (double) (var2 + 1); } if (var10 == 2) { this.motionX -= var6; } if (var10 == 3) { this.motionX += var6; } if (var10 == 4) { this.motionZ += var6; } if (var10 == 5) { this.motionZ -= var6; } int[][] var13 = field_70500_g[var10]; double var14 = (double) (var13[1][0] - var13[0][0]); double var16 = (double) (var13[1][2] - var13[0][2]); double var18 = Math.sqrt(var14 * var14 + var16 * var16); double var20 = this.motionX * var14 + this.motionZ * var16; if (var20 < 0.0D) { var14 = -var14; var16 = -var16; } double var22 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); this.motionX = var22 * var14 / var18; this.motionZ = var22 * var16 / var18; double var24; double var26; if (this.riddenByEntity != null) { var24 = this.riddenByEntity.motionX * this.riddenByEntity.motionX + this.riddenByEntity.motionZ * this.riddenByEntity.motionZ; var26 = this.motionX * this.motionX + this.motionZ * this.motionZ; if (var24 > 1.0E-4D && var26 < 0.01D) { this.motionX += this.riddenByEntity.motionX * 0.1D; this.motionZ += this.riddenByEntity.motionZ * 0.1D; var12 = false; } } if (var12) { var24 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); if (var24 < 0.03D) { this.motionX *= 0.0D; this.motionY *= 0.0D; this.motionZ *= 0.0D; } else { this.motionX *= 0.5D; this.motionY *= 0.0D; this.motionZ *= 0.5D; } } var24 = 0.0D; var26 = (double) var45 + 0.5D + (double) var13[0][0] * 0.5D; double var28 = (double) var47 + 0.5D + (double) var13[0][2] * 0.5D; double var30 = (double) var45 + 0.5D + (double) var13[1][0] * 0.5D; double var32 = (double) var47 + 0.5D + (double) var13[1][2] * 0.5D; var14 = var30 - var26; var16 = var32 - var28; double var34; double var36; if (var14 == 0.0D) { this.posX = (double) var45 + 0.5D; var24 = this.posZ - (double) var47; } else if (var16 == 0.0D) { this.posZ = (double) var47 + 0.5D; var24 = this.posX - (double) var45; } else { var34 = this.posX - var26; var36 = this.posZ - var28; var24 = (var34 * var14 + var36 * var16) * 2.0D; } this.posX = var26 + var14 * var24; this.posZ = var28 + var16 * var24; this.setPosition(this.posX, this.posY + (double) this.yOffset, this.posZ); var34 = this.motionX; var36 = this.motionZ; if (this.riddenByEntity != null) { var34 *= 0.75D; var36 *= 0.75D; } if (var34 < -var4) { var34 = -var4; } if (var34 > var4) { var34 = var4; } if (var36 < -var4) { var36 = -var4; } if (var36 > var4) { var36 = var4; } this.moveEntity(var34, 0.0D, var36); if (var13[0][1] != 0 && MathHelper.floor_double(this.posX) - var45 == var13[0][0] && MathHelper.floor_double(this.posZ) - var47 == var13[0][2]) { this.setPosition(this.posX, this.posY + (double) var13[0][1], this.posZ); } else if (var13[1][1] != 0 && MathHelper.floor_double(this.posX) - var45 == var13[1][0] && MathHelper.floor_double(this.posZ) - var47 == var13[1][2]) { this.setPosition(this.posX, this.posY + (double) var13[1][1], this.posZ); } if (this.riddenByEntity != null) { this.motionX *= 0.996999979019165D; this.motionY *= 0.0D; this.motionZ *= 0.996999979019165D; } else { if (this.minecartType == 2) { double var38 = this.pushX * this.pushX + this.pushZ * this.pushZ; if (var38 > 1.0E-4D) { var38 = (double) MathHelper.sqrt_double(var38); this.pushX /= var38; this.pushZ /= var38; double var40 = 0.04D; this.motionX *= 0.800000011920929D; this.motionY *= 0.0D; this.motionZ *= 0.800000011920929D; this.motionX += this.pushX * var40; this.motionZ += this.pushZ * var40; } else { this.motionX *= 0.8999999761581421D; this.motionY *= 0.0D; this.motionZ *= 0.8999999761581421D; } } this.motionX *= 0.9599999785423279D; this.motionY *= 0.0D; this.motionZ *= 0.9599999785423279D; } Vec3 var54 = this.func_70489_a(this.posX, this.posY, this.posZ); if (var54 != null && var9 != null) { double var39 = (var9.yCoord - var54.yCoord) * 0.05D; var22 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); if (var22 > 0.0D) { this.motionX = this.motionX / var22 * (var22 + var39); this.motionZ = this.motionZ / var22 * (var22 + var39); } this.setPosition(this.posX, var54.yCoord, this.posZ); } int var53 = MathHelper.floor_double(this.posX); int var55 = MathHelper.floor_double(this.posZ); if (var53 != var45 || var55 != var47) { var22 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); this.motionX = var22 * (double) (var53 - var45); this.motionZ = var22 * (double) (var55 - var47); } double var41; if (this.minecartType == 2) { var41 = this.pushX * this.pushX + this.pushZ * this.pushZ; if (var41 > 1.0E-4D && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.001D) { var41 = (double) MathHelper.sqrt_double(var41); this.pushX /= var41; this.pushZ /= var41; if (this.pushX * this.motionX + this.pushZ * this.motionZ < 0.0D) { this.pushX = 0.0D; this.pushZ = 0.0D; } else { this.pushX = this.motionX; this.pushZ = this.motionZ; } } } if (var11) { var41 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); if (var41 > 0.01D) { double var43 = 0.06D; this.motionX += this.motionX / var41 * var43; this.motionZ += this.motionZ / var41 * var43; } else if (var10 == 1) { if (this.worldObj.isBlockNormalCube(var45 - 1, var2, var47)) { this.motionX = 0.02D; } else if (this.worldObj.isBlockNormalCube(var45 + 1, var2, var47)) { this.motionX = -0.02D; } } else if (var10 == 0) { if (this.worldObj.isBlockNormalCube(var45, var2, var47 - 1)) { this.motionZ = 0.02D; } else if (this.worldObj.isBlockNormalCube(var45, var2, var47 + 1)) { this.motionZ = -0.02D; } } } } else { if (this.motionX < -var4) { this.motionX = -var4; } if (this.motionX > var4) { this.motionX = var4; } if (this.motionZ < -var4) { this.motionZ = -var4; } if (this.motionZ > var4) { this.motionZ = var4; } if (this.onGround) { this.motionX *= 0.5D; this.motionY *= 0.5D; this.motionZ *= 0.5D; } this.moveEntity(this.motionX, this.motionY, this.motionZ); if (!this.onGround) { this.motionX *= 0.949999988079071D; this.motionY *= 0.949999988079071D; this.motionZ *= 0.949999988079071D; } } this.doBlockCollisions(); this.rotationPitch = 0.0F; double var49 = this.prevPosX - this.posX; double var50 = this.prevPosZ - this.posZ; if (var49 * var49 + var50 * var50 > 0.001D) { this.rotationYaw = (float) (Math.atan2(var50, var49) * 180.0D / Math.PI); if (this.field_70499_f) { this.rotationYaw += 180.0F; } } double var51 = (double) MathHelper.wrapAngleTo180_float(this.rotationYaw - this.prevRotationYaw); if (var51 < -170.0D || var51 >= 170.0D) { this.rotationYaw += 180.0F; this.field_70499_f = !this.field_70499_f; } this.setRotation(this.rotationYaw, this.rotationPitch); List var15 = this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D)); if (var15 != null && !var15.isEmpty()) { for (int var52 = 0; var52 < var15.size(); ++var52) { Entity var17 = (Entity) var15.get(var52); if (var17 != this.riddenByEntity && var17.canBePushed() && var17 instanceof EntityMinecart) { var17.applyEntityCollision(this); } } } if (this.riddenByEntity != null && this.riddenByEntity.isDead) { if (this.riddenByEntity.ridingEntity == this) { this.riddenByEntity.ridingEntity = null; } this.riddenByEntity = null; } if (this.fuel > 0) { --this.fuel; } if (this.fuel <= 0) { this.pushX = this.pushZ = 0.0D; } this.setMinecartPowered(this.fuel > 0); } }
/** * 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. */ public void onLivingUpdate() { float var1; float var2; if (this.worldObj.isRemote) { var1 = MathHelper.cos(this.animTime * (float) Math.PI * 2.0F); var2 = MathHelper.cos(this.prevAnimTime * (float) Math.PI * 2.0F); if (var2 <= -0.3F && var1 >= -0.3F) { this.worldObj.playSound( this.posX, this.posY, this.posZ, "mob.enderdragon.wings", 5.0F, 0.8F + this.rand.nextFloat() * 0.3F, false); } } this.prevAnimTime = this.animTime; float var3; if (this.func_110143_aJ() <= 0.0F) { var1 = (this.rand.nextFloat() - 0.5F) * 8.0F; var2 = (this.rand.nextFloat() - 0.5F) * 4.0F; var3 = (this.rand.nextFloat() - 0.5F) * 8.0F; this.worldObj.spawnParticle( "largeexplode", this.posX + (double) var1, this.posY + 2.0D + (double) var2, this.posZ + (double) var3, 0.0D, 0.0D, 0.0D); } else { this.updateDragonEnderCrystal(); var1 = 0.2F / (MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 10.0F + 1.0F); var1 *= (float) Math.pow(2.0D, this.motionY); if (this.slowed) { this.animTime += var1 * 0.5F; } else { this.animTime += var1; } this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw); if (this.ringBufferIndex < 0) { for (int var25 = 0; var25 < this.ringBuffer.length; ++var25) { this.ringBuffer[var25][0] = (double) this.rotationYaw; this.ringBuffer[var25][1] = this.posY; } } if (++this.ringBufferIndex == this.ringBuffer.length) { this.ringBufferIndex = 0; } this.ringBuffer[this.ringBufferIndex][0] = (double) this.rotationYaw; this.ringBuffer[this.ringBufferIndex][1] = this.posY; double var4; double var6; double var8; double var26; float var33; if (this.worldObj.isRemote) { if (this.newPosRotationIncrements > 0) { var26 = this.posX + (this.newPosX - this.posX) / (double) this.newPosRotationIncrements; var4 = this.posY + (this.newPosY - this.posY) / (double) this.newPosRotationIncrements; var6 = this.posZ + (this.field_110152_bk - this.posZ) / (double) this.newPosRotationIncrements; var8 = MathHelper.wrapAngleTo180_double(this.newRotationYaw - (double) this.rotationYaw); this.rotationYaw = (float) ((double) this.rotationYaw + var8 / (double) this.newPosRotationIncrements); this.rotationPitch = (float) ((double) this.rotationPitch + (this.newRotationPitch - (double) this.rotationPitch) / (double) this.newPosRotationIncrements); --this.newPosRotationIncrements; this.setPosition(var26, var4, var6); this.setRotation(this.rotationYaw, this.rotationPitch); } } else { var26 = this.targetX - this.posX; var4 = this.targetY - this.posY; var6 = this.targetZ - this.posZ; var8 = var26 * var26 + var4 * var4 + var6 * var6; if (this.target != null) { this.targetX = this.target.posX; this.targetZ = this.target.posZ; double var10 = this.targetX - this.posX; double var12 = this.targetZ - this.posZ; double var14 = Math.sqrt(var10 * var10 + var12 * var12); double var16 = 0.4000000059604645D + var14 / 80.0D - 1.0D; if (var16 > 10.0D) { var16 = 10.0D; } this.targetY = this.target.boundingBox.minY + var16; } else { this.targetX += this.rand.nextGaussian() * 2.0D; this.targetZ += this.rand.nextGaussian() * 2.0D; } if (this.forceNewTarget || var8 < 100.0D || var8 > 22500.0D || this.isCollidedHorizontally || this.isCollidedVertically) { this.setNewTarget(); } var4 /= (double) MathHelper.sqrt_double(var26 * var26 + var6 * var6); var33 = 0.6F; if (var4 < (double) (-var33)) { var4 = (double) (-var33); } if (var4 > (double) var33) { var4 = (double) var33; } this.motionY += var4 * 0.10000000149011612D; this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw); double var11 = 180.0D - Math.atan2(var26, var6) * 180.0D / Math.PI; double var13 = MathHelper.wrapAngleTo180_double(var11 - (double) this.rotationYaw); if (var13 > 50.0D) { var13 = 50.0D; } if (var13 < -50.0D) { var13 = -50.0D; } Vec3 var15 = this.worldObj .getWorldVec3Pool() .getVecFromPool( this.targetX - this.posX, this.targetY - this.posY, this.targetZ - this.posZ) .normalize(); Vec3 var40 = this.worldObj .getWorldVec3Pool() .getVecFromPool( (double) MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F), this.motionY, (double) (-MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F))) .normalize(); float var17 = (float) (var40.dotProduct(var15) + 0.5D) / 1.5F; if (var17 < 0.0F) { var17 = 0.0F; } this.randomYawVelocity *= 0.8F; float var18 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0F + 1.0F; double var19 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0D + 1.0D; if (var19 > 40.0D) { var19 = 40.0D; } this.randomYawVelocity = (float) ((double) this.randomYawVelocity + var13 * (0.699999988079071D / var19 / (double) var18)); this.rotationYaw += this.randomYawVelocity * 0.1F; float var21 = (float) (2.0D / (var19 + 1.0D)); float var22 = 0.06F; this.moveFlying(0.0F, -1.0F, var22 * (var17 * var21 + (1.0F - var21))); if (this.slowed) { this.moveEntity( this.motionX * 0.800000011920929D, this.motionY * 0.800000011920929D, this.motionZ * 0.800000011920929D); } else { this.moveEntity(this.motionX, this.motionY, this.motionZ); } Vec3 var23 = this.worldObj .getWorldVec3Pool() .getVecFromPool(this.motionX, this.motionY, this.motionZ) .normalize(); float var24 = (float) (var23.dotProduct(var40) + 1.0D) / 2.0F; var24 = 0.8F + 0.15F * var24; this.motionX *= (double) var24; this.motionZ *= (double) var24; this.motionY *= 0.9100000262260437D; } this.renderYawOffset = this.rotationYaw; this.dragonPartHead.width = this.dragonPartHead.height = 3.0F; this.dragonPartTail1.width = this.dragonPartTail1.height = 2.0F; this.dragonPartTail2.width = this.dragonPartTail2.height = 2.0F; this.dragonPartTail3.width = this.dragonPartTail3.height = 2.0F; this.dragonPartBody.height = 3.0F; this.dragonPartBody.width = 5.0F; this.dragonPartWing1.height = 2.0F; this.dragonPartWing1.width = 4.0F; this.dragonPartWing2.height = 3.0F; this.dragonPartWing2.width = 4.0F; var2 = (float) (this.getMovementOffsets(5, 1.0F)[1] - this.getMovementOffsets(10, 1.0F)[1]) * 10.0F / 180.0F * (float) Math.PI; var3 = MathHelper.cos(var2); float var28 = -MathHelper.sin(var2); float var5 = this.rotationYaw * (float) Math.PI / 180.0F; float var27 = MathHelper.sin(var5); float var7 = MathHelper.cos(var5); this.dragonPartBody.onUpdate(); this.dragonPartBody.setLocationAndAngles( this.posX + (double) (var27 * 0.5F), this.posY, this.posZ - (double) (var7 * 0.5F), 0.0F, 0.0F); this.dragonPartWing1.onUpdate(); this.dragonPartWing1.setLocationAndAngles( this.posX + (double) (var7 * 4.5F), this.posY + 2.0D, this.posZ + (double) (var27 * 4.5F), 0.0F, 0.0F); this.dragonPartWing2.onUpdate(); this.dragonPartWing2.setLocationAndAngles( this.posX - (double) (var7 * 4.5F), this.posY + 2.0D, this.posZ - (double) (var27 * 4.5F), 0.0F, 0.0F); if (!this.worldObj.isRemote && this.hurtTime == 0) { this.collideWithEntities( this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.dragonPartWing1 .boundingBox .expand(4.0D, 2.0D, 4.0D) .offset(0.0D, -2.0D, 0.0D))); this.collideWithEntities( this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.dragonPartWing2 .boundingBox .expand(4.0D, 2.0D, 4.0D) .offset(0.0D, -2.0D, 0.0D))); this.attackEntitiesInList( this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.dragonPartHead.boundingBox.expand(1.0D, 1.0D, 1.0D))); } double[] var29 = this.getMovementOffsets(5, 1.0F); double[] var9 = this.getMovementOffsets(0, 1.0F); var33 = MathHelper.sin( this.rotationYaw * (float) Math.PI / 180.0F - this.randomYawVelocity * 0.01F); float var32 = MathHelper.cos( this.rotationYaw * (float) Math.PI / 180.0F - this.randomYawVelocity * 0.01F); this.dragonPartHead.onUpdate(); this.dragonPartHead.setLocationAndAngles( this.posX + (double) (var33 * 5.5F * var3), this.posY + (var9[1] - var29[1]) * 1.0D + (double) (var28 * 5.5F), this.posZ - (double) (var32 * 5.5F * var3), 0.0F, 0.0F); for (int var30 = 0; var30 < 3; ++var30) { EntityDragonPart var31 = null; if (var30 == 0) { var31 = this.dragonPartTail1; } if (var30 == 1) { var31 = this.dragonPartTail2; } if (var30 == 2) { var31 = this.dragonPartTail3; } double[] var35 = this.getMovementOffsets(12 + var30 * 2, 1.0F); float var34 = this.rotationYaw * (float) Math.PI / 180.0F + this.simplifyAngle(var35[0] - var29[0]) * (float) Math.PI / 180.0F * 1.0F; float var38 = MathHelper.sin(var34); float var37 = MathHelper.cos(var34); float var36 = 1.5F; float var39 = (float) (var30 + 1) * 2.0F; var31.onUpdate(); var31.setLocationAndAngles( this.posX - (double) ((var27 * var36 + var38 * var39) * var3), this.posY + (var35[1] - var29[1]) * 1.0D - (double) ((var39 + var36) * var28) + 1.5D, this.posZ + (double) ((var7 * var36 + var37 * var39) * var3), 0.0F, 0.0F); } if (!this.worldObj.isRemote) { this.slowed = this.destroyBlocksInAABB(this.dragonPartHead.boundingBox) | this.destroyBlocksInAABB(this.dragonPartBody.boundingBox); } } }