예제 #1
0
  @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);
  }