@Override public void onUpdate() { super.onUpdate(); if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); prevRotationYaw = rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D); prevRotationPitch = rotationPitch = (float) ((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D); } if (arrowShake > 0) { arrowShake--; } if (inGround) { int i = worldObj.getBlockId(xTile, yTile, zTile); int j = worldObj.getBlockMetadata(xTile, yTile, zTile); if (i != inTile || j != inData) { inGround = false; motionX *= rand.nextFloat() * 0.2F; motionY *= rand.nextFloat() * 0.2F; motionZ *= rand.nextFloat() * 0.2F; ticksInGround = 0; ticksFlying = 0; } else { ticksInGround++; tickInGround(); if (ticksInGround == ttlInGround) { setDead(); } return; } } else { ticksFlying++; } tickFlying(); Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ); Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ); MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1); vec3d = Vec3.createVectorHelper(posX, posY, posZ); vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ); if (movingobjectposition != null) { vec3d1 = Vec3.createVectorHelper( movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List list = worldObj.getEntitiesWithinAABBExcludingEntity( this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); double d = 0.0D; for (int k = 0; k < list.size(); k++) { Entity entity2 = (Entity) list.get(k); if (!canBeShot(entity2)) { continue; } float f3 = hitBox; AxisAlignedBB axisalignedbb = entity2.boundingBox.expand(f3, f3, f3); MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1); if (movingobjectposition1 == null) { continue; } double d1 = vec3d.distanceTo(movingobjectposition1.hitVec); if (d1 < d || d == 0.0D) { entity = entity2; d = d1; } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null && (entity != shooter || ticksFlying > 2) && (onHit())) { Entity entity1 = movingobjectposition.entityHit; if (entity1 != null) { if (!worldObj.isRemote) { if (onHitTarget(entity1) && hasTorchAttachment == false) { if ((entity1 instanceof EntityLiving) && !(entity1 instanceof EntityPlayer)) { ++((EntityLiving) entity1).arrowHitTempCounter; } entity1.attackEntityFrom( DamageSource.causePlayerDamage((EntityPlayer) shooter), this.arrowCritical ? dmg * 2 : dmg); setDead(); } } } else { xTile = movingobjectposition.blockX; yTile = movingobjectposition.blockY; zTile = movingobjectposition.blockZ; inTile = worldObj.getBlockId(xTile, yTile, zTile); inData = worldObj.getBlockMetadata(xTile, yTile, zTile); Block block = Block.blocksList[inTile]; if (block != null && !(block instanceof BlockFlower)) { if (onHitBlock(movingobjectposition)) { motionX = (float) (movingobjectposition.hitVec.xCoord - posX); motionY = (float) (movingobjectposition.hitVec.yCoord - posY); motionZ = (float) (movingobjectposition.hitVec.zCoord - posZ); float f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); posX -= (motionX / (double) f2) * 0.05000000074505806D; posY -= (motionY / (double) f2) * 0.05000000074505806D; posZ -= (motionZ / (double) f2) * 0.05000000074505806D; inGround = true; arrowShake = 7; this.arrowCritical = false; } } } } if (movingobjectposition != null && !worldObj.isRemote) { Entity entity1 = movingobjectposition.entityHit; if (entity1 != null && entity1 instanceof EntityLiving && entity1 != shooter) { if (hasExplosiveAttachment && ((EntityLiving) entity1).arrowHitTempCounter < 10) { this.worldObj.createExplosion( this, (int) Math.floor(((EntityLiving) entity1).posX), (int) ((EntityLiving) entity1).posY, (int) Math.floor(((EntityLiving) entity1).posZ), 1); } if (hasIceAttachment) { ((EntityLiving) entity1) .addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 280, 3)); } if (hasPoisonAttachment) { ((EntityLiving) entity1).addPotionEffect(new PotionEffect(Potion.poison.id, 280, 3)); } if (hasLightningAttachment) { this.worldObj.addWeatherEffect( new EntityLightningBolt(this.worldObj, entity1.posX, entity1.posY, entity1.posZ)); this.setDead(); } } } FMLLog.info("" + this.inGround); posX += motionX; posZ += motionZ; posY += motionY; handleMotionUpdate(); float f1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D); for (rotationPitch = (float) ((Math.atan2(motionY, f1) * 180D) / 3.1415927410125732D); 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; setPosition(posX, posY, posZ); }
/** Called to update the entity's position/logic. */ public void onUpdate() { if (!this.worldObj.isRemote && (this.shootingEntity != null && this.shootingEntity.isDead || !this.worldObj.blockExists((int) this.posX, (int) this.posY, (int) this.posZ))) { this.setDead(); } else { super.onUpdate(); this.setFire(1); if (this.inGround) { int var1 = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); if (var1 == this.inTile) { ++this.ticksAlive; if (this.ticksAlive == 600) { this.setDead(); } return; } this.inGround = false; this.motionX *= (double) (this.rand.nextFloat() * 0.2F); this.motionY *= (double) (this.rand.nextFloat() * 0.2F); this.motionZ *= (double) (this.rand.nextFloat() * 0.2F); this.ticksAlive = 0; this.ticksInAir = 0; } else { ++this.ticksInAir; } Vec3 var15 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ); Vec3 var2 = this.worldObj .getWorldVec3Pool() .getVecFromPool( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition var3 = this.worldObj.rayTraceBlocks(var15, var2); var15 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ); var2 = this.worldObj .getWorldVec3Pool() .getVecFromPool( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (var3 != null) { var2 = this.worldObj .getWorldVec3Pool() .getVecFromPool(var3.hitVec.xCoord, var3.hitVec.yCoord, var3.hitVec.zCoord); } Entity var4 = null; List var5 = this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.boundingBox .addCoord(this.motionX, this.motionY, this.motionZ) .expand(1.0D, 1.0D, 1.0D)); double var6 = 0.0D; for (int var8 = 0; var8 < var5.size(); ++var8) { Entity var9 = (Entity) var5.get(var8); if (var9.canBeCollidedWith() && (!var9.isEntityEqual(this.shootingEntity) || this.ticksInAir >= 25)) { float var10 = 0.3F; AxisAlignedBB var11 = var9.boundingBox.expand((double) var10, (double) var10, (double) var10); MovingObjectPosition var12 = var11.calculateIntercept(var15, var2); if (var12 != null) { double var13 = var15.distanceTo(var12.hitVec); if (var13 < var6 || var6 == 0.0D) { var4 = var9; var6 = var13; } } } } if (var4 != null) { var3 = new MovingObjectPosition(var4); } if (var3 != null) { this.onImpact(var3); } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float var16 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) (Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F; for (this.rotationPitch = (float) (Math.atan2((double) var16, this.motionY) * 180.0D / Math.PI) - 90.0F; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {; } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float var17 = this.getMotionFactor(); if (this.isInWater()) { for (int var19 = 0; var19 < 4; ++var19) { float var18 = 0.25F; this.worldObj.spawnParticle( "bubble", this.posX - this.motionX * (double) var18, this.posY - this.motionY * (double) var18, this.posZ - this.motionZ * (double) var18, this.motionX, this.motionY, this.motionZ); } var17 = 0.8F; } this.motionX += this.accelerationX; this.motionY += this.accelerationY; this.motionZ += this.accelerationZ; this.motionX *= (double) var17; this.motionY *= (double) var17; this.motionZ *= (double) var17; this.worldObj.spawnParticle( "smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); this.setPosition(this.posX, this.posY, this.posZ); } }
/** Called to update the entity's position/logic. */ @Override public void onUpdate() { super.onUpdate(); if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.prevRotationYaw = this.rotationYaw = (float) ((Math.atan2(this.motionX, this.motionZ) * 180D) / Math.PI); this.prevRotationPitch = this.rotationPitch = (float) ((Math.atan2(this.motionY, f) * 180D) / Math.PI); } int i = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); if (i > 0) { Block.blocksList[i].setBlockBoundsBasedOnState( this.worldObj, this.xTile, this.yTile, this.zTile); AxisAlignedBB axisalignedbb = Block.blocksList[i].getCollisionBoundingBoxFromPool( this.worldObj, this.xTile, this.yTile, this.zTile); if (axisalignedbb != null && axisalignedbb.isVecInside( Vec3.func_72437_a().func_72345_a(this.posX, this.posY, this.posZ))) { this.inGround = true; } } if (this.arrowShake > 0) { this.arrowShake--; } if (this.inGround) { int j = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); int k = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile); if (j != this.inTile || k != this.inData) { this.inGround = false; this.motionX *= this.rand.nextFloat() * 0.2F; this.motionY *= this.rand.nextFloat() * 0.2F; this.motionZ *= this.rand.nextFloat() * 0.2F; this.ticksInGround = 0; this.ticksInAir = 0; return; } this.ticksInGround++; if (this.ticksInGround == 1200) { setDead(); } return; } this.ticksInAir++; Vec3 vec3 = Vec3.func_72437_a().func_72345_a(this.posX, this.posY, this.posZ); Vec3 vec3_1 = Vec3.func_72437_a() .func_72345_a( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks_do_do(vec3, vec3_1, false, true); vec3 = Vec3.func_72437_a().func_72345_a(this.posX, this.posY, this.posZ); vec3_1 = Vec3.func_72437_a() .func_72345_a( this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (movingobjectposition != null) { vec3_1 = Vec3.func_72437_a() .func_72345_a( movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List list = this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.boundingBox .addCoord(this.motionX, this.motionY, this.motionZ) .expand(1.0D, 1.0D, 1.0D)); double d = 0.0D; Iterator iterator = list.iterator(); do { if (!iterator.hasNext()) { break; } Entity entity1 = (Entity) iterator.next(); if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) { float f5 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f5, f5, f5); MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3, vec3_1); if (movingobjectposition1 != null) { double d1 = vec3.distanceTo(movingobjectposition1.hitVec); if (d1 < d || d == 0.0D) { entity = entity1; d = d1; } } } } while (true); if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null) { if (movingobjectposition.entityHit != null) { float f1 = MathHelper.sqrt_double( this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); int i1 = MathHelper.func_76143_f(f1 * this.damage); if (func_70241_g()) { i1 += this.rand.nextInt(i1 / 2 + 2); } DamageSource damagesource = null; if (this.shootingEntity == null) { damagesource = DamageSource.causeArrowDamage(this, this); } else { damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity); } if (isBurning()) { movingobjectposition.entityHit.setFire(5); } if (movingobjectposition.entityHit.attackEntityFrom(damagesource, i1)) { if (movingobjectposition.entityHit instanceof EntityLiving) { ((EntityLiving) movingobjectposition.entityHit).arrowHitTempCounter++; if (this.knockbackStrength > 0) { float f7 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); if (f7 > 0.0F) { movingobjectposition.entityHit.addVelocity( (this.motionX * this.knockbackStrength * 0.60000002384185791D) / f7, 0.10000000000000001D, (this.motionZ * this.knockbackStrength * 0.60000002384185791D) / f7); } } } this.worldObj.playSoundAtEntity( this, "random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); setDead(); } else { this.motionX *= -0.10000000149011612D; this.motionY *= -0.10000000149011612D; this.motionZ *= -0.10000000149011612D; this.rotationYaw += 180F; this.prevRotationYaw += 180F; this.ticksInAir = 0; } } else { this.xTile = movingobjectposition.blockX; this.yTile = movingobjectposition.blockY; this.zTile = movingobjectposition.blockZ; this.inTile = this.worldObj.getBlockId(this.xTile, this.yTile, this.zTile); this.inData = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile); this.motionX = (float) (movingobjectposition.hitVec.xCoord - this.posX); this.motionY = (float) (movingobjectposition.hitVec.yCoord - this.posY); this.motionZ = (float) (movingobjectposition.hitVec.zCoord - this.posZ); float f2 = MathHelper.sqrt_double( this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); this.posX -= (this.motionX / f2) * 0.05000000074505806D; this.posY -= (this.motionY / f2) * 0.05000000074505806D; this.posZ -= (this.motionZ / f2) * 0.05000000074505806D; this.worldObj.playSoundAtEntity( this, "random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); this.inGround = true; this.arrowShake = 7; func_70243_d(false); } } if (func_70241_g()) { for (int l = 0; l < 4; l++) { this.worldObj.spawnParticle( "crit", this.posX + (this.motionX * l) / 4D, this.posY + (this.motionY * l) / 4D, this.posZ + (this.motionZ * l) / 4D, -this.motionX, -this.motionY + 0.20000000000000001D, -this.motionZ); } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float f3 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) ((Math.atan2(this.motionX, this.motionZ) * 180D) / Math.PI); for (this.rotationPitch = (float) ((Math.atan2(this.motionY, f3) * 180D) / Math.PI); this.rotationPitch - this.prevRotationPitch < -180F; this.prevRotationPitch -= 360F) {} for (; this.rotationPitch - this.prevRotationPitch >= 180F; this.prevRotationPitch += 360F) {} for (; this.rotationYaw - this.prevRotationYaw < -180F; this.prevRotationYaw -= 360F) {} for (; this.rotationYaw - this.prevRotationYaw >= 180F; this.prevRotationYaw += 360F) {} this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float f4 = 0.99F; float f6 = 0.05F; if (isInWater()) { for (int j1 = 0; j1 < 4; j1++) { float f8 = 0.25F; this.worldObj.spawnParticle( "bubble", this.posX - this.motionX * f8, this.posY - this.motionY * f8, this.posZ - this.motionZ * f8, this.motionX, this.motionY, this.motionZ); } f4 = 0.8F; } this.motionX *= f4; this.motionY *= f4; this.motionZ *= f4; this.motionY -= f6; setPosition(this.posX, this.posY, this.posZ); func_70017_D(); }